Class: Associationist::Associations::SingularAssociation
- Inherits:
-
ActiveRecord::Associations::SingularAssociation
- Object
- ActiveRecord::Associations::SingularAssociation
- Associationist::Associations::SingularAssociation
- Defined in:
- lib/associationist/associations/singular_association.rb
Instance Method Summary collapse
- #association_scope ⇒ Object
- #find_target ⇒ Object
- #find_target? ⇒ Boolean
- #force_reload_reader ⇒ Object
- #klass ⇒ Object
Instance Method Details
#association_scope ⇒ Object
4 5 6 7 8 9 10 |
# File 'lib/associationist/associations/singular_association.rb', line 4 def association_scope @_association_scope ||= if reflection.config.scope_proc reflection.config.scope_proc.call(owner) else raise NotImplementedError end end |
#find_target ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/associationist/associations/singular_association.rb', line 13 def find_target(async: false) if reflection.config.scope_proc super else reflection.config.loader_proc.call(owner) # TODO: use async load end end |
#find_target? ⇒ Boolean
30 31 32 |
# File 'lib/associationist/associations/singular_association.rb', line 30 def find_target? !loaded? end |
#force_reload_reader ⇒ Object
46 47 48 49 |
# File 'lib/associationist/associations/singular_association.rb', line 46 def force_reload_reader reload target end |
#klass ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/associationist/associations/singular_association.rb', line 34 def klass if reflection.config.scope_proc association_scope.klass else if reflection.config.class_name reflection.config.class_name.constantize else Object end end end |