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, include_archived: false, &block) ⇒ Object
Among all the locations structures it selects the one with more location nodes.
-
#live_trees(enviro: nil, include_archived: false, &block) ⇒ 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, include_archived: false, &block) ⇒ Object
Among all the locations structures it selects the one with more location nodes
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/eco/api/session/config/tagtree.rb', line 23 def live_tree(enviro: nil, include_archived: false, &block) return @live_tree if instance_variable_defined?(:@live_tree) && @live_tree.enviro == enviro trees = live_trees(enviro: enviro, include_archived: include_archived, &block) @live_tree = trees.reject do |tree| tree.empty? end.max do |a,b| a.count <=> b.count end.tap do |tree| if tree msg ="Using LIVE LOCATIONS Structure: '#{tree.name}' (#{tree.count} nodes)" session_logger.info(msg) end end end |
#live_trees(enviro: nil, include_archived: false, &block) ⇒ Object
Retrieves all the location structures of the organisation
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/eco/api/session/config/tagtree.rb', line 39 def live_trees(enviro: nil, include_archived: false, &block) [].tap do |eco_trees| next unless apis.active_api.version_available?(:graphql) next unless graphql = apis.api(version: :graphql) kargs = { includeArchived: include_archived, includeUnpublished: false } next unless trees = graphql.currentOrganization.locationStructures(**kargs, &block) 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 17 18 19 20 |
# 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).tap do |tree| unless tree && !tree.empty? raise "Could not find a locations structure." end end end |