Class: Grape::API

Inherits:
Object
  • Object
show all
Includes:
Resources
Defined in:
lib/grape/resources.rb

Constant Summary

Constants included from Resources

Resources::VERSION

Class Method Summary collapse

Methods included from Resources

apply_attributes, create_endpoint_for, delete_endpoint_for, find, get_endpoint_for, list, list_endpoint_for, load_singular_endpoints, singular_name_for, update_endpoint_for

Class Method Details

.resources_for(clazz, methods = [:list, :get, :post, :put, :delete]) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/grape/resources.rb', line 8

def resources_for( clazz, methods=[:list, :get, :post, :put, :delete])
  raise Error("To use grape_resources on a given class it should inherit from ActiveRecord::Base.( at least for now buddy ;) )") unless clazz < ActiveRecord::Base
  
  plural_name = clazz.name.pluralize.underscore        
  resources plural_name.to_sym do
    Grape::Resources.list_endpoint_for( clazz, self ) if methods.include?(:list)
    yield if block_given?
  end

  Grape::Resources.load_singular_endpoints(clazz, self, methods)   
end