Module: Cenit::Config

Included in:
Cenit
Defined in:
lib/cenit/config.rb,
lib/cenit/config/version.rb

Constant Summary collapse

VERSION =
'0.0.1'

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(symbol, *args) ⇒ Object



31
32
33
34
35
36
37
38
39
# File 'lib/cenit/config.rb', line 31

def method_missing(symbol, *args)
  if !symbol.to_s.end_with?('=') && ((args.length == 0 && block_given?) || args.length == 1 && !block_given?)
    self[symbol] = block_given? ? yield : args[0]
  elsif args.length == 0 && !block_given?
    self[symbol]
  else
    super
  end
end

Instance Method Details

#[](option) ⇒ Object



15
16
17
# File 'lib/cenit/config.rb', line 15

def [](option)
  (value = options[option]).respond_to?(:call) ? value.call : value
end

#[]=(option, value) ⇒ Object



19
20
21
# File 'lib/cenit/config.rb', line 19

def []=(option, value)
  options[option] = value
end

#config(&block) ⇒ Object



23
24
25
# File 'lib/cenit/config.rb', line 23

def config(&block)
  class_eval(&block) if block
end

#default_optionsObject



11
12
13
# File 'lib/cenit/config.rb', line 11

def default_options
  {}
end

#optionsObject



7
8
9
# File 'lib/cenit/config.rb', line 7

def options
  @options ||= default_options
end

#respond_to?(*args) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/cenit/config.rb', line 27

def respond_to?(*args)
  super || options.has_key?(args[0])
end