Skip to content

Instantly share code, notes, and snippets.

@shingara
Created January 6, 2015 15:02
Show Gist options
  • Save shingara/c8cce363a1807c46702d to your computer and use it in GitHub Desktop.
Save shingara/c8cce363a1807c46702d to your computer and use it in GitHub Desktop.
require 'decorators/application_decorator'
class IndexApiDecorator < ApplicationDecorator
def meta
{
:count => count,
:name => name
}
end
def count
@component.count
end
def data
if decorator
list.map{|c| decorator.new(c) }
else
list
end
end
def list
@list ||= if @component.is_a?(ItemList)
@component.criteria
else
@component
end
end
def decorator
false
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment