Module: ScopedAssociations::ActiveRecord5::HasOne::ReflectionExtension
- Defined in:
- lib/scoped_associations/activerecord5/has_one.rb
Instance Method Summary collapse
Instance Method Details
#association_class ⇒ Object
49 50 51 |
# File 'lib/scoped_associations/activerecord5/has_one.rb', line 49 def association_class ScopedHasOneAssociation end |
#foreign_scope ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/scoped_associations/activerecord5/has_one.rb', line 29 def foreign_scope if [:as] "#{[:as]}_scope" else name = active_record.name name.demodulize.underscore + "_scope" end end |
#scope ⇒ Object
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/scoped_associations/activerecord5/has_one.rb', line 38 def scope old_scope = super scope_conditions = { foreign_scope => name } proc_scope = proc { where(scope_conditions) } if old_scope.nil? proc { instance_eval(&proc_scope) } else proc { instance_eval(&proc_scope).instance_eval(&old_scope) } end end |