Class: TOML::Generator

Inherits:
Object show all
Defined in:
lib/toml/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.



6
7
8
9
10
11
12
13
14
15
# File 'lib/toml/generator.rb', line 6

def initialize(doc)
  # Ensure all the to_toml methods are injected into the base Ruby classes
  # used by TOML.
  self.class.inject!
  
  @doc = doc
  @body = doc.to_toml
  
  return @body
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



4
5
6
# File 'lib/toml/generator.rb', line 4

def body
  @body
end

#docObject (readonly)

Returns the value of attribute doc.



4
5
6
# File 'lib/toml/generator.rb', line 4

def doc
  @doc
end

Class Method Details

.inject!Object

Inject to_toml methods into the Ruby classes used by TOML (booleans, String, Numeric, Array). You can add to_toml 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_toml method).



23
24
25
26
27
# File 'lib/toml/generator.rb', line 23

def self.inject!
  return if @@injected
  require 'toml/monkey_patch'
  @@injected = true
end