Class: HCL::Generator

Inherits:
Object show all
Defined in:
lib/hcl/generator.rb

Constant Summary collapse

@@injected =

Whether or not the injections have already been done.

false

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#bodyObject (readonly)

Returns the value of attribute body.



2
3
4
# File 'lib/hcl/generator.rb', line 2

def body
  @body
end

#docObject (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