Class: Lanes::Configuration
- Inherits:
-
Object
- Object
- Lanes::Configuration
- Includes:
- Lanes::Concerns::AttrAccessorWithDefault
- Defined in:
- lib/lanes/configuration.rb
Direct Known Subclasses
Class Method Summary collapse
- .apply ⇒ Object
-
.config_option(name, default, options = {}) ⇒ Object
Since changing a config value inadvertently can have pretty drastic consequences that might not be discovered immediately, we log each time a value is changed.
Instance Method Summary collapse
- #get(config, &block) ⇒ Object
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #on_change(config, &block) ⇒ Object
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
31 32 33 |
# File 'lib/lanes/configuration.rb', line 31 def initialize @observers=Hash.new{ |hash,key| hash[key] = Array.new } end |
Class Method Details
.apply ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/lanes/configuration.rb', line 48 def self.apply identifier = Lanes::Extensions.controlling.identifier ActiveJob::Base.queue_adapter = Lanes.env.test? ? :test : :resque Lanes::Job::FailureLogger.configure DB.establish_connection Jobba.configure do |config| config. = Lanes.config.redis config.namespace = "#{identifier}::jobba" end Resque.redis.namespace = "#{identifier}::resque" Resque.redis = Lanes.config.redis MessageBus.redis_config = Lanes.config.redis MessageBus.logger = Lanes.logger Lanes::SystemSettings.for_ext('lanes').apply! Extensions.each{|ext| ext.apply_configuration } end |
.config_option(name, default, options = {}) ⇒ Object
Since changing a config value inadvertently can have pretty drastic consequences that might not be discovered immediately, we log each time a value is changed
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/lanes/configuration.rb', line 17 def self.config_option( name, default, ={} ) define_method( "#{name}=" ) do | value | old_value = self.send( name ) if old_value && ![:silent] Lanes.logger.info "Config option #{name} changed from '#{old_value.inspect}' to '#{value.inspect}'" end instance_variable_set( "@#{name}", value ) if @observers.has_key?(name) @observers[name].each{ |cb| cb.call(value, old_value) } end end attr_reader_with_default(name, default) end |
Instance Method Details
#get(config, &block) ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/lanes/configuration.rb', line 39 def get(config, &block) value = self.send(config.to_sym) if block on_change(config,&block) block.call( value, value ) end value end |
#on_change(config, &block) ⇒ Object
35 36 37 |
# File 'lib/lanes/configuration.rb', line 35 def on_change(config, &block) @observers[config.to_sym] << block end |