Sha256: 733c489e05c6e8ced3c4d3a3d9d2179252eb826f4b24646768e5b78ce712b587

Contents?: true

Size: 1.67 KB

Versions: 7

Compression:

Stored size: 1.67 KB

Contents

# frozen_string_literal: true

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

        if Rails.version.to_f < 5.1
          module CollectionAssociation
            private
            def first_nth_or_last(*)
              ActiveDecorator::Decorator.instance.decorate_association(owner, super)
            end
          end
        end

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

          if Rails.version.to_f >= 5.1
            def last(*)
              ActiveDecorator::Decorator.instance.decorate_association(@association.owner, super)
            end

            private

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

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

        module CollectionAssociation
          private

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

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

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
active_decorator-1.4.1 lib/active_decorator/monkey/active_record/associations.rb
active_decorator-1.4.0 lib/active_decorator/monkey/active_record/associations.rb
active_decorator-1.3.4 lib/active_decorator/monkey/active_record/associations.rb
active_decorator-1.3.3 lib/active_decorator/monkey/active_record/associations.rb
active_decorator-1.3.2 lib/active_decorator/monkey/active_record/associations.rb
active_decorator-1.3.1 lib/active_decorator/monkey/active_record/associations.rb
active_decorator-1.3.0 lib/active_decorator/monkey/active_record/associations.rb