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

Methods

Included Modules

Helpers Partials

Constants

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

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

Protected Instance methods

Indicates an attribute or method should be included in the json output attribute :foo, :as => "bar" attribute :foo, :as => "bar", :if => lambda { |m| m.foo }

attributes(name, options = {})

Alias for attribute

Evaluate conditions given a symbol/proc/lambda/variable to evaluate

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

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, :if => lambda { |m| m.foo.present? }) { "bar" }

resolve_condition(:if => true) => true resolve_condition(:if => ‘Im truthy’) => true resolve_condition(:if => lambda { |m| false }) => false resolve_condition(:unless => lambda { |m| false }) => true resolve_condition(:unless => lambda { |m| false }, :if => proc { true}) => true

[Validate]