Class: Shrine::Plugins::Rom::RomWrapper
- Inherits:
-
Object
- Object
- Shrine::Plugins::Rom::RomWrapper
- Defined in:
- lib/shrine/plugins/rom.rb
Instance Attribute Summary collapse
-
#record_pk ⇒ Object
readonly
Returns the value of attribute record_pk.
-
#repository ⇒ Object
readonly
Returns the value of attribute repository.
Instance Method Summary collapse
- #column_type(attribute) ⇒ Object
-
#initialize(repository:, record: nil) ⇒ RomWrapper
constructor
A new instance of RomWrapper.
- #retrieve_record ⇒ Object
- #update_record(attributes) ⇒ Object
Constructor Details
#initialize(repository:, record: nil) ⇒ RomWrapper
Returns a new instance of RomWrapper.
75 76 77 78 |
# File 'lib/shrine/plugins/rom.rb', line 75 def initialize(repository:, record: nil) @repository = repository @record_pk = record.send(relation.primary_key) end |
Instance Attribute Details
#record_pk ⇒ Object (readonly)
Returns the value of attribute record_pk.
73 74 75 |
# File 'lib/shrine/plugins/rom.rb', line 73 def record_pk @record_pk end |
#repository ⇒ Object (readonly)
Returns the value of attribute repository.
73 74 75 |
# File 'lib/shrine/plugins/rom.rb', line 73 def repository @repository end |
Instance Method Details
#column_type(attribute) ⇒ Object
95 96 97 98 99 |
# File 'lib/shrine/plugins/rom.rb', line 95 def column_type(attribute) # sends "json" or "jsonb" string for JSON or JSONB column. # returns nil for String column relation.schema[attribute].type.[:db_type] end |
#retrieve_record ⇒ Object
84 85 86 87 88 89 90 91 92 93 |
# File 'lib/shrine/plugins/rom.rb', line 84 def retrieve_record case adapter when :sql repository.transaction do yield record_relation.lock.one! end else yield record_relation.one! end end |
#update_record(attributes) ⇒ Object
80 81 82 |
# File 'lib/shrine/plugins/rom.rb', line 80 def update_record(attributes) repository.update(record_pk, attributes) end |