Class: Ductr::Configuration
- Inherits:
-
Object
- Object
- Ductr::Configuration
- Defined in:
- lib/ductr/configuration.rb
Overview
Contains the framework’s configuration, including:
-
‘DUCTR_ENV` environment variable
-
‘Ductr.configure` block
-
Project root path
-
YML file configuration
Instance Attribute Summary collapse
-
#active_job ⇒ Struct
readonly
The active job configuration, available options are ‘queue_adapter`, `default_queue_name`, `queue_name_prefix` & `queue_name_delimiter`.
-
#logging ⇒ Class<Ductr::Log::Logger>
readonly
The logger constant.
-
#root ⇒ String
readonly
The project root.
-
#store_adapter ⇒ Class<ActiveSupport::Cache::Store>, Symbol
readonly
The store adapter to use.
-
#store_options ⇒ Hash<Symbol, Object>
readonly
The store adapter config options.
-
#store_parameters ⇒ Array
readonly
The store adapter config args.
-
#yml ⇒ Hash
readonly
The parsed YML configuration.
Instance Method Summary collapse
-
#adapter(name) ⇒ Adapter
Find an adapter based on its name.
-
#adapters ⇒ Array<Adapter>
Memoize configured adapters based on the YAML configuration.
-
#apply_active_job_config ⇒ void
Configures active job with the given options.
-
#initialize(env) ⇒ Configuration
constructor
Initializing environment to “development” by default, setting project root, parsing YML with the config gem and aliasing semantic logger gem constant to make it usable through the ‘Ductr.configure` block.
-
#store(adapter, *parameters, **options) ⇒ void
Configures the store instance.
Constructor Details
#initialize(env) ⇒ Configuration
Initializing environment to “development” by default, setting project root, parsing YML with the config gem and aliasing semantic logger gem constant to make it usable through the ‘Ductr.configure` block
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/ductr/configuration.rb', line 42 def initialize(env) @root = Dir.pwd @yml = load_yaml("#{root}/config/#{env}.yml") @logging = Log::Logger logging.level = :debug @active_job = Struct.new(:queue_adapter, :default_queue_name, :queue_name_prefix, :queue_name_delimiter).new @store_adapter = ActiveSupport::Cache::FileStore @store_parameters = ["tmp/store"] end |
Instance Attribute Details
#active_job ⇒ Struct (readonly)
Returns The active job configuration, available options are ‘queue_adapter`, `default_queue_name`, `queue_name_prefix` & `queue_name_delimiter`.
17 18 19 |
# File 'lib/ductr/configuration.rb', line 17 def active_job @active_job end |
#logging ⇒ Class<Ductr::Log::Logger> (readonly)
Returns The logger constant.
20 21 22 |
# File 'lib/ductr/configuration.rb', line 20 def logging @logging end |
#root ⇒ String (readonly)
Returns The project root.
23 24 25 |
# File 'lib/ductr/configuration.rb', line 23 def root @root end |
#store_adapter ⇒ Class<ActiveSupport::Cache::Store>, Symbol (readonly)
Returns The store adapter to use @see edgeapi.rubyonrails.org/classes/ActiveSupport/Cache.html#method-c-lookup_store.
27 28 29 |
# File 'lib/ductr/configuration.rb', line 27 def store_adapter @store_adapter end |
#store_options ⇒ Hash<Symbol, Object> (readonly)
Returns The store adapter config options.
33 34 35 |
# File 'lib/ductr/configuration.rb', line 33 def @store_options end |
#store_parameters ⇒ Array (readonly)
Returns The store adapter config args.
30 31 32 |
# File 'lib/ductr/configuration.rb', line 30 def store_parameters @store_parameters end |
#yml ⇒ Hash (readonly)
Returns The parsed YML configuration.
36 37 38 |
# File 'lib/ductr/configuration.rb', line 36 def yml @yml end |
Instance Method Details
#adapter(name) ⇒ Adapter
Find an adapter based on its name.
90 91 92 93 94 95 96 |
# File 'lib/ductr/configuration.rb', line 90 def adapter(name) not_found_error = -> { raise AdapterNotFoundError, "The adapter named \"#{name}\" does not exist" } adapters.find(not_found_error) do |adapter| adapter.name == name end end |
#adapters ⇒ Array<Adapter>
Memoize configured adapters based on the YAML configuration.
73 74 75 76 77 78 79 80 |
# File 'lib/ductr/configuration.rb', line 73 def adapters @adapters ||= yml.adapters.to_h.map do |name, entry| adapter_class = Ductr.adapter_registry.find(entry.adapter) config = entry.to_h.except(:adapter) adapter_class.new(name, **config) end end |
#apply_active_job_config ⇒ void
This method returns an undefined value.
Configures active job with the given options.
103 104 105 106 107 108 109 110 111 |
# File 'lib/ductr/configuration.rb', line 103 def apply_active_job_config ActiveJob::Base.logger = logging.new("ActiveJob") active_job.each_pair do |opt, value| next unless value ActiveJob::Base.send("#{opt}=", value) end end |
#store(adapter, *parameters, **options) ⇒ void
This method returns an undefined value.
Configures the store instance.
62 63 64 65 66 |
# File 'lib/ductr/configuration.rb', line 62 def store(adapter, *parameters, **) @store_adapter = adapter @store_parameters = parameters @store_options = end |