Module: Resto::Format
- Defined in:
- lib/resto/format.rb,
lib/resto/format/xml.rb,
lib/resto/format/json.rb,
lib/resto/format/plain.rb,
lib/resto/format/default.rb
Overview
This module is only used internally by these classes/modules: Resto::Request::Base (see method Request::Header#format). Resto::Response::Base (see method Response::Base#format).
Add a Format
If a user of Resto wants to handle a format different from whats available, she can create a class in the Format module. Then include the Format module into the meta class and override the methods that she wants to change. See example below.
Example:
module Resto
module Format
class Foo; end
class << Foo
include Format
def extension; 'foo' end
def accept; 'foo'; end
end
end
end
Defined Under Namespace
Classes: Default, Json, Plain, Xml
Class Method Summary collapse
-
.get(symbol = :default) ⇒ Format, ...
Returns the class that corresponds to the symbol argument.
Instance Method Summary collapse
-
#accept ⇒ String
The accept header.
-
#content_type ⇒ nil
The content-type header.
-
#decode(*args) ⇒ Array<Object>
Returns the arguments as an Array.
-
#encode(*args) ⇒ Object
Returns the first argument.
-
#extension ⇒ nil
The extension.
Class Method Details
Instance Method Details
#accept ⇒ String
The accept header. This method is overriden by the classes that includes this module if they want a different accept header.
59 |
# File 'lib/resto/format.rb', line 59 def accept; '*/*'; end |
#content_type ⇒ nil
The content-type header. This method is overriden by the classes that includes this module if they want a different content-type header.
65 |
# File 'lib/resto/format.rb', line 65 def content_type; end |
#decode(*args) ⇒ Array<Object>
Returns the arguments as an Array. This method is overriden by classes that includes this module if they want a different behavior.
71 |
# File 'lib/resto/format.rb', line 71 def decode(*args); args end |
#encode(*args) ⇒ Object
Returns the first argument. This method is overriden by classes that includes this module if they want a different behavior.
77 |
# File 'lib/resto/format.rb', line 77 def encode(*args); args.first end |
#extension ⇒ nil
The extension. This method is overriden by the classes that includes this module if they want to have an extension.
83 |
# File 'lib/resto/format.rb', line 83 def extension; end |