Skip to content

Commit

Permalink
Remove alias_method_chain gem and include the patch from Vincent :tada
Browse files Browse the repository at this point in the history
  • Loading branch information
tapan-sh committed Jun 20, 2024
1 parent 9206e14 commit 1a84c48
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 29 deletions.
3 changes: 0 additions & 3 deletions Appraisals
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,19 @@ end

appraise "rails-5" do
gem 'activemodel', '~> 5.2'
gem 'alias_method_chain'
gem 'bigdecimal'
gem 'sqlite3', '~> 1.4.0'
gem 'i18n', '~> 1.5.1'
end

appraise "rails-6" do
gem 'activemodel', '~> 6.1'
gem 'alias_method_chain'
gem 'bigdecimal'
gem 'sqlite3', '~> 2.0'
end

appraise "rails-7" do
gem 'activemodel', '~> 7.1'
gem 'alias_method_chain'
gem 'bigdecimal'
gem 'sqlite3', '~> 2.0'
end
1 change: 0 additions & 1 deletion gemfiles/rails_5.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
source "https://rubygems.org"

gem "activemodel", "~> 5.2"
gem "alias_method_chain"
gem "bigdecimal"
gem "sqlite3", "~> 1.4.0"
gem "i18n", "~> 1.5.1"
Expand Down
1 change: 0 additions & 1 deletion gemfiles/rails_6.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
source "https://rubygems.org"

gem "activemodel", "~> 6.1"
gem "alias_method_chain"
gem "bigdecimal"
gem "sqlite3", "~> 2.0"

Expand Down
1 change: 0 additions & 1 deletion gemfiles/rails_7.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
source "https://rubygems.org"

gem "activemodel", "~> 7.1"
gem "alias_method_chain"
gem "bigdecimal"
gem "sqlite3", "~> 2.0"

Expand Down
34 changes: 11 additions & 23 deletions lib/zuora/attributes.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
module Zuora
module Attributes

# If Rails 5.2 is used, alias_method_chain is required
if Gem.loaded_specs['activemodel'].version >= Gem::Version.new('5.2')
require 'alias_method_chain'
end

def self.included(base)
base.send(:include, ActiveModel::Naming)
base.send(:include, ActiveModel::Conversion)
Expand Down Expand Up @@ -45,24 +40,17 @@ def define_attributes(&block)
# generate association overrides for complex object handling
# and cache the objects so that they may be modified and updated
class_variable_get(:@@complex_attributes).each do |var, scope|
class_eval <<-EVAL
def #{scope}_with_complex
if new_record? || @#{scope}_cached
@#{scope} ||= []
else
@#{scope}_cached = true
@#{scope} = #{scope}_without_complex
class_eval <<~EVAL
prepend(Module.new do
def #{scope}
if new_record? || @#{scope}_cached
@#{scope} ||= []
else
@#{scope}_cached = true
@#{scope} = super
end
end
end
alias_method_chain :#{scope}, :complex
# if method_defined?(:#{scope})
# prepend Module.new {
# super
# # alias_method :#{scope}_without_complex, :#{scope}
# # alias_method :#{scope}, :#{scope}_with_complex
# }
# end
end)
EVAL
end
end
Expand Down Expand Up @@ -231,4 +219,4 @@ def remote_name
self.class.name.base_name
end
end
end
end

0 comments on commit 1a84c48

Please sign in to comment.