Class: Valkyrie::Persistence::Solr::ResourceFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/valkyrie/persistence/solr/resource_factory.rb

Overview

Provides access to generic methods for converting to/from Resource and hashes for persistence into Solr.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource_indexer:, adapter:) ⇒ ResourceFactory

Returns a new instance of ResourceFactory.



13
14
15
16
# File 'lib/valkyrie/persistence/solr/resource_factory.rb', line 13

def initialize(resource_indexer:, adapter:)
  @resource_indexer = resource_indexer
  @adapter = adapter
end

Instance Attribute Details

#adapterObject (readonly)

Returns the value of attribute adapter.



8
9
10
# File 'lib/valkyrie/persistence/solr/resource_factory.rb', line 8

def adapter
  @adapter
end

#resource_indexerObject (readonly)

Returns the value of attribute resource_indexer.



8
9
10
# File 'lib/valkyrie/persistence/solr/resource_factory.rb', line 8

def resource_indexer
  @resource_indexer
end

Instance Method Details

#from_resource(resource:) ⇒ Hash

Returns The solr document represented as a hash.

Parameters:

Returns:

  • (Hash)

    The solr document represented as a hash.



27
28
29
# File 'lib/valkyrie/persistence/solr/resource_factory.rb', line 27

def from_resource(resource:)
  Valkyrie::Persistence::Solr::ModelConverter.new(resource, resource_factory: self).convert!
end

#to_resource(object:) ⇒ Valkyrie::Resource

Parameters:

  • object (Hash)

    The solr document in a hash to convert to a resource.

Returns:



21
22
23
# File 'lib/valkyrie/persistence/solr/resource_factory.rb', line 21

def to_resource(object:)
  ORMConverter.new(object, resource_factory: self).convert!
end