Class: Ricordami::Config

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

Constant Summary collapse

ATTRIBUTE_NAMES =
[:redis_host, :redis_port, :redis_db, :thread_safe]

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



20
21
22
# File 'lib/ricordami/configuration.rb', line 20

def initialize
  @options = {}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &blk) ⇒ Object (private)



30
31
32
33
34
35
36
37
# File 'lib/ricordami/configuration.rb', line 30

def method_missing(meth, *args, &blk)
  return @options[meth] if ATTRIBUTE_NAMES.include?(meth)
  if args.length == 1 && match = /^(.*)=$/.match(meth.to_s)
    name = match[1].to_sym
    return @options[name] = args.first if ATTRIBUTE_NAMES.include?(name)
  end
  raise AttributeNotSupported.new("attribute #{meth.to_s.inspect} is not supported")
end

Instance Method Details

#from_hash(options) ⇒ Object



24
25
26
# File 'lib/ricordami/configuration.rb', line 24

def from_hash(options)
  @options = options.slice(*ATTRIBUTE_NAMES)
end