Class: ActsAsFerret::Remote::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/ferret_server.rb

Constant Summary collapse

DEFAULTS =
{
  'host'      => 'localhost',
  'port'      => '9009',
  'cf'        => "#{RAILS_ROOT}/config/ferret_server.yml",
  'pid_file'  => "#{RAILS_ROOT}/log/ferret_server.pid",
  'log_file'  => "#{RAILS_ROOT}/log/ferret_server.log",
  'log_level' => 'debug',
  'socket'    => nil,
  'script'    => nil
}

Instance Method Summary collapse

Constructor Details

#initialize(file = DEFAULTS['cf']) ⇒ Config

load the configuration file and apply default settings



27
28
29
30
31
32
33
34
# File 'lib/ferret_server.rb', line 27

def initialize (file=DEFAULTS['cf'])
  @everything = YAML.load(ERB.new(IO.read(file)).result)
  raise "malformed ferret server config" unless @everything.is_a?(Hash)
  @config = DEFAULTS.merge(@everything[RAILS_ENV] || {})
  if @everything[RAILS_ENV]
    @config['uri'] = socket.nil? ? "druby://#{host}:#{port}" : "drbunix:#{socket}"
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object

treat the keys of the config data as methods



38
39
40
# File 'lib/ferret_server.rb', line 38

def method_missing (name, *args)
  @config.has_key?(name.to_s) ? @config[name.to_s] : super
end