Class: TFDSL::Block
- Inherits:
-
Object
- Object
- TFDSL::Block
- Defined in:
- lib/tfdsl/block.rb
Overview
This class is the representation of terraform configuration block www.terraform.io/docs/configuration/
Constant Summary collapse
- @@formatter =
Formatter.new
Instance Attribute Summary collapse
-
#__labels__ ⇒ Object
readonly
Returns the value of attribute __labels__.
-
#__type__ ⇒ Object
readonly
Returns the value of attribute __type__.
Instance Method Summary collapse
-
#initialize(&block) ⇒ Block
constructor
A new instance of Block.
- #method_missing(method_name, *args, &block) ⇒ Object
- #respond_to_missing?(_method_name, _include_private = true) ⇒ Boolean
- #to_s ⇒ Object
- #to_str ⇒ Object
- #to_tf ⇒ Object
Constructor Details
#initialize(&block) ⇒ Block
Returns a new instance of Block.
7 8 9 10 |
# File 'lib/tfdsl/block.rb', line 7 def initialize(&block) @__blocks__ = [] instance_eval(&block) if block_given? end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/tfdsl/block.rb', line 12 def method_missing(method_name, *args, &block) super if [:respond_to_missing?].include? method_name method = method_name.to_s.gsub(/=$/, '') if block_given? r = Block.new r.__type__ = method r.__labels__ = args @__blocks__ << r return r.instance_eval(&block) end return instance_variable_set "@#{method}", *args unless args.empty? return instance_variable_get "@#{method}" if args.empty? end |
Instance Attribute Details
#__labels__ ⇒ Object (readonly)
Returns the value of attribute __labels__.
5 6 7 |
# File 'lib/tfdsl/block.rb', line 5 def __labels__ @__labels__ end |
#__type__ ⇒ Object (readonly)
Returns the value of attribute __type__.
5 6 7 |
# File 'lib/tfdsl/block.rb', line 5 def __type__ @__type__ end |
Instance Method Details
#respond_to_missing?(_method_name, _include_private = true) ⇒ Boolean
28 29 30 |
# File 'lib/tfdsl/block.rb', line 28 def respond_to_missing?(_method_name, _include_private = true) true end |
#to_s ⇒ Object
40 41 42 |
# File 'lib/tfdsl/block.rb', line 40 def to_s to_tf end |
#to_str ⇒ Object
36 37 38 |
# File 'lib/tfdsl/block.rb', line 36 def to_str to_tf end |
#to_tf ⇒ Object
32 33 34 |
# File 'lib/tfdsl/block.rb', line 32 def to_tf @@formatter.format self end |