Module: Munson
- Defined in:
- lib/munson.rb,
lib/munson/agent.rb,
lib/munson/query.rb,
lib/munson/client.rb,
lib/munson/version.rb,
lib/munson/document.rb,
lib/munson/attribute.rb,
lib/munson/collection.rb,
lib/munson/connection.rb,
lib/munson/response_mapper.rb,
lib/munson/middleware/json_parser.rb,
lib/munson/middleware/encode_json_api.rb
Defined Under Namespace
Modules: Middleware Classes: Agent, Attribute, Client, ClientNotSet, Collection, Connection, Document, Error, KeyFormatter, Query, RelationshipNotFound, RelationshipNotIncludedError, Resource, ResponseMapper, UnrecognizedKeyFormatter, UnsupportedSortDirectionError
Constant Summary collapse
- VERSION =
"0.3.0"
Class Method Summary collapse
- .configure(opts = {}, &block) ⇒ Object
-
.default_connection ⇒ Munson::Connection?
The default connection.
-
.factory(document) ⇒ Munson::Document, ~Munson::Resource
Transforms a JSONAPI hash into a Munson::Document, Munson::Resource, or arbitrary class.
-
.lookup_type(type) ⇒ Class
Lookup a class by JSON Spec type name.
-
.register_type(type, klass) ⇒ Object
Register a JSON Spec resource type to a class This is used in Faraday response middleware to package the JSON into a domain model.
Class Method Details
.configure(opts = {}, &block) ⇒ Object
53 54 55 |
# File 'lib/munson.rb', line 53 def configure(opts={}, &block) @default_connection = Munson::Connection.new(opts, &block) end |
.default_connection ⇒ Munson::Connection?
The default connection
60 61 62 |
# File 'lib/munson.rb', line 60 def default_connection defined?(@default_connection) ? @default_connection : nil end |
.factory(document) ⇒ Munson::Document, ~Munson::Resource
Transforms a JSONAPI hash into a Munson::Document, Munson::Resource, or arbitrary class
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/munson.rb', line 34 def factory(document) document = Munson::Document.new(document) if document.is_a?(Hash) klass = Munson.lookup_type(document.type) if klass && klass.respond_to?(:munson_initializer) klass.munson_initializer(document) else document end end |
.lookup_type(type) ⇒ Class
Lookup a class by JSON Spec type name
80 81 82 |
# File 'lib/munson.rb', line 80 def lookup_type(type) @registered_types[type.to_sym] end |
.register_type(type, klass) ⇒ Object
Register a JSON Spec resource type to a class This is used in Faraday response middleware to package the JSON into a domain model
72 73 74 |
# File 'lib/munson.rb', line 72 def register_type(type, klass) @registered_types[type.to_sym] = klass end |