Class: Bcome::ConfigFactory
- Inherits:
-
Object
- Object
- Bcome::ConfigFactory
- Defined in:
- lib/objects/config_factory.rb
Instance Attribute Summary collapse
-
#tree ⇒ Object
readonly
Returns the value of attribute tree.
Instance Method Summary collapse
- #add_crumbs(crumbs, data) ⇒ Object
- #flattened ⇒ Object
- #hash_for_identifier_from_view(identifier, views) ⇒ Object
-
#initialize ⇒ ConfigFactory
constructor
A new instance of ConfigFactory.
Constructor Details
#initialize ⇒ ConfigFactory
Returns a new instance of ConfigFactory.
4 5 6 7 |
# File 'lib/objects/config_factory.rb', line 4 def initialize @tree = { views: [] } @collections = [] end |
Instance Attribute Details
#tree ⇒ Object (readonly)
Returns the value of attribute tree.
2 3 4 |
# File 'lib/objects/config_factory.rb', line 2 def tree @tree end |
Instance Method Details
#add_crumbs(crumbs, data) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/objects/config_factory.rb', line 13 def add_crumbs(crumbs, data) views = @tree number_crumbs = crumbs.size crumbs.each_with_index do |crumb, index| is_last_crumb = number_crumbs == (index + 1) if this_view = hash_for_identifier_from_view(crumb, views) views = this_view else this_view = { identifier: crumb } this_view[:views] = [] unless is_last_crumb && data[:type].to_sym == :inventory views[:views] << this_view views = hash_for_identifier_from_view(crumb, views) end this_view.merge!(data) if is_last_crumb end end |
#flattened ⇒ Object
9 10 11 |
# File 'lib/objects/config_factory.rb', line 9 def flattened @tree[:views].first end |
#hash_for_identifier_from_view(identifier, views) ⇒ Object
32 33 34 35 |
# File 'lib/objects/config_factory.rb', line 32 def hash_for_identifier_from_view(identifier, views) raise Bcome::Exception::InventoriesCannotHaveSubViews, 'Inventories cannot hold other inventories - invalid network config' unless views.key?(:views) views[:views].select { |v| v[:identifier].to_s == identifier.to_s }.first end |