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.
6 7 8 9 |
# File 'lib/objects/config_factory.rb', line 6 def initialize @tree = { views: [] } @collections = [] end |
Instance Attribute Details
#tree ⇒ Object (readonly)
Returns the value of attribute tree.
4 5 6 |
# File 'lib/objects/config_factory.rb', line 4 def tree @tree end |
Instance Method Details
#add_crumbs(crumbs, data) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/objects/config_factory.rb', line 15 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
11 12 13 |
# File 'lib/objects/config_factory.rb', line 11 def flattened @tree[:views].first end |
#hash_for_identifier_from_view(identifier, views) ⇒ Object
34 35 36 37 38 |
# File 'lib/objects/config_factory.rb', line 34 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 |