Class: Eco::API::Session::Config::TagTree
- Inherits:
-
BaseConfig
- Object
- Hash
- BaseConfig
- Eco::API::Session::Config::TagTree
- Defined in:
- lib/eco/api/session/config/tagtree.rb
Instance Attribute Summary
Attributes inherited from BaseConfig
Instance Method Summary collapse
-
#live_tree(enviro: nil) ⇒ Object
Among all the locations structures it selects the one with more location nodes.
-
#live_trees(enviro: nil) ⇒ Object
Retrieves all the location structures of the organisation.
- #scope_tree(enviro: nil) ⇒ Object
Methods inherited from BaseConfig
#apis, attr_key, #clone, #file_manager, #initialize
Methods inherited from Hash
Constructor Details
This class inherits a constructor from Eco::API::Session::Config::BaseConfig
Instance Method Details
#live_tree(enviro: nil) ⇒ Object
Among all the locations structures it selects the one with more location nodes
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/eco/api/session/config/tagtree.rb', line 19 def live_tree(enviro: nil) return @live_tree if instance_variable_defined?(:@live_tree) && @live_tree.enviro == enviro trees = live_trees(enviro: enviro) @live_tree = trees.reject do |tree| tree.empty? end.max do |a,b| a.count <=> b.count end.tap do |tree| session_logger.info("Using LIVE LOCATIONS Structure: '#{tree.name}'") if tree end end |
#live_trees(enviro: nil) ⇒ Object
Retrieves all the location structures of the organisation
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/eco/api/session/config/tagtree.rb', line 32 def live_trees(enviro: nil) [].tap do |eco_trees| next unless apis.active_api.version_available?(:graphql) next unless graphql = apis.api(version: :graphql) kargs = { includeArchived: false, includeUnpublished: false } next unless trees = graphql.currentOrganization.locationStructures(**kargs) trees.each do |tree| args = { enviro: enviro, id: tree.id, name: tree.name} eco_tree = Eco::API::Organization::TagTree.new(tree.treeify, **args) eco_trees.push(eco_tree) end end end |
#scope_tree(enviro: nil) ⇒ Object
8 9 10 11 12 13 14 15 16 |
# File 'lib/eco/api/session/config/tagtree.rb', line 8 def scope_tree(enviro: nil) return @tagtree if instance_variable_defined?(:@tagtree) && @tagtree.enviro == enviro if tree_file = self.file if (tree = file_manager.load_json(tree_file)) && !tree.empty? @tagtree = Eco::API::Organization::TagTree.new(tree, enviro: enviro) end end @tagtree ||= live_tree(enviro: enviro) end |