Class: Narrator::ControllerResource
- Inherits:
-
Object
- Object
- Narrator::ControllerResource
- Defined in:
- lib/narrator/controller_resource.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(controller, *args) ⇒ ControllerResource
constructor
A new instance of ControllerResource.
- #narrate_resource ⇒ Object
Constructor Details
#initialize(controller, *args) ⇒ ControllerResource
Returns a new instance of ControllerResource.
13 14 15 16 17 18 |
# File 'lib/narrator/controller_resource.rb', line 13 def initialize(controller, *args) @controller = controller @params = controller.params @options = args. @name = args.first end |
Class Method Details
.add_after_filter(controller_class, method, *args) ⇒ Object
4 5 6 7 8 9 10 11 |
# File 'lib/narrator/controller_resource.rb', line 4 def self.add_after_filter(controller_class, method, *args) = args. resource_name = args.first after_filter_method = .delete(:prepend) ? :prepend_after_filter : :after_filter controller_class.send(after_filter_method, .slice(:only, :except, :if, :unless)) do |controller| controller.class.narrator_resource_class.new(controller, resource_name, .except(:only, :except, :if, :unless)).send(method) end end |
Instance Method Details
#narrate_resource ⇒ Object
20 21 22 |
# File 'lib/narrator/controller_resource.rb', line 20 def narrate_resource @controller.narrate(resource_instance) if resource_instance.valid? end |