Sha256: 0ce1fd7b9619eb41daf4f8c0fbfddc804c60f37301353819be5a7a8912a9972c
Contents?: true
Size: 839 Bytes
Versions: 2
Compression:
Stored size: 839 Bytes
Contents
module Roar::Rails module ModelMethods # DISCUSS: move this into a generic namespace as we could need that in Sinatra as well. def extend_with_representer!(model, representer=nil) representer ||= representer_for_model(model) model.extend(representer) end private def representer_for_model(model) (model.class.name + "Representer").constantize end end module Responder include ModelMethods def display(model, given_options={}) # TODO: remove the [] semantics, this should be done with a Collection representer. if model.respond_to?(:map!) model.map! do |r| extend_with_representer!(r) r.to_hash end else extend_with_representer!(model, options.delete(:with_representer)) end super end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
roar-rails-0.0.5 | lib/roar/rails/responder.rb |
roar-rails-0.0.4 | lib/roar/rails/responder.rb |