lib/tobox/configuration.rb in tobox-0.4.5 vs lib/tobox/configuration.rb in tobox-0.5.0

- old
+ new

@@ -5,26 +5,25 @@ module Tobox class Configuration extend Forwardable - attr_reader :handlers, :lifecycle_events, :arguments_handler, :default_logger, :database + attr_reader :plugins, :handlers, :lifecycle_events, :arguments_handler, :default_logger, :database, :fetcher_class, + :config def_delegator :@config, :[] DEFAULT_CONFIGURATION = { environment: ENV.fetch("APP_ENV", "development"), logger: nil, log_level: nil, database_uri: nil, database_options: nil, table: :outbox, - group_column: nil, - inbox_table: nil, - inbox_column: nil, + created_at_column: nil, max_attempts: 10, - exponential_retry_factor: 4, + exponential_retry_factor: 2, wait_for_events_delay: 5, shutdown_timeout: 10, concurrency: 4, # TODO: CPU count worker: :thread }.freeze @@ -43,10 +42,11 @@ @lifecycle_events = {} @handlers = {} @message_to_arguments = nil @plugins = [] + @fetcher_class = Class.new(Fetcher) if block case block.arity when 0 instance_exec(&block) @@ -139,10 +139,12 @@ @plugins << plugin plugin.load_dependencies(self, **options, &block) if plugin.respond_to?(:load_dependencies) extend(plugin::ConfigurationMethods) if defined?(plugin::ConfigurationMethods) + @fetcher_class.__send__(:include, plugin::FetcherMethods) if defined?(plugin::FetcherMethods) + plugin.configure(self, **options, &block) if plugin.respond_to?(:configure) end def freeze @name.freeze @@ -155,21 +157,21 @@ end private def method_missing(meth, *args, &block) - if DEFAULT_CONFIGURATION.key?(meth) && args.size == 1 + if @config.key?(meth) && args.size == 1 @config[meth] = args.first elsif /\Aon_(.*)\z/.match(meth) && args.empty? on(Regexp.last_match(1).to_sym, &block) else super end end def respond_to_missing?(meth, *args) - super(meth, *args) || - DEFAULT_CONFIGURATION.key?(meth) || + super || + @config.key?(meth) || /\Aon_(.*)\z/.match(meth) end end end