Class: JSONAPI::Home::V1::Resource
- Inherits:
-
Object
- Object
- JSONAPI::Home::V1::Resource
- Includes:
- ActiveModel::Model
- Defined in:
- app/models/jsonapi/home/v1/resource.rb
Instance Attribute Summary collapse
-
#route ⇒ Object
writeonly
Sets the attribute route.
Class Method Summary collapse
Instance Method Summary collapse
- #created_at ⇒ Object
- #deprecated ⇒ Object
- #description ⇒ Object
- #documentation ⇒ Object
- #href ⇒ Object
- #id ⇒ Object
- #intent ⇒ Object
- #jsonapi_version ⇒ Object
- #mediatype ⇒ Object
- #namespace ⇒ Object
- #updated_at ⇒ Object
- #valid? ⇒ Boolean
- #verb ⇒ Object
- #version ⇒ Object
Instance Attribute Details
#route=(value) ⇒ Object
Sets the attribute route
10 11 12 |
# File 'app/models/jsonapi/home/v1/resource.rb', line 10 def route=(value) @route = value end |
Class Method Details
.all ⇒ Object
13 14 15 |
# File 'app/models/jsonapi/home/v1/resource.rb', line 13 def self.all routes.map {|route| new(route: route)}.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
80 81 82 |
# File 'app/models/jsonapi/home/v1/resource.rb', line 80 def created_at CREATED_AT end |
#deprecated ⇒ Object
52 53 54 55 56 57 58 |
# File 'app/models/jsonapi/home/v1/resource.rb', line 52 def deprecated if configuration.fetch(:deprecated).respond_to?(:fetch) configuration.fetch(:deprecated).fetch(action, nil) else configuration.fetch(:deprecated) end end |
#description ⇒ Object
48 49 50 |
# File 'app/models/jsonapi/home/v1/resource.rb', line 48 def description configuration.fetch(:description) end |
#documentation ⇒ Object
60 61 62 |
# File 'app/models/jsonapi/home/v1/resource.rb', line 60 def documentation configuration.fetch(:documentation) end |
#href ⇒ Object
72 73 74 |
# File 'app/models/jsonapi/home/v1/resource.rb', line 72 def href File.join(location, path) end |
#id ⇒ Object
32 33 34 |
# File 'app/models/jsonapi/home/v1/resource.rb', line 32 def id "#{namespace}-#{version}-#{intent}" end |
#intent ⇒ Object
36 37 38 |
# File 'app/models/jsonapi/home/v1/resource.rb', line 36 def intent defaults.fetch(:action) end |
#jsonapi_version ⇒ Object
64 65 66 |
# File 'app/models/jsonapi/home/v1/resource.rb', line 64 def jsonapi_version configuration.fetch(:version) end |
#mediatype ⇒ Object
76 77 78 |
# File 'app/models/jsonapi/home/v1/resource.rb', line 76 def mediatype JSONAPI::MEDIA_TYPE end |
#namespace ⇒ Object
40 41 42 |
# File 'app/models/jsonapi/home/v1/resource.rb', line 40 def namespace configuration.fetch(:namespace) end |
#updated_at ⇒ Object
84 85 86 |
# File 'app/models/jsonapi/home/v1/resource.rb', line 84 def updated_at Time.now end |
#valid? ⇒ Boolean
88 89 90 |
# File 'app/models/jsonapi/home/v1/resource.rb', line 88 def valid? !route.internal && defaults.any? && controller.present? && configuration end |
#verb ⇒ Object
68 69 70 |
# File 'app/models/jsonapi/home/v1/resource.rb', line 68 def verb route.verb end |
#version ⇒ Object
44 45 46 |
# File 'app/models/jsonapi/home/v1/resource.rb', line 44 def version configuration.fetch(:version) end |