Module: ClassyResources

Defined in:
lib/classy_resources/sequel_errors_to_xml.rb,
lib/classy_resources.rb,
lib/classy_resources/sequel.rb,
lib/classy_resources/active_record.rb,
lib/classy_resources/post_body_params.rb,
lib/classy_resources/post_body_param_parsing.rb

Overview

stolen from active record

Defined Under Namespace

Modules: ActiveRecord, Sequel, SequelErrorsToXml Classes: PostBodyParams, ResourceBuilder

Instance Method Summary collapse

Instance Method Details

#class_for(resource) ⇒ Object



8
9
10
# File 'lib/classy_resources.rb', line 8

def class_for(resource)
  resource.to_s.singularize.classify.constantize
end

#collection_url_for(resource, format) ⇒ Object



16
17
18
# File 'lib/classy_resources.rb', line 16

def collection_url_for(resource, format)
  "/#{resource}.#{format}"
end

#define_resource(*options) ⇒ Object



12
13
14
# File 'lib/classy_resources.rb', line 12

def define_resource(*options)
  ResourceBuilder.new(self, *options)
end

#object_route_url(resource, format) ⇒ Object



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

def object_route_url(resource, format)
  "/#{resource}/:id.#{format}"
end

#object_url_for(resource, format, object) ⇒ Object



24
25
26
# File 'lib/classy_resources.rb', line 24

def object_url_for(resource, format, object)
  "/#{resource}/#{object.id}.#{format}"
end

#serialize(object, format) ⇒ Object



32
33
34
# File 'lib/classy_resources.rb', line 32

def serialize(object, format)
  object.send(:"to_#{format}")
end

#set_content_type(format) ⇒ Object



28
29
30
# File 'lib/classy_resources.rb', line 28

def set_content_type(format)
  content_type Mime.const_get(format.to_s.upcase).to_s
end