Class: ActiveRecord::Associations::Association
- Inherits:
-
Object
- Object
- ActiveRecord::Associations::Association
- Defined in:
- lib/hobo/extensions/active_record/associations/association.rb
Overview
:nodoc:
Instance Method Summary collapse
Instance Method Details
#scoped ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/hobo/extensions/active_record/associations/association.rb', line 4 def scoped # Rails implementation just returns target_scope.merge(association_scope) sc = target_scope.merge(association_scope) # Hobo adds in scopes declared on the association, e.g. has_many ..... :scope => :foo if (declared_scope = [:scope]) if declared_scope.is_a? Array declared_scope.inject(sc) { |result, element| result.merge(klass.send(element)) } elsif declared_scope.is_a? Hash method = declared_scope.keys.first arg = declared_scope.values.first sc.merge(klass.send(method, arg)) else # It's just a symbol -- the name of a scope sc.merge(klass.send(declared_scope)) end else sc end end |