Class: Spotlight::Resource
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Spotlight::Resource
show all
- Extended by:
- ActiveModel::Callbacks
- Includes:
- SolrDocument::AtomicUpdates
- Defined in:
- app/models/spotlight/resource.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.class_for_resource(r) ⇒ Object
23
24
25
26
27
28
29
|
# File 'app/models/spotlight/resource.rb', line 23
def self.class_for_resource r
p = providers.select do |p|
p.can_provide? r
end
p.sort_by(&:weight).first
end
|
.providers ⇒ Object
19
20
21
|
# File 'app/models/spotlight/resource.rb', line 19
def self.providers
Spotlight::Engine.config.resource_providers
end
|
.resource_global_id_field ⇒ Object
38
39
40
|
# File 'app/models/spotlight/resource.rb', line 38
def self.resource_global_id_field
:"#{Spotlight::Engine.config.solr_fields.prefix}spotlight_resource_id#{Spotlight::Engine.config.solr_fields.string_suffix}"
end
|
Instance Method Details
#becomes_provider ⇒ Object
60
61
62
63
64
65
66
67
68
69
70
|
# File 'app/models/spotlight/resource.rb', line 60
def becomes_provider
klass = Spotlight::Resource.class_for_resource(self)
if klass
z = self.becomes klass
z.type = z.class.to_s
z
else
self
end
end
|
#needs_provider? ⇒ Boolean
72
73
74
|
# File 'app/models/spotlight/resource.rb', line 72
def needs_provider?
type.blank?
end
|
#reindex ⇒ Object
48
49
50
51
52
53
54
|
# File 'app/models/spotlight/resource.rb', line 48
def reindex
run_callbacks :index do
data = to_solr
data = [data] unless data.is_a? Array
blacklight_solr.update params: { commitWithin: 500 }, data: data.to_json, headers: { 'Content-Type' => 'application/json'} unless data.empty?
end
end
|
#reindex_with_lock ⇒ Object
42
43
44
45
46
|
# File 'app/models/spotlight/resource.rb', line 42
def reindex_with_lock
with_lock do
yield
end
end
|
#save_and_commit ⇒ Object
76
77
78
|
# File 'app/models/spotlight/resource.rb', line 76
def save_and_commit
save.tap { blacklight_solr.commit rescue nil }
end
|
#update_index_time! ⇒ Object
56
57
58
|
# File 'app/models/spotlight/resource.rb', line 56
def update_index_time!
self.update_columns indexed_at: Time.current
end
|