Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
The most basic-ass presenter ever
class Api::V3::CompanyPresenter
attr_accessor :company, :includes
def initialize(company, includes: [])
@company = company
@includes = Array(includes)
end
def as_json
{
uuid: company.uuid,
name: company.name,
status: company.status,
}.tap do |hash|
# Don't do big slow stuff if you don't need to
hash[:foo] = company.foo_is_slow if (includes & ['foo', 'full']).any?
hash[:bar] = company.bar_is_big if (includes & ['bar', 'full']).any?
if includes.include? 'full'
hash[:bla] = company.bla
# all the other shit... including slow stuff
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.