Class: AwesomePrint::Inspector
Constant Summary collapse
- AP =
:__awesome_print__
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
-
#awesome(object) ⇒ Object
Dispatcher that detects data nesting and invokes object-aware formatter.
-
#colorize? ⇒ Boolean
Return true if we are to colorize the output.
-
#initialize(options = {}) ⇒ Inspector
constructor
A new instance of Inspector.
Constructor Details
#initialize(options = {}) ⇒ Inspector
Returns a new instance of Inspector.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/awesome_print/inspector.rb', line 24 def initialize( = {}) @options = { :indent => 4, # Indent using 4 spaces. :index => true, # Display array indices. :html => false, # Use ANSI color codes rather than HTML. :multiline => true, # Display in multiple lines. :plain => false, # Use colors. :sort_keys => false, # Do not sort hash keys. :limit => false, # Limit large output for arrays and hashes. Set to a boolean or integer. :mongo_mapper => { :show_associations => false, # Display association data for MongoMapper documents and classes :inline_embedded => false # Display embedded associations inline with MongoMapper documents }, :color => { :args => :pale, :array => :white, :assoc => :greenish, :bigdecimal => :blue, :class => :yellow, :date => :greenish, :falseclass => :red, :fixnum => :blue, :float => :blue, :hash => :pale, :keyword => :cyan, :method => :purpleish, :nilclass => :red, :string => :yellowish, :struct => :pale, :symbol => :cyanish, :time => :greenish, :trueclass => :green, :variable => :cyanish } } # Merge custom defaults and let explicit options parameter override them. merge_custom_defaults! () @formatter = AwesomePrint::Formatter.new(self) Thread.current[AP] ||= [] end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
20 21 22 |
# File 'lib/awesome_print/inspector.rb', line 20 def @options end |
Instance Method Details
#awesome(object) ⇒ Object
Dispatcher that detects data nesting and invokes object-aware formatter.
70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/awesome_print/inspector.rb', line 70 def awesome(object) if Thread.current[AP].include?(object.object_id) nested(object) else begin Thread.current[AP] << object.object_id unnested(object) ensure Thread.current[AP].pop end end end |
#colorize? ⇒ Boolean
Return true if we are to colorize the output.
85 86 87 88 |
# File 'lib/awesome_print/inspector.rb', line 85 def colorize? AwesomePrint.force_colors ||= false AwesomePrint.force_colors || (STDOUT.tty? && ((ENV['TERM'] && ENV['TERM'] != 'dumb') || ENV['ANSICON'])) end |