module Subjoin::Inheritable
Mixin providing methods necessary for using custom classes derived from {Resource}.
Using this approach you create your own classes to represent JSON-API resource types of a specific JSON-API server implementation. These classes must be sub-classes of {Resource} and must include {Inheritable}. Next you must override a class variable, `ROOT_URI`, which should be the root of all URIs of the API.
By default, Subjoin
will use the lower-cased name of the class as the type in URIs. If the class name does not match the type, you can further override `TYPE_PATH` to indicate the name (or longer URI fragment) that should be used in URIs to request the resource type. Your custom classes must also be part of the Subjoin
module. You should probably create one sub-class of Subjoin::Resource
that overrides `ROOT_URI`, and then create other classes as sub-classes of this:
module Subjoin # Use this class as the parent of further subclasses. # They will inherit the ROOT_URI defined here class ExampleResource < Subjoin::Resource include Inheritable ROOT_URI="http://example.com" end # Subjoin will make requests to http://example.com/articles class Articles < ExampleResource end # Use TYPE_PATH if you don't want to name the class the same thing as # the type class ArticleComments < ExampleResource TYPE_PATH="comments" end end
Constants
- ROOT_URI
Root URI for all API requests
- TYPE_PATH
JSON-API type corresponding to this class, and presumably string to be used in requests for resources of this type. If not provided, the lower-cased name of the class will be used
Public Class Methods
Callback invoked whenever module is included in another module or class.
# File lib/subjoin/inheritable.rb, line 51 def self.included(base) base.extend(ClassMethods) end