Sha256: d252e06591e8ebcc2042e5e6c1457d4aa5353e45af895dcc5a69def54302df85

Contents?: true

Size: 1.57 KB

Versions: 8

Compression:

Stored size: 1.57 KB

Contents

# frozen_string_literal: true

# A monkey-patch for Active Record that enables association auto-decoration.
module Gifted
  module Monkey
    module ActiveRecord
      module Associations
        module Association
          def target
            Gifted::Decorator.instance.decorate_association(owner, super)
          end
        end

        module CollectionProxy
          def take(*)
            Gifted::Decorator.instance.decorate_association(@association.owner, super)
          end

          def last(*)
            Gifted::Decorator.instance.decorate_association(@association.owner, super)
          end

          private

            def find_nth_with_limit(*)
              Gifted::Decorator.instance.decorate_association(@association.owner, super)
            end

            def find_nth_from_last(*)
              Gifted::Decorator.instance.decorate_association(@association.owner, super)
            end
        end

        module CollectionAssociation
          private

            def build_record(*)
              Gifted::Decorator.instance.decorate_association(@owner, super)
            end
        end
      end

      module AssociationRelation
        def take(*)
          Gifted::Decorator.instance.decorate_association(@association.owner, super)
        end

        private

          def find_nth_with_limit(*)
            Gifted::Decorator.instance.decorate_association(@association.owner, super)
          end

          def find_nth_from_last(*)
            Gifted::Decorator.instance.decorate_association(@association.owner, super)
          end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
gifted-1.3.0 lib/gifted/monkey/active_record/associations.rb
gifted-1.2.0 lib/gifted/monkey/active_record/associations.rb
gifted-1.1.1 lib/gifted/monkey/active_record/associations.rb
gifted-1.1.0 lib/gifted/monkey/active_record/associations.rb
gifted-1.0.0 lib/gifted/monkey/active_record/associations.rb
gifted-0.2.1 lib/gifted/monkey/active_record/associations.rb
gifted-0.2.0 lib/gifted/monkey/active_record/associations.rb
gifted-0.1.0 lib/gifted/monkey/active_record/associations.rb