Class: Rabl::Builder

Inherits:
Object
  • Object
show all
Includes:
Partials
Defined in:
lib/rabl/builder.rb

Constant Summary collapse

SETTING_TYPES =
{
  :extends => :file,
  :node    => :name,
  :child   => :data,
  :glue    => :data
}

Constants included from Helpers

Helpers::KNOWN_OBJECT_CLASSES

Instance Method Summary collapse

Methods included from Partials

#fetch_source, #object_to_hash, #partial

Methods included from Helpers

#collection_root_name, #context_scope, #data_name, #data_object, #data_object_attribute, #determine_object_root, #escape_output, #fetch_result_from_cache, #is_collection?, #is_name_value?, #is_object?, #object_root_name, #template_cache_configured?

Constructor Details

#initialize(options = {}, &block) ⇒ Builder

Constructs a new rabl hash based on given object and options options = { :format => “json”, :root => true, :child_root => true,

:attributes, :node, :child, :glue, :extends }


16
17
18
19
20
# File 'lib/rabl/builder.rb', line 16

def initialize(options={}, &block)
  @options    = options
  @_scope     = options[:scope]
  @_view_path = options[:view_path]
end

Instance Method Details

#build(object, options = {}) ⇒ Object

Given an object and options, returns the hash representation build(@user, :format => “json”, :attributes => { … }, :root_name => “user”)



24
25
26
27
28
29
30
# File 'lib/rabl/builder.rb', line 24

def build(object, options={})
  @_object = object

  cache_results do
    compile_hash(options)
  end
end