Module: Baptize::Plugins::Env

Included in:
DSL
Defined in:
lib/baptize/plugins/env.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



38
39
40
41
42
43
44
# File 'lib/baptize/plugins/env.rb', line 38

def method_missing(sym, *args, &block)
  if any?(sym)
    fetch(sym)
  else
    super
  end
end

Instance Method Details

#any?(key) ⇒ Boolean

Returns:

  • (Boolean)


5
6
7
8
9
10
11
12
# File 'lib/baptize/plugins/env.rb', line 5

def any?(key)
  value = fetch(key)
  if value && value.respond_to?(:any?)
    value.any?
  else
    !fetch(key).nil?
  end
end

#delete(key) ⇒ Object



22
23
24
# File 'lib/baptize/plugins/env.rb', line 22

def delete(key)
  config.delete(key)
end

#fetch(key, default = nil, &block) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/baptize/plugins/env.rb', line 26

def fetch(key, default=nil, &block)
  value = fetch_for(key, default, &block)
  while callable_without_parameters?(value)
    value = set(key, value.call)
  end
  return value
end

#respond_to?(sym, include_priv = false) ⇒ Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/baptize/plugins/env.rb', line 34

def respond_to?(sym, include_priv = false)
  super || any?(sym)
end

#set(key, value = nil, &block) ⇒ Object



14
15
16
# File 'lib/baptize/plugins/env.rb', line 14

def set(key, value=nil, &block)
  config[key] = block || value
end

#set_if_empty(key, value = nil, &block) ⇒ Object



18
19
20
# File 'lib/baptize/plugins/env.rb', line 18

def set_if_empty(key, value=nil, &block)
  set(key, value, &block) unless config.has_key? key
end