Class: Valkyrie::Persistence::Postgres::ResourceFactory

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

Overview

Provides access to generic methods for converting to/from Resource and ORM::Resource.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(adapter:) ⇒ ResourceFactory

Returns a new instance of ResourceFactory.

Parameters:



12
13
14
# File 'lib/valkyrie/persistence/postgres/resource_factory.rb', line 12

def initialize(adapter:)
  @adapter = adapter
end

Instance Attribute Details

#adapterObject (readonly)

Returns the value of attribute adapter.



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

def adapter
  @adapter
end

Instance Method Details

#from_resource(resource:) ⇒ Valkyrie::Persistence::Postgres::ORM::Resource

Returns ActiveRecord resource for the Valkyrie resource.

Parameters:

Returns:



26
27
28
# File 'lib/valkyrie/persistence/postgres/resource_factory.rb', line 26

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

#orm_classClass

Accessor for the ActiveRecord class which all Postgres resources are an instance of.

Returns:

  • (Class)


33
34
35
# File 'lib/valkyrie/persistence/postgres/resource_factory.rb', line 33

def orm_class
  ::Valkyrie::Persistence::Postgres::ORM::Resource
end

#to_resource(object:) ⇒ Valkyrie::Resource

Returns Model representation of the AR record.

Parameters:

Returns:



19
20
21
# File 'lib/valkyrie/persistence/postgres/resource_factory.rb', line 19

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