Sha256: f8047e93b51dd0f51f157beb276c1094be563719aa6633e9157fc69f7a5afa9e
Contents?: true
Size: 1.24 KB
Versions: 13
Compression:
Stored size: 1.24 KB
Contents
module ActiveRecord module Associations class Association #:nodoc: 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 = options[: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 private def raise_on_type_mismatch!(record) # Don't complain if the interface type of a polymorphic association doesn't exist klass = @reflection.klass rescue nil unless klass.nil? || record.is_a?(klass) || record.is_a?(Array) raise ActiveRecord::AssociationTypeMismatch, "#{@reflection.klass} expected, got #{record.class}" end end end end end
Version data entries
13 entries across 13 versions & 1 rubygems