Class: PUNK::Settings

Inherits:
DotHash::Settings
  • Object
show all
Defined in:
lib/punk/core/settings.rb

Direct Known Subclasses

Env, Runnable

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/punk/core/settings.rb', line 11

def method_missing(key, *args, &block)
  match = /^(.*)([!?])$/.match(key)
  if match && key?(match[1]) && !key?(key)
    value = execute(match[1], *args, &block)
    case match[2]
    when '?'
      return value if value.is_a?(TrueClass) || value.is_a?(FalseClass)
    when '!'
      raise InternalServerError, "Value is nil: #{key}" if value.nil?
      return value
    end
  end
  super
end

Instance Method Details

#respond_to_missing?(key, *args) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
29
30
# File 'lib/punk/core/settings.rb', line 26

def respond_to_missing?(key, *args)
  match = /^(.*)([!?])$/.match(key)
  key = match[1] if match && !key?(key)
  super
end