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


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


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

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

#query(args = {}) ⇒ Object


80
81
82
83
84
# File 'lib/active_fedora/loadable_from_json.rb', line 80

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

#rdf_subjectObject


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

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

#reflection(predicate) ⇒ Object


95
96
97
# File 'lib/active_fedora/loadable_from_json.rb', line 95

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