module Eco module API class Session class Config < Hash def initialize() super(nil) self["org"] = {} end def reopen yield(self) end def apis self["apis"] ||= Session::Config::Apis.new(root: self) end def logger self["logger"] ||= Session::Config::Logger.new(root: self) end def s3storage self["s3_storage"] ||= Session::Config::S3Storage.new(root: self) end def files self["files"] ||= Session::Config::Files.new(root: self) end def mailer self["mailer"] ||= Session::Config::Mailer.new(root: self) end def org self["org"] end def people self["people"] ||= Session::Config::People.new(root: self) end def usecases self["usecases"] ||= Session::Config::UseCases.new(root: self) end # LOGGER def log_console_level=(value) logger.console_level= value end def log_file_level=(value) logger.file_level = value end def log_file=(file) logger.file = file end def timestamp_console=(value) logger.timestamp_console = value end def log_connection=(value) logger.log_connection = value end # API def dry_run! self["dry-run"] = true end def dry_run? self["dry-run"] end def run_mode=(mode) apis.active_api.mode = mode end def run_mode_local? apis.active_api.local? end def run_mode_remote? apis.active_api.remote? end def apis? apis.apis? end def add_api(name, **kargs) apis.add(name, **kargs) self end def active_api(name) apis.active_name = name self end def api(logger = ::Logger.new(IO::NULL)) apis.api(logger) end def policy_groups policy_groups = api&.policy_groups.to_a.compact Eco::API::Organization::PolicyGroups.new(policy_groups) end # FILES def working_directory=(path) files.working_directory = path 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))}" end # ORG def tagtree=(file) org["tagtree"] = file end # PEOPLE def discarded_people_file=(value) people.discarded_file = value end def people_cache=(file) people.cache = file end def requests_backup_folder=(folder) people.requests_folder = folder end # PERSON FIELDS MAPPER def person_fields_mapper=(file) people.fields_mapper = file end def default_schema=(name) people.default_schema = name end # ACCOUNT PRESETS def presets_custom=(file) people.presets_custom = file end def presets_map=(file) people.presets_map = file end # CUSTOM PERSON PARSERS def person_parser(format: :csv, &block) people.add_parser(format: format, &block) end # CUSTOM USE CASES def use_cases(&block) usecases.add(&block) end end end end end 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'