Class: Waves::Foundations::REST::Resource
- Extended by:
- Resources::Mixin::ClassMethods
- Includes:
- Functor::Method, ResponseMixin
- Defined in:
- lib/waves/foundations/rest.rb
Overview
Should maybe insulate the term -> HTTP method mapping a bit more. Or less. –rue
Base class to use for resources.
Mainly here for simple access to some convenience methods.
Class Method Summary collapse
-
.creatable(&block) ⇒ Object
Creatability definition block (POST).
-
.introduce_mime(type, options) ⇒ Object
Introduce new MIME type and its extension(s).
-
.representation(*types, &block) ⇒ Object
Representation definition block.
-
.url_of_form(spec) ⇒ Object
URL format specification.
-
.viewable(&block) ⇒ Object
Viewability definition block (GET).
Methods included from Resources::Mixin::ClassMethods
after, always, before, handler, on, paths, with, wrap
Methods included from ResponseMixin
#app, #attributes, #captured, #controller, #http_cache, #log, #main, #model, #model_name, #modified?, #not_found, #not_modified, #params, #paths, #query, #redirect, #resource, #response, #traits, #view
Class Method Details
.creatable(&block) ⇒ Object
Creatability definition block (POST)
196 197 198 199 200 201 202 203 |
# File 'lib/waves/foundations/rest.rb', line 196 def self.creatable(&block) raise BadDefinition, "No .url_of_form specified!" unless @pathspec @method = :post instance_eval &block ensure @method = nil end |
.introduce_mime(type, options) ⇒ Object
Introduce new MIME type and its extension(s)
This is used to allow resources to differentiate between different kinds of representations (or content types.) For example, a Wiki page resource may introduce a MIME type for an “editable” representation, which then allows producing the appropriate editor interface. The MIME types added thusly should follow the normal semantics, which means that usually they will be of the form “application/vnd.somestring”. As an example, the Unspecified MIME type is defined in Waves as “vnd.com.rubywaves.unspecified”.
The users can communicate the desired MIME type either the correct way of using the Accept header or, commonly with a web browser, by using the extension.
221 222 223 224 225 226 227 228 229 230 231 232 |
# File 'lib/waves/foundations/rest.rb', line 221 def self.introduce_mime(type, ) exts = Array([:exts]) raise ArgumentError, "Must give file extensions for MIME!" if exts.empty? Waves::MimeExts[type] += exts Waves::MimeExts[type].uniq! exts.each {|ext| Waves::MimeTypes[ext] << type Waves::MimeTypes[ext].uniq! } end |
.representation(*types, &block) ⇒ Object
Representation definition block
236 237 238 239 |
# File 'lib/waves/foundations/rest.rb', line 236 def self.representation(*types, &block) # @todo Faking it. on(@method, @pathspec, :requested => types) {} end |
.url_of_form(spec) ⇒ Object
URL format specification.
The resource defines its own parts, but the app may provide a prefix or even completely override its selection (so long as it can provide all the named captures the resource is expecting, which means that type of override is rare in practice.
249 250 251 |
# File 'lib/waves/foundations/rest.rb', line 249 def self.url_of_form(spec) @pathspec = Application.url_for self, spec end |
.viewable(&block) ⇒ Object
Viewability definition block (GET)
257 258 259 260 261 262 263 264 |
# File 'lib/waves/foundations/rest.rb', line 257 def self.viewable(&block) raise BadDefinition, "No .url_of_form specified!" unless @pathspec @method = :get instance_eval &block ensure @method = nil end |