Class: Zabby::Config

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

Constant Summary collapse

SETTING_LIST =
%w{server user password proxy_host proxy_user proxy_password}

Instance Method Summary collapse

Constructor Details

#initializeConfig

TODO:

Anything to configure here?

Initialize Zabby configuration settings



13
14
# File 'lib/zabby/config.rb', line 13

def initialize
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object

Dynamic setter and getter methods for the configuration variables.

Parameters:

  • name (String)

    Setting name, ending with “=” in case we are setting a value

  • args (Array)

    Setting value

  • block (Proc)

    Unused

Returns:

  • (Object)

    Return the value set

Raises:



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/zabby/config.rb', line 31

def method_missing(name, *args, &block)
  name = name.to_s.gsub(/=$/, '')
  raise ConfigurationError.new("Unknown setting '#{name}'") if !SETTING_LIST.include?(name.to_s)

  if args.empty?
    instance_variable_get("@#{name}")
  elsif args.size != 1
    raise ConfigurationError.new("Too many values for '#{name}'")
  else
    instance_variable_set("@#{name}", args.first)
  end
end

Instance Method Details

#listObject

Display configuration variables



17
18
19
20
21
22
23
24
# File 'lib/zabby/config.rb', line 17

def list
puts "Zabby configuration"
puts "==================="
  SETTING_LIST.each do |k|
    puts "#{k} = #{instance_variable_get("@#{k}")}"
  end
  nil
end