Skip to content

Commit

Permalink
Adds if statement to code
Browse files Browse the repository at this point in the history
  • Loading branch information
nesquena committed Apr 13, 2011
1 parent f1ddd6a commit 8136205
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/rabl/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,10 @@ def attribute(*args)

# Creates an arbitrary code node that is included in the json output
# code(:foo) { "bar" }
def code(name, &block)
@_result[name] = block.call(@_object)
# code(:foo, :if => lambda { |m| m.foo.present? })
def code(name, options={}, &block)
append_node = options[:if].nil? || (options[:if].respond_to?(:call) && options[:if].call(@_object))
@_result[name] = block.call(@_object) if append_node
end

# Creates a child node that is included in json output
Expand Down

0 comments on commit 8136205

Please sign in to comment.