Class: Lolita::Menu::NestedTree::TreeBuilder
- Inherits:
-
Object
- Object
- Lolita::Menu::NestedTree::TreeBuilder
- Defined in:
- lib/lolita-menu/nested_tree/tree_builder.rb
Instance Attribute Summary collapse
-
#items ⇒ Object
readonly
Returns the value of attribute items.
-
#root ⇒ Object
readonly
Returns the value of attribute root.
Instance Method Summary collapse
-
#initialize(klass, items, scope_attributes = {}) ⇒ TreeBuilder
constructor
A new instance of TreeBuilder.
- #item_ids ⇒ Object
- #update_items ⇒ Object
Constructor Details
#initialize(klass, items, scope_attributes = {}) ⇒ TreeBuilder
Returns a new instance of TreeBuilder.
8 9 10 11 12 13 14 15 16 |
# File 'lib/lolita-menu/nested_tree/tree_builder.rb', line 8 def initialize(klass, items, scope_attributes = {}) @klass = klass @scope_attributes = scope_attributes @root = @klass.find_or_create_root(@scope_attributes) @items = items.is_a?(Hash) ? items.values : items @items.map! do |item| Lolita::Menu::NestedTree::BranchBuilder.new(@root, item) end end |
Instance Attribute Details
#items ⇒ Object (readonly)
Returns the value of attribute items.
6 7 8 |
# File 'lib/lolita-menu/nested_tree/tree_builder.rb', line 6 def items @items end |
#root ⇒ Object (readonly)
Returns the value of attribute root.
6 7 8 |
# File 'lib/lolita-menu/nested_tree/tree_builder.rb', line 6 def root @root end |
Instance Method Details
#item_ids ⇒ Object
18 19 20 |
# File 'lib/lolita-menu/nested_tree/tree_builder.rb', line 18 def item_ids @items.map { |item| item.value_for(:item_id) } end |
#update_items ⇒ Object
22 23 24 25 26 27 |
# File 'lib/lolita-menu/nested_tree/tree_builder.rb', line 22 def update_items @items.each do |item| @klass.update_item(item) end @klass.remove_items(deleted_items) end |