class ActiveFedora::LoadableFromJson::SolrBackedResource

Public Class Methods

new(model) click to toggle source
# File lib/active_fedora/loadable_from_json.rb, line 34
def initialize(model)
  @model = model
  @hash = {}
end

Public Instance Methods

freeze() click to toggle source
# File lib/active_fedora/loadable_from_json.rb, line 30
def freeze
  @hash.freeze
end
get_values(k) click to toggle source
# File lib/active_fedora/loadable_from_json.rb, line 49
def get_values(k)
  @hash[k]
end
insert(vals) click to toggle source

Called by Associations::RDF#replace to add data to this resource represenation @param [Array] vals an array of 3 elements (subject, predicate, object) to insert

# 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!(*) click to toggle source
# File lib/active_fedora/loadable_from_json.rb, line 53
def persist!(*)
  true
end
query(args = {}) click to toggle source
# 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() click to toggle source
# File lib/active_fedora/loadable_from_json.rb, line 94
def rdf_subject
  ::RDF::URI.new(nil)
end
reflection(predicate) click to toggle source

Find the reflection on the model that uses the given predicate

# 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) click to toggle source

It is expected that the singular filter gets applied after fetching the value from this resource, so cast everything back to an array.

# File lib/active_fedora/loadable_from_json.rb, line 45
def set_value(k, v)
  @hash[k] = Array(v)
end
to_s() click to toggle source
# File lib/active_fedora/loadable_from_json.rb, line 39
def to_s
  @hash.to_s
end