Class: Narrator::ControllerResource

Inherits:
Object
  • Object
show all
Defined in:
lib/narrator/controller_resource.rb

Class Method Summary collapse

Instance Method Summary collapse

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.extract_options!
  @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)
  options = args.extract_options!
  resource_name = args.first
  after_filter_method = options.delete(:prepend) ? :prepend_after_filter : :after_filter
  controller_class.send(after_filter_method, options.slice(:only, :except, :if, :unless)) do |controller|
    controller.class.narrator_resource_class.new(controller, resource_name, options.except(:only, :except, :if, :unless)).send(method)
  end
end

Instance Method Details

#narrate_resourceObject



20
21
22
# File 'lib/narrator/controller_resource.rb', line 20

def narrate_resource
  @controller.narrate(resource_instance) if resource_instance.valid?
end