Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Minimum ActiveResource now 3.0; XML Serialization patched

With this commit, the minimum Rails/ActiveResource version is now
set to 3.0.  Versions between 3.0.0 and 3.0.19 will have their
ActiveModel XML serialization patched according to
rails/rails#8853 since Chargify will no longer
allow XML with `type="yaml"` parameters.  See the Readme for more
information.
  • Loading branch information...
commit e127fdc442ea1172f675051cd4927f28b6cea7f4 1 parent 7d041e2
@moklett moklett authored
View
2  Gemfile.lock
@@ -2,7 +2,7 @@ PATH
remote: .
specs:
chargify_api_ares (0.5.4)
- activeresource (>= 2.3.5)
+ activeresource (>= 3.0.0)
GEM
remote: http://rubygems.org/
View
2  chargify_api_ares.gemspec
@@ -17,7 +17,7 @@ Gem::Specification.new do |s|
s.require_paths = %w[lib]
# Runtime Dependencies
- s.add_runtime_dependency('activeresource', '>= 2.3.5')
+ s.add_runtime_dependency('activeresource', '>= 3.0.0')
# Development Dependencies
s.add_development_dependency('rake', '~> 10.0.3')
View
5 lib/chargify_api_ares.rb
@@ -15,9 +15,10 @@
require 'chargify_api_ares/resources/usage'
require 'chargify_api_ares/resources/webhook'
+require 'active_resource/version'
if defined?(::ActiveResource::VERSION::MAJOR) &&
::ActiveResource::VERSION::MAJOR == 3 &&
::ActiveResource::VERSION::MINOR == 0 &&
::ActiveResource::VERSION::TINY < 20
- raise RuntimeError, 'This gem is not compatible with ActiveResource versions 3.0.0 to 3.0.19, please upgrade to at least 3.0.20'
-end
+ require 'patches/activemodel_3_0_patch.rb'
+end
View
23 lib/patches/activemodel_3_0_patch.rb
@@ -0,0 +1,23 @@
+ActiveSupport::Deprecation.warn("The Chargify gem is patching your ActiveModel because it is less than version 3.0.20! (https://github.com/chargify/chargify_api_ares/blob/master/README.md)")
+
+module ActiveModel
+ module Serializers
+ module Xml
+ class Serializer
+ class Attribute
+ protected
+
+ # Patch `compute_type` to avoid adding `type="yaml"` to
+ # nil attributes in < 3.0.20 ActiveModel
+ #
+ # See https://github.com/rails/rails/pull/8853
+ alias_method :compute_type_orig, :compute_type
+ def compute_type
+ return if value.nil?
+ compute_type_orig
+ end
+ end
+ end
+ end
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.