Class: ActsAsFerret::Server::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/acts_as_ferret/server/config.rb

Constant Summary collapse

DEFAULTS =
{
  'host'      => 'localhost',
  'port'      => '9009',
  'cf'        => "config/ferret_server.yml",
  'pid_file'  => "log/ferret_server.pid",
  'log_file'  => "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



23
24
25
26
27
28
29
30
# File 'lib/acts_as_ferret/server/config.rb', line 23

def initialize(file = DEFAULTS['cf'])
  @everything = YAML.load(ERB.new(IO.read(abs_config_file_path(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



42
43
44
# File 'lib/acts_as_ferret/server/config.rb', line 42

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

Instance Method Details

#abs_config_file_path(path) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/acts_as_ferret/server/config.rb', line 32

def abs_config_file_path(path)
  if path =~ /^\//
    path
  else
    Rails.root.join(path).to_s
  end
end