Class: Itamae::Definition

Inherits:
Resource::Base show all
Defined in:
lib/itamae/definition.rb

Class Attribute Summary collapse

Attributes inherited from Resource::Base

#attributes, #current_attributes, #notifications, #recipe, #resource_name, #subscriptions, #updated

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Resource::Base

#action_nothing, define_attribute, inherited, #resource_type

Constructor Details

#initialize(*args) ⇒ Definition

Returns a new instance of Definition.



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/itamae/definition.rb', line 22

def initialize(*args)
  super

  r = Recipe::RecipeFromDefinition.new(
    runner,
    self.class.defined_in_recipe.path,
  )
  recipe.children << r

  r.definition = self
  r.load(params: @attributes.merge(name: resource_name))
end

Class Attribute Details

.defined_in_recipeObject

Returns the value of attribute defined_in_recipe.



7
8
9
# File 'lib/itamae/definition.rb', line 7

def defined_in_recipe
  @defined_in_recipe
end

.definition_blockObject

Returns the value of attribute definition_block.



6
7
8
# File 'lib/itamae/definition.rb', line 6

def definition_block
  @definition_block
end

Class Method Details

.create_class(name, params, defined_in_recipe, &block) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/itamae/definition.rb', line 9

def create_class(name, params, defined_in_recipe, &block)
  Class.new(self).tap do |klass|
    klass.definition_block = block
    klass.defined_in_recipe = defined_in_recipe

    klass.define_attribute :action, default: :run
    params.each_pair do |key, value|
      klass.define_attribute key.to_sym, type: Object, default: value
    end
  end
end

Instance Method Details

#run(*args) ⇒ Object



35
36
37
# File 'lib/itamae/definition.rb', line 35

def run(*args)
  # nothing
end