Class: Praxis::MediaType
- Inherits:
-
Blueprint
- Object
- Blueprint
- Praxis::MediaType
- Includes:
- Types::MediaTypeCommon
- Defined in:
- lib/praxis/media_type.rb
Overview
An Internet Media Type as defined in RFC 1590, as used in HTTP (see RFC 2616). As used in the Praxis framework, media types also define the structure and content of entities of that type: the attributes that exist, their names and types.
An object with a media type can be represented on the wire using different structured-syntax encodings; for example, a controller might respond with an actual Widget object, but a Content-Type header specifying ‘application/vnd.acme.widget+json’; Praxis uses the information contained in the media-type definition of Widget to transform the object into an equivalent JSON representation. If the content type ends with ‘+xml’ instead, and the XML handler is registered with the framework, Praxis will respond with an XML representation of the widget. The use of media types allows your application’s models to be decoupled from its HTTP interface specification.
A media type definition consists of:
- a MIME type identifier
- attributes, each of which has a name and a data type
- named links to other resources
- named views, which expose interesting subsets of attributes
Direct Known Subclasses
Defined Under Namespace
Classes: DSLCompiler, FieldResolver
Class Method Summary collapse
Class Method Details
._finalize! ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/praxis/media_type.rb', line 71 def self._finalize! super # Only define our special links accessor if it was setup using the special DSL # (we might have an app defining an attribute called `links` on its own, in which # case we leave it be) if @attribute && self.attributes.key?(:links) && self.attributes[:links].type < Praxis::Links module_eval <<-RUBY, __FILE__, __LINE__ + 1 def links self.class::Links.new(@object) end RUBY end end |
.attributes(opts = {}, &block) ⇒ Object
67 68 69 |
# File 'lib/praxis/media_type.rb', line 67 def self.attributes(opts={}, &block) super(opts.merge(dsl_compiler: MediaType::DSLCompiler), &block) end |