Class: ActiveFedora::LoadableFromJson::SolrBackedResource
- Inherits:
-
Object
- Object
- ActiveFedora::LoadableFromJson::SolrBackedResource
- Defined in:
- lib/active_fedora/loadable_from_json.rb
Defined Under Namespace
Classes: FakeQuery
Instance Method Summary collapse
- #freeze ⇒ Object
- #get_values(k) ⇒ Object
-
#initialize(model) ⇒ SolrBackedResource
constructor
A new instance of SolrBackedResource.
-
#insert(vals) ⇒ Object
Called by Associations::RDF#replace to add data to this resource represenation.
- #persist! ⇒ Object
- #query(args = {}) ⇒ Object
- #rdf_subject ⇒ Object
-
#reflection(predicate) ⇒ Object
Find the reflection on the model that uses the given predicate.
-
#set_value(k, v) ⇒ Object
It is expected that the singular filter gets applied after fetching the value from this resource, so cast everything back to an array.
- #to_s ⇒ Object
Constructor Details
#initialize(model) ⇒ SolrBackedResource
Returns a new instance of SolrBackedResource.
34 35 36 37 |
# File 'lib/active_fedora/loadable_from_json.rb', line 34 def initialize(model) @model = model @hash = {} end |
Instance Method Details
#freeze ⇒ Object
30 31 32 |
# File 'lib/active_fedora/loadable_from_json.rb', line 30 def freeze @hash.freeze end |
#get_values(k) ⇒ Object
49 50 51 |
# File 'lib/active_fedora/loadable_from_json.rb', line 49 def get_values(k) @hash[k] end |
#insert(vals) ⇒ Object
Called by Associations::RDF#replace to add data to this resource represenation
100 101 102 103 104 105 106 107 108 |
# File 'lib/active_fedora/loadable_from_json.rb', line 100 def insert(vals) _, pred, val = vals k = reflection(pred) if @hash[k].is_a?(Array) set_value(k, @hash[k] << val) else set_value(k, [val]) end end |
#persist! ⇒ Object
53 54 55 |
# File 'lib/active_fedora/loadable_from_json.rb', line 53 def persist!(*) true end |
#query(args = {}) ⇒ Object
88 89 90 91 92 |
# File 'lib/active_fedora/loadable_from_json.rb', line 88 def query(args = {}) predicate = args[:predicate] reflection = reflection(predicate) FakeQuery.new(get_values(reflection)) end |
#rdf_subject ⇒ Object
94 95 96 |
# File 'lib/active_fedora/loadable_from_json.rb', line 94 def rdf_subject ::RDF::URI.new(nil) end |
#reflection(predicate) ⇒ Object
Find the reflection on the model that uses the given predicate
111 112 113 114 115 |
# File 'lib/active_fedora/loadable_from_json.rb', line 111 def reflection(predicate) result = Array(@model.outgoing_reflections.find { |_key, reflection| reflection.predicate == predicate }).first return result if result fail "Unable to find reflection for #{predicate} in #{@model}" end |
#set_value(k, v) ⇒ Object
It is expected that the singular filter gets applied after fetching the value from this resource, so cast everything back to an array.
45 46 47 |
# File 'lib/active_fedora/loadable_from_json.rb', line 45 def set_value(k, v) @hash[k] = Array(v) end |
#to_s ⇒ Object
39 40 41 |
# File 'lib/active_fedora/loadable_from_json.rb', line 39 def to_s @hash.to_s end |