Module: Resourcery::ControllerMacro

Defined in:
lib/resourcery/controller_macro.rb

Instance Method Summary collapse

Instance Method Details

#serve_resource(klass = nil, opts = {}) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/resourcery/controller_macro.rb', line 3

def serve_resource(klass = nil, opts = {})
  @resource_options = {
    finder: :find
  }.merge(opts)

  extend  ControllerExtensions::ClassMethods
  include ControllerExtensions::Filters
  include ControllerExtensions::InstanceMethods

  # determine resource class
  @resource_class = case klass
    when Class then klass
    when Symbol then klass.to_s.classify.constantize
    else name.gsub(/Controller$/, '').singularize.constantize
  end

  helper_method :resource, :collection

  # Make sure we'll serve at least HTML
  respond_to :html if mimes_for_respond_to.empty?
end