Skip to content

Instantly share code, notes, and snippets.

@spastorino
Created October 12, 2010 14:15
Show Gist options
  • Save spastorino/622228 to your computer and use it in GitHub Desktop.
Save spastorino/622228 to your computer and use it in GitHub Desktop.
diff --git a/activeresource/lib/active_resource/base.rb b/activeresource/lib/active_resource/base.rb
index b5b46d7..b47ce0e 100644
--- a/activeresource/lib/active_resource/base.rb
+++ b/activeresource/lib/active_resource/base.rb
@@ -3,7 +3,6 @@ require 'active_support/core_ext/class/attribute_accessors'
require 'active_support/core_ext/class/inheritable_attributes'
require 'active_support/core_ext/hash/indifferent_access'
require 'active_support/core_ext/kernel/reporting'
-require 'active_support/core_ext/module/attr_accessor_with_default'
require 'active_support/core_ext/module/delegation'
require 'active_support/core_ext/module/aliasing'
require 'active_support/core_ext/object/blank'
@@ -563,10 +562,10 @@ module ActiveResource
@headers ||= {}
end
- attr_accessor_with_default(:element_name) { model_name.element } #:nodoc:
- attr_accessor_with_default(:collection_name) { ActiveSupport::Inflector.pluralize(element_name) } #:nodoc:
+ attr_accessor :element_name
+ attr_accessor :collection_name
- attr_accessor_with_default(:primary_key, 'id') #:nodoc:
+ attr_accessor :primary_key
# Gets the \prefix for a resource's nested URL (e.g., <tt>prefix/collectionname/1.xml</tt>)
# This method is regenerated at runtime based on what the \prefix is set to.
@@ -1314,6 +1313,12 @@ module ActiveResource
super({ :root => self.class.element_name }.merge(options))
end
+ def self.inherited(subclass)
+ subclass.element_name = subclass.model_name.element
+ subclass.collection_name = ActiveSupport::Inflector.pluralize(subclass.element_name)
+ subclass.primary_key = 'id'
+ end
+
protected
def connection(refresh = false)
self.class.connection(refresh)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment