Class: AmazingPrint::Inspector
Constant Summary collapse
- AP =
:__amazing_print__
Instance Attribute Summary collapse
-
#indentator ⇒ Object
Returns the value of attribute indentator.
-
#options ⇒ Object
Returns the value of attribute options.
Class Method Summary collapse
-
.reload_dotfile ⇒ Object
Unload the cached dotfile and load it again.
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
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 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/amazing_print/inspector.rb', line 29 def initialize( = {}) = { indent: 4, # Number of spaces for indenting. index: true, # Display array indices. html: false, # Use ANSI color codes rather than HTML. multiline: true, # Display in multiple lines. colors: :values_only, # Controls what should be colored. Can be one of :all, :values_only, or :none raw: false, # Do not recursively format instance variables. sort_keys: false, # Do not sort hash keys. sort_vars: true, # Sort instance variables. limit: false, # Limit arrays & hashes. Accepts bool or int. hash_format: :symbol, # The format for printing hashes. Can be one of :json, :rocket, or :symbol class_name: :class, # Method used to get Instance class name. object_id: true, # Show object_id. color: { args: :whiteish, array: :white, bigdecimal: :blue, class: :yellow, date: :greenish, falseclass: :red, fixnum: :blue, integer: :blue, float: :blue, hash: :whiteish, keyword: :cyan, method: :purpleish, nilclass: :red, rational: :blue, string: :yellowish, struct: :whiteish, symbol: :cyanish, time: :greenish, trueclass: :green, variable: :cyanish } } # Merge custom defaults and let explicit options parameter override them. merge_custom_defaults! () @formatter = AmazingPrint::Formatter.new(self) @indentator = AmazingPrint::Indentator.new([:indent].abs) Thread.current[AP] ||= [] ExtLoader.call end |
Instance Attribute Details
#indentator ⇒ Object
Returns the value of attribute indentator.
16 17 18 |
# File 'lib/amazing_print/inspector.rb', line 16 def indentator @indentator end |
#options ⇒ Object
Returns the value of attribute options.
16 17 18 |
# File 'lib/amazing_print/inspector.rb', line 16 def end |
Class Method Details
.reload_dotfile ⇒ Object
Unload the cached dotfile and load it again.
23 24 25 26 27 |
# File 'lib/amazing_print/inspector.rb', line 23 def self.reload_dotfile # rubocop:todo Naming/PredicateMethod @@dotfile = nil new.send :load_dotfile true end |
Instance Method Details
#awesome(object) ⇒ Object
Dispatcher that detects data nesting and invokes object-aware formatter.
88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/amazing_print/inspector.rb', line 88 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.
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/amazing_print/inspector.rb', line 103 def colorize? AmazingPrint.force_colors ||= false AmazingPrint.force_colors || ( if defined? @colorize_stdout @colorize_stdout else @colorize_stdout = $stdout.tty? && ( ( ENV['TERM'] && ENV['TERM'] != 'dumb' ) || ENV['ANSICON'] ) end ) end |
#current_indentation ⇒ Object
78 79 80 |
# File 'lib/amazing_print/inspector.rb', line 78 def current_indentation indentator.indentation end |
#increase_indentation ⇒ Object
82 83 84 |
# File 'lib/amazing_print/inspector.rb', line 82 def increase_indentation(&) indentator.indent(&) end |