class Lanes::Configuration

Public Class Methods

apply() click to toggle source
# File lib/lanes/configuration.rb, line 49
def self.apply
    controlling_ext = Lanes::Extensions.controlling

    ActiveJob::Base.queue_adapter = Lanes.env.test? ? :test : :resque
    Lanes::Job::FailureLogger.configure

    DB.establish_connection

    Jobba.configure do |config|
        config.redis_options = Lanes.config.redis
        config.namespace = "#{controlling_ext.identifier}::jobba"
    end

    Resque.redis.namespace = "#{controlling_ext.identifier}::resque"
    Resque.redis = Lanes.config.redis

    Lanes::SystemSettings.for_ext('lanes').apply!
    Extensions.each{|ext| ext.apply_configuration }

    if Kernel.const_defined?(:Guard) && ::Guard.const_defined?(:Jest)
        ::Guard::Jest.logger = Lanes.logger
    end
end
config_option( name, default, options={} ) click to toggle source

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

# File lib/lanes/configuration.rb, line 18
def self.config_option( name, default, options={} )
    define_method( "#{name}=" ) do | value |
        old_value = self.send( name )
        if old_value && !options[: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
new() click to toggle source
# File lib/lanes/configuration.rb, line 32
def initialize
    @observers=Hash.new{ |hash,key| hash[key] = Array.new }
end

Public Instance Methods

get(config, &block) click to toggle source
# File lib/lanes/configuration.rb, line 40
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) click to toggle source
# File lib/lanes/configuration.rb, line 36
def on_change(config, &block)
    @observers[config.to_sym] << block
end