Class: Builder::Json

Inherits:
Hash show all
Defined in:
lib/builder/json.rb

Instance Method Summary collapse

Methods inherited from Hash

#<<, #array_mode, #method_missing, #tag!, #text!

Methods inherited from Abstract

#comment!, #declare!, #instruct!, #nil?

Constructor Details

#initialize(options = {}) ⇒ Json

Returns a new instance of Json.



7
8
9
10
11
12
13
14
# File 'lib/builder/json.rb', line 7

def initialize(options = {})
  # @default_content_key is used in such case: markup.key(value, :attr_key => attr_value)
  # in this case, we need some key for value.
  @default_content_key  = (options[:default_content_key] || :content).to_sym
  @include_root = options[:include_root]
  @target = {}
  @array_mode = false
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Builder::Hash

Instance Method Details

#target!Object



16
17
18
19
20
21
22
# File 'lib/builder/json.rb', line 16

def target!
  if @include_root
    @target.to_json
  else
    @target[@root].to_json
  end
end