Class: ActiveFedora::LoadableFromJson::SolrBackedResource

Inherits:
Object
  • Object
show all
Defined in:
lib/active_fedora/loadable_from_json.rb

Defined Under Namespace

Classes: FakeQuery

Instance Method Summary collapse

Constructor Details

#initialize(model) ⇒ SolrBackedResource

Returns a new instance of SolrBackedResource.



36
37
38
39
# File 'lib/active_fedora/loadable_from_json.rb', line 36

def initialize(model)
  @model = model
  @hash = {}
end

Instance Method Details

#freezeObject



32
33
34
# File 'lib/active_fedora/loadable_from_json.rb', line 32

def freeze
  @hash.freeze
end

#get_values(k) ⇒ Object



51
52
53
# File 'lib/active_fedora/loadable_from_json.rb', line 51

def get_values(k)
  @hash[k]
end

#insert(vals) ⇒ Object

Called by Associations::RDF#replace to add data to this resource represenation

Parameters:

  • vals (Array)

    an array of 3 elements (subject, predicate, object) to insert



98
99
100
101
# File 'lib/active_fedora/loadable_from_json.rb', line 98

def insert(vals)
  _, pred, val = vals
  set_value(reflection(pred), [val])
end

#query(args = {}) ⇒ Object



86
87
88
89
90
# File 'lib/active_fedora/loadable_from_json.rb', line 86

def query(args={})
  predicate = args[:predicate]
  reflection = reflection(predicate)
  FakeQuery.new(get_values(reflection))
end

#rdf_subjectObject



92
93
94
# File 'lib/active_fedora/loadable_from_json.rb', line 92

def rdf_subject
  ::RDF::URI.new(nil)
end

#reflection(predicate) ⇒ Object



103
104
105
# File 'lib/active_fedora/loadable_from_json.rb', line 103

def reflection(predicate)
  Array(@model.outgoing_reflections.find { |key, reflection| reflection.predicate == predicate }).first
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.



47
48
49
# File 'lib/active_fedora/loadable_from_json.rb', line 47

def set_value(k, v)
  @hash[k] = Array(v)
end

#to_sObject



41
42
43
# File 'lib/active_fedora/loadable_from_json.rb', line 41

def to_s
  @hash.to_s
end