Sha256: 706eec44ba0d2980b25daff6efe83efa10c3d409cef8ca2fd4e2fdf3c2dc9d36

Contents?: true

Size: 780 Bytes

Versions: 5

Compression:

Stored size: 780 Bytes

Contents

module ActiveRecord

  class Relation
    attr_accessor :origin, :origin_attribute

    def member_class
      @klass
    end
  end

  module Associations
    class AssociationCollection

      def scoped_with_origin
        relation = scoped_without_origin.clone
        relation.origin = @owner
        relation.origin_attribute = @reflection.name
        relation
      end
      alias_method_chain :scoped, :origin

      def method_missing_with_origin(method, *args, &block)
        res = method_missing_without_origin(method, *args, &block)
        res.origin = @owner if res.respond_to?(:origin)
        res.origin_attribute = @reflection.name if res.respond_to?(:origin_attribute)
        res
      end
      alias_method_chain :method_missing, :origin

    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
hobo-1.3.0 lib/hobo/extensions/active_record/relation_with_origin.rb
hobo-1.3.0.RC4 lib/hobo/extensions/active_record/relation_with_origin.rb
hobo-1.3.0.RC3 lib/hobo/extensions/active_record/relation_with_origin.rb
hobo-1.3.0.RC2 lib/hobo/extensions/active_record/relation_with_origin.rb
hobo-1.3.0.RC1 lib/hobo/extensions/active_record/relation_with_origin.rb