Class: Trifle::Docs::Helper::Tree
- Inherits:
-
Object
- Object
- Trifle::Docs::Helper::Tree
- Defined in:
- lib/trifle/docs/helper/tree.rb
Instance Attribute Summary collapse
-
#mapping ⇒ Object
readonly
Returns the value of attribute mapping.
Instance Method Summary collapse
- #deep_merge(this_hash, other_hash, &block) ⇒ Object
- #deep_merge!(this_hash, other_hash, &block) ⇒ Object
-
#initialize(mapping:) ⇒ Tree
constructor
A new instance of Tree.
- #menu ⇒ Object
Constructor Details
#initialize(mapping:) ⇒ Tree
Returns a new instance of Tree.
9 10 11 |
# File 'lib/trifle/docs/helper/tree.rb', line 9 def initialize(mapping:) @mapping = mapping end |
Instance Attribute Details
#mapping ⇒ Object (readonly)
Returns the value of attribute mapping.
7 8 9 |
# File 'lib/trifle/docs/helper/tree.rb', line 7 def mapping @mapping end |
Instance Method Details
#deep_merge(this_hash, other_hash, &block) ⇒ Object
21 22 23 |
# File 'lib/trifle/docs/helper/tree.rb', line 21 def deep_merge(this_hash, other_hash, &block) deep_merge!(this_hash.dup, other_hash, &block) end |
#deep_merge!(this_hash, other_hash, &block) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/trifle/docs/helper/tree.rb', line 25 def deep_merge!(this_hash, other_hash, &block) this_hash.merge!(other_hash) do |key, this_val, other_val| if this_val.is_a?(Hash) && other_val.is_a?(Hash) deep_merge(this_val, other_val, &block) elsif block_given? block.call(key, this_val, other_val) else other_val end end end |
#menu ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/trifle/docs/helper/tree.rb', line 13 def @menu ||= mapping.inject({}) do |out, (url, )| deep_merge( out, url.split('/').reverse.inject({ '_meta' => }) { |o, k| { k => o } } ) end end |