lib/ruhl/rails/ruhl_presenter.rb in ruhl-0.14.0 vs lib/ruhl/rails/ruhl_presenter.rb in ruhl-0.15.0
- old
+ new
@@ -1,17 +1,38 @@
require 'ruhl/rails/active_record_presenter'
class RuhlPresenter
include ActiveRecordPresenter
-
+ include FormHelper
+
attr_reader :presentee, :context
def initialize(obj, context)
@presentee = obj
@context = context
define_paths(obj.class.name.underscore.downcase)
end
-
+
+ def method_missing(name, *args)
+ if presentee.respond_to?(name)
+ # Pass presenter method call to model so you don't have to
+ # redefine every model method in the presenter class.
+ presentee.send(name, *args)
+ elsif context.respond_to?(name)
+ # Instead of saying context.link_to('Some site', some_path)
+ # can just use link_to
+ context.send(name, *args)
+ end
+ end
+
+ # Extend scope of respond_to? to model.
+ def respond_to?(name)
+ if super
+ true
+ else
+ presentee.respond_to?(name)
+ end
+ end
end
module ActionController
class Base