Sha256: 44e7a6a1360ff453dda155242a6dbb79afe8b83debf90215bb72cb778aed8f41

Contents?: true

Size: 808 Bytes

Versions: 5

Compression:

Stored size: 808 Bytes

Contents

module TOML  
  class Generator
    attr_reader :body, :doc

    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
    
    # Whether or not the injections have already been done.
    @@injected = false
    # 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).
    def self.inject!
      return if @@injected
      require 'toml/monkey_patch'
      @@injected = true
    end
  end#Generator
end#TOML

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
toml_empty-0.3.0 lib/toml/generator.rb
toml-0.3.0 lib/toml/generator.rb
toml_empty-0.1.0 lib/toml/generator.rb
toml-0.2.0 lib/toml/generator.rb
toml-0.1.2 lib/toml/generator.rb