Module: ConvenientService::Service::Configs::AwesomePrintInspect

Includes:
Config, Essential
Defined in:
lib/convenient_service/service/configs/awesome_print_inspect.rb

Overview

Patches services to use Awesome Print to generate colored inspect strings. Useful for debugging. Works as expected for byebug and pry.

Has issues with escaping colors for binding.break and irb. There is a workaround in the examples, but its possible negative outcome has not been investigated yet. Use it at your own risk.

Examples:

AwesomePrintInspect output for byebug or pry.

class Service
  include ::ConvenientService::Standard::Config
  include ::ConvenientService::AwesomePrintInspect::Config

  def result
    success(foo: :bar)
  end
end

Service.result
# =>
{
  :ConvenientService => {
         :entity => "Result",
        :service => "Service",
         :status => :success,
      :data_keys => [
          [0] :foo
      ]
  }
}

AwesomePrintInspect output for binding.break or irb.


class Service
  include ::ConvenientService::Standard::Config
  include ::ConvenientService::AwesomePrintInspect::Config

  def result
    success(foo: :bar)
  end
end

Service.result
# =>
{
  :ConvenientService^[[0;37m => ^[[0m{
         :entity^[[0;37m => ^[[0m^[[0;33m"Result"^[[0m,
        :service^[[0;37m => ^[[0m^[[0;33m"Service"^[[0m,
         :status^[[0;37m => ^[[0m^[[0;36m:success^[[0m,
      :data_keys^[[0;37m => ^[[0m[
          ^[[1;37m[0] ^[[0m^[[0;36m:foo^[[0m
      ]
    }
}

AwesomePrintInspect output for binding.break or irb with Reline hack.


class Service
  include ::ConvenientService::Standard::Config
  include ::ConvenientService::AwesomePrintInspect::Config

  def result
    success(foo: :bar)
  end
end

class Reline::Unicode
  def self.escape_for_print(str)
    str
  end
end

Service.result
# =>
{
  :ConvenientService => {
         :entity => "Result",
        :service => "Service",
         :status => :success,
      :data_keys => [
          [0] :foo
      ]
  }
}

See Also: