Class: Clowne::Adapters::Base::Association
- Inherits:
-
Object
- Object
- Clowne::Adapters::Base::Association
- Defined in:
- lib/clowne/adapters/base/association.rb
Instance Method Summary collapse
- #association ⇒ Object
- #call(_record) ⇒ Object
- #clone_one(child) ⇒ Object
-
#initialize(reflection, source, declaration, adapter, params) ⇒ Association
constructor
- Params:
reflection
- Association eflection object
source
- Instance of cloned object (ex: User.new(posts: posts))
declaration
-
Relation description (ex: Clowne::Declarations::IncludeAssociation.new(:posts))
adapter
:: Clowne adapterparams
:: = Instance of Hash.
- Instance of cloned object (ex: User.new(posts: posts))
- Association eflection object
- Params:
- #with_scope ⇒ Object
Constructor Details
#initialize(reflection, source, declaration, adapter, params) ⇒ Association
Params:
reflection
-
Association eflection object
source
-
Instance of cloned object (ex: User.new(posts: posts))
declaration
-
Relation description
(ex: Clowne::Declarations::IncludeAssociation.new(:posts))
adapter
-
Clowne adapter
params
-
Instance of Hash
14 15 16 17 18 19 20 21 |
# File 'lib/clowne/adapters/base/association.rb', line 14 def initialize(reflection, source, declaration, adapter, params) @source = source @declaration = declaration @adapter = adapter @params = params @association_name = declaration.name.to_s @reflection = reflection end |
Instance Method Details
#association ⇒ Object
27 28 29 |
# File 'lib/clowne/adapters/base/association.rb', line 27 def association @_association ||= source.__send__(association_name) end |
#call(_record) ⇒ Object
23 24 25 |
# File 'lib/clowne/adapters/base/association.rb', line 23 def call(_record) raise NotImplementedError end |
#clone_one(child) ⇒ Object
31 32 33 34 |
# File 'lib/clowne/adapters/base/association.rb', line 31 def clone_one(child) cloner = cloner_for(child) cloner ? cloner.call(child, ) : dup_record(child) end |
#with_scope ⇒ Object
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/clowne/adapters/base/association.rb', line 36 def with_scope scope = declaration.scope if scope.is_a?(Symbol) init_scope.__send__(scope) elsif scope.is_a?(Proc) init_scope.instance_exec(params, &scope) || init_scope else init_scope end.to_a end |