Class: Toast::Single
Overview
GET is the only allowed verb. To make changes the URI with ID has to be used.
Instance Attribute Summary collapse
-
#model ⇒ Object
readonly
Returns the value of attribute model.
Attributes inherited from Resource
#base_uri, #payload_content_type, #prefered_media_type
Instance Method Summary collapse
- #delete ⇒ Object
- #get ⇒ Object
-
#initialize(model, subresource_name, params, config_in, config_out) ⇒ Single
constructor
A new instance of Single.
- #link(l) ⇒ Object
- #post(payload) ⇒ Object
- #put ⇒ Object
- #unlink(l) ⇒ Object
Methods inherited from Resource
#apply, build, get_class_by_resource_name
Constructor Details
#initialize(model, subresource_name, params, config_in, config_out) ⇒ Single
Returns a new instance of Single.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/toast/single.rb', line 16 def initialize model, subresource_name, params, config_in, config_out @config_in = config_in @config_out = config_out unless @config_out.singles.include? subresource_name raise ResourceNotFound end @model = model @params = params @format = params[:format] unless @model.respond_to?(subresource_name) raise "Toast Error: Cannot find class method '#{@model}.#{subresource_name}', which is configured in 'acts_as_resource > singles'." end @record = if @config_out.pass_params_to.include?(subresource_name) if @model.method(subresource_name).arity != 1 raise "Toast Error: Class method '#{@model}.#{subresource_name}' must accept one parameter, as configured by 'acts_as_resource > pass_params_to'." end @model.send(subresource_name, @params) else if(@model.method(subresource_name).arity < -1 or @model.method(subresource_name).arity > 0) raise "Toast Error: Class method '#{@model}.#{subresource_name}' must be callable w/o parameters" end @model.send(subresource_name) end raise ResourceNotFound if @record.nil? end |
Instance Attribute Details
#model ⇒ Object (readonly)
Returns the value of attribute model.
14 15 16 |
# File 'lib/toast/single.rb', line 14 def model @model end |
Instance Method Details
#delete ⇒ Object
77 78 79 |
# File 'lib/toast/single.rb', line 77 def delete raise MethodNotAllowed end |
#get ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/toast/single.rb', line 48 def get case @format when "html" { :template => "resources/#{model.to_s.underscore}", :locals => { model.to_s.pluralize.underscore.to_sym => @record } } when "json" { :json => @record.represent( @config_out.exposed_attributes, @config_out.exposed_associations, @base_uri, @config_out.media_type), :status => :ok } else raise ResourceNotFound end end |
#link(l) ⇒ Object
81 82 83 |
# File 'lib/toast/single.rb', line 81 def link l raise MethodNotAllowed end |
#post(payload) ⇒ Object
73 74 75 |
# File 'lib/toast/single.rb', line 73 def post payload raise MethodNotAllowed end |
#unlink(l) ⇒ Object
85 86 87 |
# File 'lib/toast/single.rb', line 85 def unlink l raise MethodNotAllowed end |