Module: McCracken
- Defined in:
- lib/mccracken.rb,
lib/mccracken/agent.rb,
lib/mccracken/query.rb,
lib/mccracken/client.rb,
lib/mccracken/version.rb,
lib/mccracken/document.rb,
lib/mccracken/attribute.rb,
lib/mccracken/collection.rb,
lib/mccracken/connection.rb,
lib/mccracken/response_mapper.rb,
lib/mccracken/middleware/json_parser.rb,
lib/mccracken/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.1"
Class Method Summary collapse
- .configure(opts = {}, &block) ⇒ Object
-
.default_connection ⇒ McCracken::Connection?
The default connection.
-
.factory(document) ⇒ McCracken::Document, ~McCracken::Resource
Transforms a JSONAPI hash into a McCracken::Document, McCracken::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/mccracken.rb', line 53 def configure(opts={}, &block) @default_connection = McCracken::Connection.new(opts, &block) end |
.default_connection ⇒ McCracken::Connection?
The default connection
60 61 62 |
# File 'lib/mccracken.rb', line 60 def default_connection defined?(@default_connection) ? @default_connection : nil end |
.factory(document) ⇒ McCracken::Document, ~McCracken::Resource
Transforms a JSONAPI hash into a McCracken::Document, McCracken::Resource, or arbitrary class
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/mccracken.rb', line 34 def factory(document) document = McCracken::Document.new(document) if document.is_a?(Hash) klass = McCracken.lookup_type(document.type) if klass && klass.respond_to?(:mccracken_initializer) klass.mccracken_initializer(document) else document end end |
.lookup_type(type) ⇒ Class
Lookup a class by JSON Spec type name
80 81 82 |
# File 'lib/mccracken.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/mccracken.rb', line 72 def register_type(type, klass) @registered_types[type.to_sym] = klass end |