Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save philsturgeon/bfabe7461ec6faf9457b6a75f25c0d9c to your computer and use it in GitHub Desktop.
Save philsturgeon/bfabe7461ec6faf9457b6a75f25c0d9c to your computer and use it in GitHub Desktop.
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