Class: Ansible::Ruby::DslBuilders::Block

Inherits:
Unit
  • Object
show all
Defined in:
lib/ansible/ruby/dsl_builders/block.rb

Instance Method Summary collapse

Methods inherited from Unit

#ansible_when, #become, #become_user, #ignore_errors, #vars

Methods inherited from Base

#jinja, #method_missing, #respond_to_missing?

Constructor Details

#initializeBlock

Returns a new instance of Block.



10
11
12
13
14
15
16
17
# File 'lib/ansible/ruby/dsl_builders/block.rb', line 10

def initialize
  super
  @task_builders = []
  temp_counter = 0
  @temp_counter_incrementer = lambda do
    temp_counter += 1
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Ansible::Ruby::DslBuilders::Base

Instance Method Details

#_resultObject

allow for other attributes besides the module in any order



27
28
29
30
31
32
33
34
35
# File 'lib/ansible/ruby/dsl_builders/block.rb', line 27

def _result
  tasks = @task_builders.map(&:_result)
  args = {
    tasks: tasks
  }.merge @task_args
  block = Models::Block.new args
  block.validate!
  block
end

#task(name, &block) ⇒ Object



19
20
21
22
23
24
# File 'lib/ansible/ruby/dsl_builders/block.rb', line 19

def task(name, &block)
  task_builder = Task.new name, Models::Task, @temp_counter_incrementer
  task_builder.instance_eval(&block)
  @task_builders << task_builder
  task_builder._register
end