lib/eco/api/session/config.rb in eco-helpers-0.7.2 vs lib/eco/api/session/config.rb in eco-helpers-0.8.1

- old
+ new

@@ -1,54 +1,59 @@ module Eco module API class Session class Config < Hash - def initialize() + attr_reader :name + + def initialize(name = :default) super(nil) + @name = name self["org"] = {} end + def clone(name) + keys.each_with_object(self.class.new(name)) do |key, cnf| + begin + cnf[key] = self[key].clone(config: cnf) + rescue ArgumentError + cnf[key] = self[key].clone + end + end + end + def reopen yield(self) end def apis - self["apis"] ||= Session::Config::Apis.new(root: self) + self["apis"] ||= Session::Config::Apis.new(config: self) end def logger - self["logger"] ||= Session::Config::Logger.new(root: self) + self["logger"] ||= Session::Config::Logger.new(config: self) end def s3storage - self["s3_storage"] ||= Session::Config::S3Storage.new(root: self) + self["s3_storage"] ||= Session::Config::S3Storage.new(config: self) end def files - self["files"] ||= Session::Config::Files.new(root: self) + self["files"] ||= Session::Config::Files.new(config: self) end def mailer - self["mailer"] ||= Session::Config::Mailer.new(root: self) + self["mailer"] ||= Session::Config::Mailer.new(config: self) end def org self["org"] end def people - self["people"] ||= Session::Config::People.new(root: self) + self["people"] ||= Session::Config::People.new(config: self) end - def usecases - self["usecases"] ||= Session::Config::UseCases.new(root: self) - end - - def api_policies - self["api_policies"] ||= Session::Config::Policies.new(root: self) - end - # LOGGER def log_console_level=(value) logger.console_level= value end @@ -110,23 +115,52 @@ # FILES def working_directory=(path) files.working_directory = path end + def working_directory(mode: :active_api) + if mode == :active_api + apis.active_root_name + else + files.working_directory + end + end + def file_timestamp_pattern=(pattern) files.timestamp_pattern = pattern end def file_manager Eco::API::Common::Session::FileManager.new(self) end - def require(file) - require_relative "#{File.expand_path(file_manager.dir.file(file))}" + def require(file = nil, match: nil) + if match + file_manager.dir.dir_files(pattern: match).each do |file| + #pp "#{File.expand_path(file)}" + require_relative File.expand_path(file) + end + else + require_relative "#{File.expand_path(file_manager.dir.file(file))}" + end end # ORG + + def location_codes=(file) + org["location_codes"] = file + end + + def location_codes + org["location_codes"] + end + + def locations_mapper + file = file_manager.newest(location_codes) + @locations_mapper ||= Eco::Data::Mapper.new(file_manager.load_json(file), internal: :first) + end + def tagtree=(file) org["tagtree"] = file end def policy_groups @@ -172,32 +206,43 @@ people.presets_map = file end # CUSTOM PERSON PARSERS def person_parser(format: :csv, &block) - people.add_parser(format: format, &block) + people.parser(format: format, &block) end # CUSTOM USE CASES - def use_cases(&block) - usecases.add(&block) + def usecases + cases = self["usecases"] ||= Eco::API::UseCases::UseGroup.new + if block_given? + yield(cases) + self + else + cases + end end # API POLICIES - def policies(&block) - api_policies.add(&block) + def policies + api_policies = self["policies"] ||= Eco::API::Policies::UsedPolicies.new + if block_given? + yield(api_policies) + self + else + api_policies + end end end end end end +require_relative 'config/base_config' require_relative 'config/api' require_relative 'config/apis' require_relative 'config/logger' require_relative 'config/mailer' require_relative 'config/s3_storage' require_relative 'config/files' require_relative 'config/people' -require_relative 'config/use_cases' -require_relative 'config/policies'