Skip to content

Commit

Permalink
Rails 5
Browse files Browse the repository at this point in the history
  • Loading branch information
adamgeorgeson committed Jun 20, 2024
1 parent d45eb2d commit f9ff263
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 19 deletions.
9 changes: 5 additions & 4 deletions Appraisals
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ appraise "rails-4" do
gem 'bigdecimal', '~> 1.4'
end

# appraise "rails-5" do
# gem 'activemodel', '~> 5.0.7'
# gem 'bigdecimal'
# end
appraise "rails-5" do
gem 'activemodel', '~> 5.2'
gem 'bigdecimal'
gem 'alias_method_chain'
end

# appraise "rails-6" do
# gem 'activemodel', '~> 6.0.1'
Expand Down
6 changes: 2 additions & 4 deletions gemfiles/rails_5.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@

source "https://rubygems.org"

gem "akami", "~> 1.3.2"
gem "nokogiri", "~> 1.15.6"
gem "wasabi", ">= 3.7"
gem "activemodel", "~> 5.0.7"
gem "activemodel", "~> 5.2"
gem "bigdecimal"
gem "alias_method_chain"

gemspec path: "../"
21 changes: 17 additions & 4 deletions lib/zuora/attributes.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
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 @@ -39,9 +45,6 @@ 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|
# set up the instance variable for the new assoc collection
# for new records, but call the original one for existing
# records and cache/return the result for subsequent calls.
class_eval <<-EVAL
def #{scope}_with_complex
if new_record? || @#{scope}_cached
Expand All @@ -52,6 +55,14 @@ def #{scope}_with_complex
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
EVAL
end
end
Expand Down Expand Up @@ -209,8 +220,10 @@ def attributes

# remove all dirty tracking for the object and return self for chaining.
def clear_changed_attributes!
@changed_attributes = {}
clear_changes_information
self
# @changed_attributes = {}
# self
end

# the name to use when referencing remote Zuora objects
Expand Down
3 changes: 2 additions & 1 deletion lib/zuora/objects/amendment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ def apply_response(response_hash, type)
self.invoice_id = result[:invoice_id]
self.payment_transaction_number = result[:payment_transaction_number]
@previously_changed = changes
@changed_attributes.clear
# @changed_attributes.clear
clear_changes_information
return true
else
self.errors.add(:base, result[:errors][:message])
Expand Down
11 changes: 7 additions & 4 deletions lib/zuora/objects/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ def reload!
self.send("#{k}=", v)
}
@previously_changed = changes
@changed_attributes.clear
# @changed_attributes = ActiveSupport::HashWithIndifferentAccess.new
clear_changes_information
self
end

Expand Down Expand Up @@ -84,9 +85,9 @@ def self.select(select)
def self.all
keys = (attributes - unselectable_attributes).map(&:to_s).map(&:zuora_camelize)
sql = "select #{keys.join(', ')} from #{remote_name}"

result = self.connector.query(sql)

generate(result.to_hash, :query_response)
end

Expand Down Expand Up @@ -191,7 +192,9 @@ def apply_response(response_hash, type)
if result[:success]
self.id = result[:id]
@previously_changed = changes
@changed_attributes.clear
# require 'pry'; binding.pry
# @changed_attributes = ActiveSupport::HashWithIndifferentAccess.new
clear_changes_information
return true
else
raise StandardError.new(result[:errors][:message])
Expand Down
3 changes: 2 additions & 1 deletion lib/zuora/objects/subscribe_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ def apply_response(response_hash, type)
subscription.name = result[:subscription_number]
subscription.clear_changed_attributes!
@previously_changed = changes
@changed_attributes.clear
# @changed_attributes = ActiveSupport::HashWithIndifferentAccess.new
clear_changes_information
else
self.errors.add(:base, result[:errors][:message])
end
Expand Down
2 changes: 1 addition & 1 deletion zuora.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Gem::Specification.new do |s|
s.add_development_dependency 'test-unit'
s.add_development_dependency 'yard', '~> 0.7.5'

s.add_dependency 'activemodel', '< 5.0.0'
s.add_dependency 'activemodel'#, '< 5.0.0'
# s.add_dependency 'activesupport', '< 5.0.0'
s.add_dependency 'httpi', '~> 3.0'
s.add_dependency 'rack', '< 3.0'
Expand Down

0 comments on commit f9ff263

Please sign in to comment.