Class: Karafka::Helpers::ConfigImporter
- Inherits:
-
Module
- Object
- Module
- Karafka::Helpers::ConfigImporter
- Defined in:
- lib/karafka/helpers/config_importer.rb
Overview
Module allowing for configuration injections. By default injects whole app config Allows for granular config injection
Instance Method Summary collapse
- #extended(model) ⇒ Object
- #included(model) ⇒ Object
-
#initialize(attributes = { config: %i[itself] }) ⇒ ConfigImporter
constructor
A new instance of ConfigImporter.
Constructor Details
#initialize(attributes = { config: %i[itself] }) ⇒ ConfigImporter
Returns a new instance of ConfigImporter.
11 12 13 14 |
# File 'lib/karafka/helpers/config_importer.rb', line 11 def initialize(attributes = { config: %i[itself] }) super() @attributes = attributes end |
Instance Method Details
#extended(model) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/karafka/helpers/config_importer.rb', line 30 def extended(model) super @attributes.each do |name, path| model.class_eval <<~RUBY, __FILE__, __LINE__ + 1 def self.#{name} @#{name} ||= ::Karafka::App.config.#{path.join('.')} end RUBY end end |
#included(model) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/karafka/helpers/config_importer.rb', line 17 def included(model) super @attributes.each do |name, path| model.class_eval <<~RUBY, __FILE__, __LINE__ + 1 def #{name} @#{name} ||= ::Karafka::App.config.#{path.join('.')} end RUBY end end |