Class: Valkyrie::Persistence::Postgres::ResourceConverter
- Inherits:
-
Object
- Object
- Valkyrie::Persistence::Postgres::ResourceConverter
- Defined in:
- lib/valkyrie/persistence/postgres/resource_converter.rb
Overview
Responsible for converting a Resource into a ORM::Resource
Instance Attribute Summary collapse
-
#resource ⇒ Object
readonly
Returns the value of attribute resource.
-
#resource_factory ⇒ Object
readonly
Returns the value of attribute resource_factory.
Instance Method Summary collapse
- #convert! ⇒ Object
-
#initialize(resource, resource_factory:) ⇒ ResourceConverter
constructor
A new instance of ResourceConverter.
Constructor Details
#initialize(resource, resource_factory:) ⇒ ResourceConverter
Returns a new instance of ResourceConverter.
8 9 10 11 |
# File 'lib/valkyrie/persistence/postgres/resource_converter.rb', line 8 def initialize(resource, resource_factory:) @resource = resource @resource_factory = resource_factory end |
Instance Attribute Details
#resource ⇒ Object (readonly)
Returns the value of attribute resource.
7 8 9 |
# File 'lib/valkyrie/persistence/postgres/resource_converter.rb', line 7 def resource @resource end |
#resource_factory ⇒ Object (readonly)
Returns the value of attribute resource_factory.
7 8 9 |
# File 'lib/valkyrie/persistence/postgres/resource_converter.rb', line 7 def resource_factory @resource_factory end |
Instance Method Details
#convert! ⇒ Object
13 14 15 16 17 18 |
# File 'lib/valkyrie/persistence/postgres/resource_converter.rb', line 13 def convert! orm_class.find_or_initialize_by(id: resource.id && resource.id.to_s).tap do |orm_object| orm_object.internal_resource = resource.internal_resource orm_object..merge!(resource.attributes.except(:id, :internal_resource, :created_at, :updated_at)) end end |