Module: Pipetree::Inspect
- Included in:
- Pipetree, Flow::Inspect
- Defined in:
- lib/pipetree/inspect.rb
Instance Method Summary collapse
-
#inspect(options = { style: :line }) ⇒ Object
TODO: implement for nested TODO: remove in Representable::Debug.
-
#inspect_func(func) ⇒ Object
open source file to retrieve the constant name.
- #inspect_line(names) ⇒ Object
- #inspect_object(obj) ⇒ Object
- #inspect_proc(proc) ⇒ Object
- #inspect_row(index, name) ⇒ Object
- #inspect_rows(names) ⇒ Object
Instance Method Details
#inspect(options = { style: :line }) ⇒ Object
TODO: implement for nested TODO: remove in Representable::Debug.
4 5 6 7 8 9 10 11 |
# File 'lib/pipetree/inspect.rb', line 4 def inspect(={ style: :line }) names = each_with_index.collect do |func, i| [i, inspect_func(func)] end return inspect_line(names) if [:style] == :line inspect_rows(names) end |
#inspect_func(func) ⇒ Object
open source file to retrieve the constant name.
14 15 16 17 |
# File 'lib/pipetree/inspect.rb', line 14 def inspect_func(func) return inspect_object(func) unless func.is_a?(Proc) inspect_proc(func) end |
#inspect_line(names) ⇒ Object
27 28 29 30 |
# File 'lib/pipetree/inspect.rb', line 27 def inspect_line(names) string = names.collect { |i, name| "#{name}" }.join("|>") "[#{string}]" end |
#inspect_object(obj) ⇒ Object
19 20 21 |
# File 'lib/pipetree/inspect.rb', line 19 def inspect_object(obj) obj.inspect.sub(/0x\w+/, "") end |
#inspect_proc(proc) ⇒ Object
23 24 25 |
# File 'lib/pipetree/inspect.rb', line 23 def inspect_proc(proc) File.readlines(proc.source_location[0])[proc.source_location[1]-1].match(/^\s+([\w\:]+)/)[1] end |
#inspect_row(index, name) ⇒ Object
42 43 44 |
# File 'lib/pipetree/inspect.rb', line 42 def inspect_row(index, name) "#{index}|>#{name}" end |
#inspect_rows(names) ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/pipetree/inspect.rb', line 32 def inspect_rows(names) string = names.collect do |i, name| index = sprintf("%2d", i) inspect_row(index, name) end.join("\n") # name = sprintf("%-60.300s", name) # no idea what i'm doing here. # "#{index}) #{name} #{func.source_location.join(":")}" "\n#{string}" end |