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

.urlObject



29
30
31
# File 'app/models/jsonapi/home/v1/resource.rb', line 29

def self.url
  @url
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

.with(url) ⇒ Object



25
26
27
# File 'app/models/jsonapi/home/v1/resource.rb', line 25

def self.with(url)
  tap { @url = url }
end

Instance Method Details

#created_atObject



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

def created_at
  CREATED_AT
end

#deprecatedObject



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

def deprecated
  if configuration.fetch(:deprecated).respond_to?(:fetch)
    configuration.fetch(:deprecated).fetch(action, nil)
  else
    configuration.fetch(:deprecated)
  end
end

#descriptionObject



56
57
58
# File 'app/models/jsonapi/home/v1/resource.rb', line 56

def description
  configuration.fetch(:description)
end

#documentationObject



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

def documentation
  configuration.fetch(:documentation)
end

#hrefObject



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

def href
  File.join(location, path)
end

#idObject



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

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

#intentObject



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

def intent
  defaults.fetch(:action)
end

#jsonapi_versionObject



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

def jsonapi_version
  configuration.fetch(:version)
end

#mediatypeObject



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

def mediatype
  JSONAPI::MEDIA_TYPE
end

#namespaceObject



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

def namespace
  configuration.fetch(:namespace)
end

#updated_atObject



92
93
94
# File 'app/models/jsonapi/home/v1/resource.rb', line 92

def updated_at
  Time.now
end

#valid?Boolean

Returns:

  • (Boolean)


96
97
98
# File 'app/models/jsonapi/home/v1/resource.rb', line 96

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

#verbObject



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

def verb
  route.verb
end

#versionObject



52
53
54
# File 'app/models/jsonapi/home/v1/resource.rb', line 52

def version
  configuration.fetch(:version)
end