Class: JSONAPI::Home::V1::Resource
- Inherits:
-
Object
- Object
- JSONAPI::Home::V1::Resource
- Includes:
- ActiveModel::Model
- Defined in:
- app/models/jsonapi/home/v1/resource.rb
Class Method Summary collapse
Instance Method Summary collapse
- #created_at ⇒ Object
- #deprecated ⇒ Object
- #description ⇒ Object
- #documentation ⇒ Object
- #href ⇒ Object
- #id ⇒ Object
-
#initialize(route) ⇒ Resource
constructor
A new instance of Resource.
- #intent ⇒ Object
- #jsonapi_version ⇒ Object
- #location ⇒ Object
- #mediatype ⇒ Object
- #namespace ⇒ Object
- #updated_at ⇒ Object
- #valid? ⇒ Boolean
- #verb ⇒ Object
- #version ⇒ Object
Constructor Details
#initialize(route) ⇒ Resource
Returns a new instance of Resource.
32 33 34 |
# File 'app/models/jsonapi/home/v1/resource.rb', line 32 def initialize(route) @route = route end |
Class Method Details
.all ⇒ Object
13 14 15 |
# File 'app/models/jsonapi/home/v1/resource.rb', line 13 def self.all routes.map(&method(:new)).select(&:valid?) end |
.fetch(id) ⇒ Object
21 22 23 |
# File 'app/models/jsonapi/home/v1/resource.rb', line 21 def self.fetch(id) all.index_by(&:id).fetch(id) end |
.where(attributes) ⇒ Object
17 18 19 |
# File 'app/models/jsonapi/home/v1/resource.rb', line 17 def self.where(attributes) all.where(attributes) end |
Instance Method Details
#created_at ⇒ Object
90 91 92 |
# File 'app/models/jsonapi/home/v1/resource.rb', line 90 def created_at CREATED_AT end |
#deprecated ⇒ Object
56 57 58 59 60 61 62 |
# File 'app/models/jsonapi/home/v1/resource.rb', line 56 def deprecated if configuration.fetch(:deprecated).respond_to?(:fetch) configuration.fetch(:deprecated).fetch(action, nil) else configuration.fetch(:deprecated) end end |
#description ⇒ Object
52 53 54 |
# File 'app/models/jsonapi/home/v1/resource.rb', line 52 def description configuration.fetch(:description) end |
#documentation ⇒ Object
64 65 66 |
# File 'app/models/jsonapi/home/v1/resource.rb', line 64 def documentation configuration.fetch(:documentation) end |
#href ⇒ Object
76 77 78 |
# File 'app/models/jsonapi/home/v1/resource.rb', line 76 def href File.join(location, path) end |
#id ⇒ Object
36 37 38 |
# File 'app/models/jsonapi/home/v1/resource.rb', line 36 def id "#{namespace}-#{version}-#{intent}" end |
#intent ⇒ Object
40 41 42 |
# File 'app/models/jsonapi/home/v1/resource.rb', line 40 def intent defaults.fetch(:action) end |
#jsonapi_version ⇒ Object
68 69 70 |
# File 'app/models/jsonapi/home/v1/resource.rb', line 68 def jsonapi_version configuration.fetch(:version) end |
#location ⇒ Object
80 81 82 83 84 |
# File 'app/models/jsonapi/home/v1/resource.rb', line 80 def location configuration.fetch(:location) || ENV.fetch("HOME_LOCATION", nil) || Rails.application.routes.url_helpers.root_path end |
#mediatype ⇒ Object
86 87 88 |
# File 'app/models/jsonapi/home/v1/resource.rb', line 86 def mediatype JSONAPI::MEDIA_TYPE end |
#namespace ⇒ Object
44 45 46 |
# File 'app/models/jsonapi/home/v1/resource.rb', line 44 def namespace configuration.fetch(:namespace) end |
#updated_at ⇒ Object
94 95 96 |
# File 'app/models/jsonapi/home/v1/resource.rb', line 94 def updated_at Time.now end |
#valid? ⇒ Boolean
98 99 100 |
# File 'app/models/jsonapi/home/v1/resource.rb', line 98 def valid? !route.internal && defaults.any? && controller.present? && configuration end |
#verb ⇒ Object
72 73 74 |
# File 'app/models/jsonapi/home/v1/resource.rb', line 72 def verb route.verb end |
#version ⇒ Object
48 49 50 |
# File 'app/models/jsonapi/home/v1/resource.rb', line 48 def version configuration.fetch(:version) end |