]> gitweb.fluxo.info Git - leap/leap_cli.git/commitdiff
json bugfix: upgrading CertificateAuthority gem broke everything, since it depends...
authorelijah <elijah@riseup.net>
Wed, 22 Oct 2014 08:27:08 +0000 (01:27 -0700)
committerelijah <elijah@riseup.net>
Wed, 22 Oct 2014 08:27:08 +0000 (01:27 -0700)
lib/leap_cli.rb
lib/override/json.rb [new file with mode: 0644]
lib/override/to_json.rb [new file with mode: 0644]

index 6cd625e77b8931c09beb3b64a84bad5889633a68..baff32fc4d73b8efa364172a029d97ff153d897b 100644 (file)
@@ -5,6 +5,10 @@ end
 
 $ruby_version = RUBY_VERSION.split('.').collect{ |i| i.to_i }.extend(Comparable)
 
+# ensure leap_cli/lib/overrides has the highest priority
+# (these files override bad behavior in gems that overrides JSON)
+$:.unshift(File.expand_path('../override',__FILE__))
+
 require 'leap/platform'
 
 require 'leap_cli/version'
diff --git a/lib/override/json.rb b/lib/override/json.rb
new file mode 100644 (file)
index 0000000..8857a22
--- /dev/null
@@ -0,0 +1,11 @@
+#
+# This exists solely to prevent other gems we depend on from
+# importing json/ext (e.g. require 'json').
+#
+# If json/ext is imported, json/pure cannot work, and we heavily
+# rely on the specific behavior of json/pure.
+#
+# This trick only works if this directory is early in the
+# include path.
+#
+require 'json/pure'
diff --git a/lib/override/to_json.rb b/lib/override/to_json.rb
new file mode 100644 (file)
index 0000000..73fbe5c
--- /dev/null
@@ -0,0 +1,20 @@
+#
+# activesupport/lib/core_ext/object/to_json.rb overrides to_json for
+# most core objects like so:
+#
+#    [Object, Array, FalseClass, Float, Hash, Integer, NilClass, String, TrueClass].each do |klass|
+#      klass.class_eval do
+#        # Dumps object in JSON (JavaScript Object Notation). See www.json.org for more info.
+#        def to_json(options = nil)
+#          ActiveSupport::JSON.encode(self, options)
+#        end
+#      end
+#    end
+#
+# We cannot tolerate this. We need the normal to_json to be called, not
+# ActiveSupport's custom version.
+#
+# This file exists to override the behavior of ActiveSupport. This file will get included
+# instead of the normal to_json.rb.
+#
+