Class: Ansible::Ruby::DslBuilders::Base
- Inherits:
-
Object
- Object
- Ansible::Ruby::DslBuilders::Base
- Defined in:
- lib/ansible/ruby/dsl_builders/base.rb
Direct Known Subclasses
Args, FileLevel, ModuleCall, Task, Tasks
Instance Attribute Summary collapse
-
#result ⇒ Object
readonly
Returns the value of attribute result.
Instance Method Summary collapse
- #evaluate(*args, &block) ⇒ Object
-
#initialize ⇒ Base
constructor
A new instance of Base.
- #method_missing(id, *args, &block) ⇒ Object
- #respond_to_missing? ⇒ Boolean
Constructor Details
#initialize ⇒ Base
Returns a new instance of Base.
5 6 7 |
# File 'lib/ansible/ruby/dsl_builders/base.rb', line 5 def initialize @result = nil end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(id, *args, &block) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/ansible/ruby/dsl_builders/base.rb', line 25 def method_missing(id, *args, &block) result = begin process_method id, *args, &block rescue StandardError => our_error begin super rescue NoMethodError => ruby_error matching_line = ruby_error.backtrace .map { |str| str.split ':' } .find { |arr| arr[0] == '(eval)' }[1] raise "#{our_error.} at line #{matching_line}!" end end method_missing_return id, result, *args end |
Instance Attribute Details
#result ⇒ Object (readonly)
Returns the value of attribute result.
9 10 11 |
# File 'lib/ansible/ruby/dsl_builders/base.rb', line 9 def result @result end |
Instance Method Details
#evaluate(*args, &block) ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'lib/ansible/ruby/dsl_builders/base.rb', line 11 def evaluate(*args, &block) if block instance_eval(&block) else raise 'Expected code as an argument if no block supplied!' unless args.length == 1 instance_eval args[0] end @result end |
#respond_to_missing? ⇒ Boolean
21 22 23 |
# File 'lib/ansible/ruby/dsl_builders/base.rb', line 21 def respond_to_missing?(*) super end |