Class Rabl::Builder
In: lib/rabl/builder.rb
Parent: Object

Methods

attribute   attributes   build   child   code   compile_hash   extends   glue   new   node   resolve_condition  

Included Modules

Rabl::Partials

Public Class methods

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

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

Public Instance methods

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

Protected Instance methods

Indicates an attribute or method should be included in the json output attribute :foo, :as => "bar"

attributes(name, options={})

Alias for attribute

Creates a child node that is included in json output child(@user) { attribute :full_name } child(@user => :person) { … } child(@users => :people) { … }

code(name, options={}, &block)

Alias for node

Returns a hash representation of the data object compile_hash(:root_name => false) compile_hash(:root_name => "user")

Extends an existing rabl template with additional attributes in the block extends("users/show") { attribute :full_name }

Glues data from a child node to the json_output glue(@user) { attribute :full_name => :user_full_name }

Creates an arbitrary node that is included in the json output node(:foo) { "bar" } node(:foo) { "bar" } node(:foo, :if => lambda { |m| m.foo.present? }) { "bar" }

resolve_condition(:if => true) => true resolve_condition(:if => lambda { |m| false }) => false resolve_condition(:unless => lambda { |m| true }) => true

[Validate]