Class: HCL::Generator
Constant Summary collapse
- @@injected =
Whether or not the injections have already been done.
false
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#doc ⇒ Object
readonly
Returns the value of attribute doc.
Class Method Summary collapse
-
.inject! ⇒ Object
Inject to_hcl methods into the Ruby classes used by HCL (booleans, String, Numeric, Array).
Instance Method Summary collapse
-
#initialize(doc) ⇒ Generator
constructor
A new instance of Generator.
Constructor Details
#initialize(doc) ⇒ Generator
Returns a new instance of Generator.
4 5 6 7 8 9 10 11 12 13 |
# File 'lib/hcl/generator.rb', line 4 def initialize(doc) # Ensure all the to_hcl methods are injected into the base Ruby classes # used by HCL. self.class.inject! @doc = doc @body = doc.to_hcl return @body end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
2 3 4 |
# File 'lib/hcl/generator.rb', line 2 def body @body end |
#doc ⇒ Object (readonly)
Returns the value of attribute doc.
2 3 4 |
# File 'lib/hcl/generator.rb', line 2 def doc @doc end |
Class Method Details
.inject! ⇒ Object
Inject to_hcl methods into the Ruby classes used by HCL (booleans, String, Numeric, Array). You can add to_hcl methods to your own classes to allow them to be easily serialized by the generator (and it will shout if something doesn’t have a to_hcl method).
21 22 23 24 25 |
# File 'lib/hcl/generator.rb', line 21 def self.inject! return if @@injected require 'hcl/monkey_patch' @@injected = true end |