Class: AwesomePrint::Inspector
Constant Summary collapse
- AP =
:__awesome_print__
Instance Attribute Summary collapse
-
#indentator ⇒ Object
Returns the value of attribute indentator.
-
#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.
- #current_indentation ⇒ Object
- #increase_indentation ⇒ Object
-
#initialize(options = {}) ⇒ Inspector
constructor
A new instance of Inspector.
Constructor Details
#initialize(options = {}) ⇒ Inspector
Returns a new instance of Inspector.
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/awesome_print/inspector.rb', line 57 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. :raw => false, # Do not recursively format object instance variables. :sort_keys => false, # Do not sort hash keys. :limit => false, # Limit large output for arrays and hashes. Set to a boolean or integer. :color => { :args => :pale, :array => :white, :bigdecimal => :blue, :class => :yellow, :date => :greenish, :falseclass => :red, :fixnum => :blue, :float => :blue, :hash => :pale, :keyword => :cyan, :method => :purpleish, :nilclass => :red, :rational => :blue, :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) @indentator = AwesomePrint::Indentator.new(@options[:indent].abs) Thread.current[AP] ||= [] end |
Instance Attribute Details
#indentator ⇒ Object
Returns the value of attribute indentator.
53 54 55 |
# File 'lib/awesome_print/inspector.rb', line 53 def indentator @indentator end |
#options ⇒ Object
Returns the value of attribute options.
53 54 55 |
# File 'lib/awesome_print/inspector.rb', line 53 def @options end |
Instance Method Details
#awesome(object) ⇒ Object
Dispatcher that detects data nesting and invokes object-aware formatter.
109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/awesome_print/inspector.rb', line 109 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.
124 125 126 127 |
# File 'lib/awesome_print/inspector.rb', line 124 def colorize? AwesomePrint.force_colors ||= false AwesomePrint.force_colors || (STDOUT.tty? && ((ENV['TERM'] && ENV['TERM'] != 'dumb') || ENV['ANSICON'])) end |
#current_indentation ⇒ Object
99 100 101 |
# File 'lib/awesome_print/inspector.rb', line 99 def current_indentation indentator.indentation end |
#increase_indentation ⇒ Object
103 104 105 |
# File 'lib/awesome_print/inspector.rb', line 103 def increase_indentation indentator.indent(&Proc.new) end |