Sha256: db1630bcd9a9c761bbeda9d08982ced39ce6bca22743344267dbe0d5642713bf

Contents?: true

Size: 1.22 KB

Versions: 19

Compression:

Stored size: 1.22 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)
          raise ActiveRecord::AssociationTypeMismatch, "#{@reflection.klass} expected, got #{record.class}"
        end
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
hobo-2.0.1 lib/hobo/extensions/active_record/associations/association.rb
hobo-2.0.0 lib/hobo/extensions/active_record/associations/association.rb
hobo-2.0.0.pre10 lib/hobo/extensions/active_record/associations/association.rb
hobo-2.0.0.pre9 lib/hobo/extensions/active_record/associations/association.rb
hobo-2.0.0.pre8 lib/hobo/extensions/active_record/associations/association.rb
hobo-2.0.0.pre7 lib/hobo/extensions/active_record/associations/association.rb
hobo-2.0.0.pre6 lib/hobo/extensions/active_record/associations/association.rb
hobo-2.0.0.pre5 lib/hobo/extensions/active_record/associations/association.rb
hobo-2.0.0.pre4 lib/hobo/extensions/active_record/associations/association.rb
hobo-2.0.0.pre3 lib/hobo/extensions/active_record/associations/association.rb
hobo-2.0.0.pre2 lib/hobo/extensions/active_record/associations/association.rb
hobo-2.0.0.pre1 lib/hobo/extensions/active_record/associations/association.rb
hobo-1.4.0.pre8 lib/hobo/extensions/active_record/associations/association.rb
hobo-1.4.0.pre7 lib/hobo/extensions/active_record/associations/association.rb
hobo-1.4.0.pre6 lib/hobo/extensions/active_record/associations/association.rb
hobo-1.4.0.pre5 lib/hobo/extensions/active_record/associations/association.rb
hobo-1.4.0.pre4 lib/hobo/extensions/active_record/associations/association.rb
hobo-1.4.0.pre3 lib/hobo/extensions/active_record/associations/association.rb
hobo-1.4.0.pre2 lib/hobo/extensions/active_record/associations/association.rb