Selaa lähdekoodia

Merge pull request #91 from Shopify/avoid_overriding_methods_unnecessarily

Don't override headers and delete methods in AR4
Peter McCracken 11 vuotta sitten
vanhempi
commit
a7dad7f313
1 muutettua tiedostoa jossa 15 lisäystä ja 11 poistoa
  1. 15 11
      lib/active_resource/base_ext.rb

+ 15 - 11
lib/active_resource/base_ext.rb

@@ -1,19 +1,23 @@
 module ActiveResource
   class Base
-    # Backported from ActiveResource master branch
-    def self.headers
-      @headers ||= {}
+    if ActiveResource::VERSION::MAJOR < 4
+      # Backported from ActiveResource master branch
+      def self.headers
+        @headers ||= {}
 
-      if superclass != Object && superclass.headers
-        @headers = superclass.headers.merge(@headers)
-      else
-        @headers
+        if superclass != Object && superclass.headers
+          @headers = superclass.headers.merge(@headers)
+        else
+          @headers
+        end
+      end
+
+      # https://github.com/rails/activeresource/commit/dfef85ce8f653f75673631b2950fcdb0781c313c
+      def self.delete(id, options = {})
+        connection.delete(element_path(id, options), headers)
       end
     end
-    # https://github.com/rails/activeresource/commit/dfef85ce8f653f75673631b2950fcdb0781c313c
-    def self.delete(id, options = {})
-      connection.delete(element_path(id, options), headers)
-    end
+
     def self.build(attributes = {})
       attrs = self.format.decode(connection.get("#{new_element_path}", headers).body).merge(attributes)
       self.new(attrs)