Class: JSONAPI::Home::V1::Resource

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Model
Defined in:
app/models/jsonapi/home/v1/resource.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#route=(value) ⇒ Object

Sets the attribute route

Parameters:

  • value

    the value to set the attribute route to.



10
11
12
# File 'app/models/jsonapi/home/v1/resource.rb', line 10

def route=(value)
  @route = value
end

Class Method Details

.allObject



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_atObject



80
81
82
# File 'app/models/jsonapi/home/v1/resource.rb', line 80

def created_at
  CREATED_AT
end

#deprecatedObject



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

#descriptionObject



48
49
50
# File 'app/models/jsonapi/home/v1/resource.rb', line 48

def description
  configuration.fetch(:description)
end

#documentationObject



60
61
62
# File 'app/models/jsonapi/home/v1/resource.rb', line 60

def documentation
  configuration.fetch(:documentation)
end

#hrefObject



72
73
74
# File 'app/models/jsonapi/home/v1/resource.rb', line 72

def href
  File.join(location, path)
end

#idObject



32
33
34
# File 'app/models/jsonapi/home/v1/resource.rb', line 32

def id
  "#{namespace}-#{version}-#{intent}"
end

#intentObject



36
37
38
# File 'app/models/jsonapi/home/v1/resource.rb', line 36

def intent
  defaults.fetch(:action)
end

#jsonapi_versionObject



64
65
66
# File 'app/models/jsonapi/home/v1/resource.rb', line 64

def jsonapi_version
  configuration.fetch(:version)
end

#mediatypeObject



76
77
78
# File 'app/models/jsonapi/home/v1/resource.rb', line 76

def mediatype
  JSONAPI::MEDIA_TYPE
end

#namespaceObject



40
41
42
# File 'app/models/jsonapi/home/v1/resource.rb', line 40

def namespace
  configuration.fetch(:namespace)
end

#updated_atObject



84
85
86
# File 'app/models/jsonapi/home/v1/resource.rb', line 84

def updated_at
  Time.now
end

#valid?Boolean

Returns:

  • (Boolean)


88
89
90
# File 'app/models/jsonapi/home/v1/resource.rb', line 88

def valid?
  !route.internal && defaults.any? && controller.present? && configuration
end

#verbObject



68
69
70
# File 'app/models/jsonapi/home/v1/resource.rb', line 68

def verb
  route.verb
end

#versionObject



44
45
46
# File 'app/models/jsonapi/home/v1/resource.rb', line 44

def version
  configuration.fetch(:version)
end