Created
September 7, 2012 20:48
-
-
Save jredville/3669487 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Reportable | |
def as_json | |
{:meta => meta, :report => report} | |
end | |
end | |
class ReportPresenter | |
include Reportable | |
def self.column(name, options={}) | |
end | |
def meta | |
#...prepare meta | |
end | |
def report | |
# prepare report based on columns | |
end | |
end | |
class SoftwareOverviewPresenter < ReportPresenter | |
column :application, :model => Applications, :column => :name | |
column :publisher, :from => :application, :path => "publisher.name" | |
column :used, :from => lambda {} | |
end | |
class OrganizationalUnitTagCloudPresenter | |
def as_json | |
#... | |
end | |
end | |
class CombinationPresenter | |
def initialize(*items) | |
@items = items | |
end | |
def as_json | |
@items.each_with_object({}) { |item, res| res.merge(item.as_json) } | |
end | |
end | |
# in sinatra app | |
get 'report' do | |
report = company.reports.software_overview(query) | |
ous = OrganizationalUnitTagCloudPresenter.new company.ous | |
app.combine(report, ous) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I like the base presenter class for report. I'd nix the Reportable module given it's tightly dependent on the presenter directly though. I'm still undecided on the column stuff and worry that you may need some sort of setup that might make the column method a bit more complex than a PORO. That being said, having a base class to deal with sorting, pagination, and filtering makes perfect sense.
For the sinatra app portion, I like having the idea of a 1:1 mapping between the report identifier and a presenter... if that presenter wants to delegate to a presenter internally, it's free to do so (as in the case for OU) but having the sinatra be a very simple dispatcher where it just needs to resolve the report and hand it the request context seems better.