makandra / active_type

Make any Ruby object quack like ActiveRecord
MIT License
1.09k stars 74 forks source link

Fix aliassing ar_attribute method #164

Closed sudoremo closed 2 years ago

sudoremo commented 2 years ago

In lib/active_type/virtual_attributes.rb, an alias is created so that the original ActiveRecord method attribute still can be used:

class << self
  if method_defined?(:attribute)
    alias_method :ar_attribute, :attribute
  end
end

The problem is that, since this is an ActiveSupport::Concern, the ClassMethods-Module which contains the new attribute method is mixed in before the aliassing happens. This effectively aliases the ActiveType attribute to itself - at least with Ruby 3 and Rails 7.

This PR attempts to fix this by renaming the overriding method attribute to at_attribute and performing a second alias operation.

Many thanks for having a look at this 👍 🎆

kratob commented 2 years ago

Sorry, for the slow reaction; thanks for the PR.

sudoremo commented 2 years ago

Sorry, for the slow reaction; thanks for the PR.

No worries @kratob, thanks a lot for merging. Do you have any predictions when 2.3.0 (and therefore this PR) will be pushed to rubygems?

kratob commented 2 years ago

@sudoremo I thought I had released it already, but apparently not. It should be live now.

sudoremo commented 2 years ago

Many thanks @kratob :)