lib/eco/api/session/config.rb in eco-helpers-2.1.1 vs lib/eco/api/session/config.rb in eco-helpers-2.1.2

- old
+ new

@@ -226,16 +226,34 @@ def tagtree=(file) org["tagtree"] = file end + # It uses the `tagtree.json` file and in its absence, if `graphql` enabled, the `life_tagtree` # @return [Eco::API::Organization::TagTree] def tagtree(enviro: nil) return @tagtree if instance_variable_defined?(:@tagtree) && @tagtree.enviro == enviro if tree_file = org["tagtree"] tree = [] tree = file_manager.load_json(tree_file) unless !tree_file @tagtree = Eco::API::Organization::TagTree.new(tree, enviro: enviro) + else + @tagtree = live_tree(enviro: enviro) + end + end + + # It obtains the first of the live tagtree in the org + # @note it requires graphql connection configuration parameters + # @return [Eco::API::Organization::TagTree] + def live_tree(enviro: nil) + return @live_tree if instance_variable_defined?(:@live_tree) && @live_tree.enviro == enviro + if apis.active_api.version_available?(:graphql) + graphql = apis.api(version: :graphql) + if tree = graphql.currentOrganization.tagTrees.to_a.first.treeify + @live_tree = Eco::API::Organization::TagTree.new(tree, enviro: enviro) + else + @live_tree = nil + end end end # @return [Eco::API::Organization::PolicyGroups] def policy_groups