Class: Producer::Core::Recipe

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/producer/core/recipe.rb,
lib/producer/core/recipe/file_evaluator.rb

Defined Under Namespace

Classes: FileEvaluator

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(env) ⇒ Recipe

Returns a new instance of Recipe.



27
28
29
30
# File 'lib/producer/core/recipe.rb', line 27

def initialize env
  @env    = env
  @tasks  = []
end

Instance Attribute Details

#envObject (readonly)

Returns the value of attribute env.



25
26
27
# File 'lib/producer/core/recipe.rb', line 25

def env
  @env
end

#tasksObject (readonly)

Returns the value of attribute tasks.



25
26
27
# File 'lib/producer/core/recipe.rb', line 25

def tasks
  @tasks
end

Class Method Details

.compose_macro(name, macro, *base_args) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/producer/core/recipe.rb', line 13

def compose_macro name, macro, *base_args
  [self, Task].each do |klass|
    klass.class_eval do
      define_method(name) { |*args| send macro, *(base_args + args) }
    end
  end
end

.define_macro(name, block) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/producer/core/recipe.rb', line 5

def define_macro name, block
  [self, Task].each do |klass|
    klass.class_eval do
      define_method(name) { |*args| task name, *args, &block }
    end
  end
end

Instance Method Details

#compose_macro(name, macro, *base_args) ⇒ Object



48
49
50
# File 'lib/producer/core/recipe.rb', line 48

def compose_macro name, macro, *base_args
  self.class.class_eval { compose_macro name, macro, *base_args }
end

#macro(name, &block) ⇒ Object



44
45
46
# File 'lib/producer/core/recipe.rb', line 44

def macro name, &block
  self.class.class_eval { define_macro name, block }
end

#source(filepath) ⇒ Object



32
33
34
# File 'lib/producer/core/recipe.rb', line 32

def source filepath
  instance_eval File.read("./#{filepath}.rb"), "#{filepath}.rb"
end

#target(hostname = nil) ⇒ Object



36
37
38
# File 'lib/producer/core/recipe.rb', line 36

def target hostname = nil
  if hostname then env.target ||= hostname else env.target end
end

#task(name, *args, &block) ⇒ Object



40
41
42
# File 'lib/producer/core/recipe.rb', line 40

def task name, *args, &block
  Task.evaluate(env, name, *args, &block).tap { |o| @tasks << o }
end

#test_macro(name, &block) ⇒ Object



52
53
54
# File 'lib/producer/core/recipe.rb', line 52

def test_macro name, &block
  Condition.define_test(name, block)
end