lib/eco/api/session.rb in eco-helpers-0.8.3 vs lib/eco/api/session.rb in eco-helpers-0.8.4

- old
+ new

@@ -1,11 +1,10 @@ module Eco module API class Session < Common::Session::BaseSession - attr_reader :batch, :policy_groups, :tagtree - attr_reader :job_groups - attr_reader :schemas + attr_reader :batch + attr_reader :job_groups attr_accessor :schema def initialize(init = {}) e = init msg = "Expected object Eco::API::Session::Config or Eco::API::Common::Session::Environment. Given: #{init}" @@ -19,37 +18,23 @@ @task = Task.new(enviro) @job_groups = JobGroups.new(enviro) @use_cases = Eco::API::UseCases::DefaultCases.new.merge(config.usecases) - @schemas = config.schemas - self.schema = config.people.default_schema || @schemas.first + self.schema = config.people.default_schema || schemas.first @policy_groups = config.policy_groups - @tagtree = nil - if tree_file = config.dig('org', 'tagtree') - tree = file_manager.load_json(tree_file) unless !tree_file - @tagtree = Eco::API::Organization::TagTree.new(tree, enviro: enviro) - end - presets_custom_file = config.people.presets_custom presets_map_file = config.people.presets_map @presets_factory = Eco::API::Organization::PresetsFactory.new({ - #policy_groups: @policy_groups, presets_custom: file_manager.dir.file(presets_custom_file, should_exist: true), presets_map: file_manager.dir.file(presets_map_file, should_exist: true), enviro: enviro }) end - def self.configure - Session::Config.new.tap do |conf| - yield(conf) if block_given? - end - end - # TASKS & JOBS def do @task end @@ -69,31 +54,26 @@ else logger.error("To use Session.s3upload, you must specify either directory, file or content and file name") end end - def job_group(name, order: :last) - case - when job_groups.exists?(name) - job_groups[name] - else - job_groups.new(name, order: order) - end + def policy_groups + config.policy_groups end - def jobs_launch(simulate: false) - job_groups.launch(simulate: simulate) + def tagtree + config.tagtree(enviro: enviro) end - def policy_groups - @policy_groups ||= config.policy_groups + def schemas + config.schemas end def schema=(value) case value when String - unless @schema = @schemas.schema(value) + unless @schema = schemas.schema(value) fatal "The schema with id or name '#{value}' does not exist" end when Ecoportal::API::V1::PersonSchema @schema = value else @@ -163,9 +143,22 @@ def process_case(name, type: nil, **params) args = { session: self }.merge(params) fatal("Undefined usecase '#{name}' of type '#{type.to_s}'") if !@use_cases.defined?(name, type: type) logger.debug("Session: going to process '#{name}' defined case") @use_cases.case(name, type: type).launch(**args) + end + + def job_group(name, order: :last) + case + when job_groups.exists?(name) + job_groups[name] + else + job_groups.new(name, order: order) + end + end + + def jobs_launch(simulate: false) + job_groups.launch(simulate: simulate) end end end end