Class: Clowne::Adapters::Base
- Inherits:
-
Object
- Object
- Clowne::Adapters::Base
- Includes:
- Registry::Container
- Defined in:
- lib/clowne/adapters/base.rb,
lib/clowne/adapters/base/association.rb
Overview
ORM-independant adapter (just calls #dup). Works with nullify/finalize.
Direct Known Subclasses
Defined Under Namespace
Classes: Association
Class Method Summary collapse
-
.dup_record(record) ⇒ Object
- Duplicate record and remember record <-> clone relationship in operation Cab be overrided in special adapter
record
-
Instance of record (ActiveRecord or Sequel).
- Duplicate record and remember record <-> clone relationship in operation Cab be overrided in special adapter
-
.operation_class ⇒ Object
Operation class which using for cloning Cab be overrided in special adapter.
Instance Method Summary collapse
-
#clone(source, plan, params: {}) ⇒ Object
- Using a plan make full duplicate of record
source
- Instance of cloned object (ex: User.new(posts: posts))
plan
- Array of Declarations
params
-
Custom params hash.
- Array of Declarations
- Instance of cloned object (ex: User.new(posts: posts))
- Using a plan make full duplicate of record
- #init_record(record) ⇒ Object
Methods included from Registry::Container
Class Method Details
.dup_record(record) ⇒ Object
Duplicate record and remember record <-> clone relationship in operation Cab be overrided in special adapter
record
-
Instance of record (ActiveRecord or Sequel)
21 22 23 24 25 26 |
# File 'lib/clowne/adapters/base.rb', line 21 def dup_record(record) record.dup.tap do |clone| operation = operation_class.current operation.add_mapping(record, clone) end end |
Instance Method Details
#clone(source, plan, params: {}) ⇒ Object
Using a plan make full duplicate of record
source
-
Instance of cloned object (ex: User.new(posts: posts))
plan
-
Array of Declarations
params
-
Custom params hash
39 40 41 42 43 44 45 46 |
# File 'lib/clowne/adapters/base.rb', line 39 def clone(source, plan, params: {}) declarations = plan.declarations init_record = init_record(self.class.dup_record(source)) declarations.inject(init_record) do |record, (type, declaration)| resolver_for(type).call(source, record, declaration, params: params, adapter: self) end end |
#init_record(record) ⇒ Object
48 49 50 51 |
# File 'lib/clowne/adapters/base.rb', line 48 def init_record(record) # Override in custom adapters record end |