Class: Ansible::Ruby::DslBuilders::FileLevel

Inherits:
Base
  • Object
show all
Defined in:
lib/ansible/ruby/dsl_builders/file_level.rb

Instance Attribute Summary

Attributes inherited from Base

#result

Instance Method Summary collapse

Methods inherited from Base

#method_missing, #respond_to_missing?

Constructor Details

#initializeFileLevel

Returns a new instance of FileLevel.



9
10
11
12
13
# File 'lib/ansible/ruby/dsl_builders/file_level.rb', line 9

def initialize
  @plays = []
  @tasks_builder = nil
  @context = nil
end

Dynamic Method Handling

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

Instance Method Details

#evaluateObject



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/ansible/ruby/dsl_builders/file_level.rb', line 33

def evaluate(*)
  super
  case @context
  when :playbook
    # TODO: Add a playbook DSL and do this like tasks
    Models::Playbook.new plays: @plays
  when :tasks
    @tasks_builder.evaluate {}
  else
    raise "Unknown context #{@context}"
  end
end

#play(name = nil, &block) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/ansible/ruby/dsl_builders/file_level.rb', line 15

def play(name = nil, &block)
  if @context == :tasks
    raise 'This is a tasks file due to a task coming before this play, cannot use play here!'
  end
  @context = :playbook
  play_builder = Play.new name
  @plays << play_builder.evaluate(&block)
end

#process_method(id) ⇒ Object



46
47
48
# File 'lib/ansible/ruby/dsl_builders/file_level.rb', line 46

def process_method(id, *)
  raise "undefined local variable or method `#{id}'"
end

#task(name, &block) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/ansible/ruby/dsl_builders/file_level.rb', line 24

def task(name, &block)
  if @context == :playbook
    raise 'This is a playbook file due to a play coming before this task, cannot use task here!'
  end
  @context = :tasks
  @tasks_builder ||= Tasks.new
  @tasks_builder.task name, &block
end