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',
}

Instance Method Summary collapse

Constructor Details

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

load the configuration file and apply default settings



25
26
27
28
29
30
# File 'lib/ferret_server.rb', line 25

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] || {})
  @config['uri'] = "druby://#{host}:#{port}" if @everything[RAILS_ENV]
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



34
35
36
# File 'lib/ferret_server.rb', line 34

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