Class: Rabl::Builder

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

Constant Summary

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 }


9
10
11
12
13
# File 'lib/rabl/builder.rb', line 9

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”)



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

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

  cache_results do
    compile_hash(options)
  end
end