Class: Builder::JsonFormat

Inherits:
HashStructure show all
Defined in:
lib/builder/json_format.rb

Instance Method Summary collapse

Methods inherited from HashStructure

#array_mode, #content!, #method_missing, #root!, #tag!, #text!

Methods inherited from Abstract

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

Constructor Details

#initialize(options = {}) ⇒ JsonFormat

Returns a new instance of JsonFormat.



7
8
9
# File 'lib/builder/json_format.rb', line 7

def initialize(options = {})
  super(options)
end

Dynamic Method Handling

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

Instance Method Details

#<<(_target) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/builder/json_format.rb', line 19

def <<(_target)
  if _target.is_a?(String)
    _target = ::ActiveSupport::JSON.decode(_target)
    _target.symbolize_keys! if _target.is_a?(Hash)
  end

  super(_target)
end

#serialization_method!Object



11
12
13
# File 'lib/builder/json_format.rb', line 11

def serialization_method!
  :to_json
end

#target!Object



28
29
30
31
32
33
34
# File 'lib/builder/json_format.rb', line 28

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

#to_sObject



15
16
17
# File 'lib/builder/json_format.rb', line 15

def to_s
  target!.to_json
end