Module: LinkedRails::Model::IRI::ClassMethods

Defined in:
lib/linked_rails/model/iri.rb

Instance Method Summary collapse

Instance Method Details

#ids_for_iris(scope) ⇒ Object



117
118
119
# File 'lib/linked_rails/model/iri.rb', line 117

def ids_for_iris(scope)
  scope.pluck(:id)
end

#iriObject



93
94
95
# File 'lib/linked_rails/model/iri.rb', line 93

def iri
  @iri ||= iri_namespace[iri_value] if iri_namespace
end

#iri_namespaceObject



97
98
99
100
101
102
# File 'lib/linked_rails/model/iri.rb', line 97

def iri_namespace
  return if self == ApplicationRecord

  superclass.try(:iri_namespace) ||
    (linked_rails_module? ? Vocab.ontola : Vocab.app)
end

#iri_templateObject



108
109
110
# File 'lib/linked_rails/model/iri.rb', line 108

def iri_template
  @iri_template ||= LinkedRails::URITemplate.new("/#{route_key}{/id}{#fragment}")
end

#iri_valueObject



104
105
106
# File 'lib/linked_rails/model/iri.rb', line 104

def iri_value
  linked_rails_module? ? name.demodulize : name
end

#iris_from_scope(scope) ⇒ Object



112
113
114
115
# File 'lib/linked_rails/model/iri.rb', line 112

def iris_from_scope(scope)
  ids = ids_for_iris(scope).uniq
  ids.map { |id| LinkedRails.iri(path: iri_template.expand(id: id)) }
end

#linked_rails_module?Boolean

Returns:

  • (Boolean)


121
122
123
# File 'lib/linked_rails/model/iri.rb', line 121

def linked_rails_module?
  (Rails.version < '6' ? parents : module_parents).include?(LinkedRails)
end

#route_keyObject



125
126
127
# File 'lib/linked_rails/model/iri.rb', line 125

def route_key
  try(:model_name)&.route_key || to_s.tableize
end