Class: CookbookOmnifetch::Integration

Inherits:
Object
  • Object
show all
Defined in:
lib/cookbook-omnifetch/integration.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeIntegration

Returns a new instance of Integration.



39
40
41
42
43
# File 'lib/cookbook-omnifetch/integration.rb', line 39

def initialize
  self.class.configurables.each do |configurable|
    instance_variable_set("@#{configurable}".to_sym, NullValue.new)
  end
end

Class Method Details

.configurable(name) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/cookbook-omnifetch/integration.rb', line 15

def self.configurable(name)
  configurables << name

  attr_writer name

  define_method(name) do
    value = instance_variable_get("@#{name}".to_sym)
    case value
    when NullValue
      raise MissingConfiguration, "`#{name}` is not configured"
    when Proc
      value.call
    else
      value
    end
  end

end

.configurablesObject



11
12
13
# File 'lib/cookbook-omnifetch/integration.rb', line 11

def self.configurables
  @configurables ||= []
end