Class: Garcon::Resource::Attribute

Inherits:
Mash
  • Object
show all
Includes:
Chef::Mixin::ParamsValidate
Defined in:
lib/garcon/chef/resource/attribute.rb

Class Method Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/garcon/chef/resource/attribute.rb', line 28

def method_missing(method, *args, &block)
  if (match = method.to_s.match(/(.*)=$/)) && args.size == 1
    self[match[1]] = args.first
  elsif (match = method.to_s.match(/(.*)\?$/)) && args.size == 0
    key?(match[1])
  elsif key?(method)
    self[method]
  else
    super
  end
end

Class Method Details

.from_hash(hash) ⇒ Object



45
46
47
48
49
# File 'lib/garcon/chef/resource/attribute.rb', line 45

def self.from_hash(hash)
  mash = Attribute.new(hash)
  mash.default = hash.default
  mash
end

Instance Method Details

#validate(map) ⇒ Object



40
41
42
43
# File 'lib/garcon/chef/resource/attribute.rb', line 40

def validate(map)
  data = super(symbolize_keys, map)
  data.each { |k,v| self[k.to_sym] = v }
end