Sha256: befced4e21ebcb657b676a1ffd2d1c5899d6dfa1443125f422ecb5fa1e4a2dc0

Contents?: true

Size: 936 Bytes

Versions: 4

Compression:

Stored size: 936 Bytes

Contents

# frozen_string_literal: true

require 'activemodel/associations'
require 'eac_ruby_utils/core_ext'

module EacRailsUtils
  module Patches
    module Rails52
      class ActiveModelAssociationMethodFix
        common_constructor :method_name do
          perform
        end

        def original_method_new_name
          "original_#{method_name}".to_sym
        end

        private

        def the_module
          ::EacRailsUtils::Models::TablelessAssociations::ClassMethods
        end

        def perform
          patch = self
          the_module.class_eval do
            alias_method patch.original_method_new_name, patch.method_name
            remove_method patch.method_name

            define_method patch.method_name do |name, scope = nil, **options, &extension|
              send(patch.original_method_new_name, name, scope, options, &extension)
            end
          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
eac_rails_utils-0.22.2 lib/eac_rails_utils/patches/rails_5_2/active_model_association_method_fix.rb
eac_rails_utils-0.22.1 lib/eac_rails_utils/patches/rails_5_2/active_model_association_method_fix.rb
eac_rails_utils-0.22.0 lib/eac_rails_utils/patches/rails_5_2/active_model_association_method_fix.rb
eac_rails_utils-0.21.0 lib/eac_rails_utils/patches/rails_5_2/active_model_association_method_fix.rb