lib/roar/rails/responder.rb in roar-rails-0.0.12 vs lib/roar/rails/responder.rb in roar-rails-0.0.13
- old
+ new
@@ -1,39 +1,29 @@
module Roar::Rails
- module ModelMethods
- private
- # DISCUSS: move this into a generic namespace as we could need that in Sinatra as well.
- def extend_with!(model, representer) # TODO: rename to #prepare_model.
- representer.prepare(model)
- end
-
- def prepare_model!(model)
- controller.prepare_model_for(format, model, options)
- end
- end
-
module Responder
- include ModelMethods
-
- # DISCUSS: why THE FUCK is options not passed as a method argument but kept as an internal instance variable in the responder? this is something i will never understand about Rails.
def display(model, *args)
if representer = options.delete(:represent_items_with)
render_items_with(model, representer) # convenience API, not recommended since it's missing hypermedia.
return super
end
- model = prepare_model!(model)
+ model = prepare_model_for(format, model, options)
super
end
private
def render_items_with(collection, representer)
- collection.map! do |m| # DISCUSS: i don't like changing the method argument here.
- extend_with!(m, representer)
- m.to_hash # FIXME: huh? and what about XML?
+ collection.map! do |mdl| # DISCUSS: i don't like changing the method argument here.
+ representer.prepare(mdl).to_hash(options) # FIXME: huh? and what about XML?
end
end
+ module PrepareModel
+ def prepare_model_for(format, model, options) # overwritten in VersionStrategy/3.0.
+ controller.prepare_model_for(format, model, options)
+ end
+ end
+ include PrepareModel
include VersionStrategy
end
end