Class: Codily::Dumper
- Inherits:
-
Object
- Object
- Codily::Dumper
- Defined in:
- lib/codily/dumper.rb
Instance Attribute Summary collapse
-
#root ⇒ Object
readonly
Returns the value of attribute root.
Instance Method Summary collapse
-
#initialize(root) ⇒ Dumper
constructor
A new instance of Dumper.
- #ruby_code ⇒ Object
- #simple_tree ⇒ Object
- #tree ⇒ Object
Constructor Details
Instance Attribute Details
#root ⇒ Object (readonly)
Returns the value of attribute root.
9 10 11 |
# File 'lib/codily/dumper.rb', line 9 def root @root end |
Instance Method Details
#ruby_code ⇒ Object
37 38 39 |
# File 'lib/codily/dumper.rb', line 37 def ruby_code "#{dump_ruby_code(tree)}\n" end |
#simple_tree ⇒ Object
33 34 35 |
# File 'lib/codily/dumper.rb', line 33 def simple_tree simplize_tree tree end |
#tree ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/codily/dumper.rb', line 11 def tree # :children: # service: (element_tree) # KEY: # :self: Elements::Base # :children: # healthcheck: # KEY: # :self: Elements::Base @tree ||= {self: root, children: {}}.tap do |tree| root.elements.each_key.sort_by { |klass| [klass.path.size, klass == Elements::Condition ? 0 : 1] }.each do |klass| elements = root.list_element(klass) elements.each do |key, element| parents = element.parents subtree = parents.inject(tree) { |r,i| r[:children][i.class.name_for_attr][i.key] } (subtree[:children][element.class.name_for_attr] ||= {})[element.key] = {self: element, children: {}} end end end end |