Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Use attr_accessor_with_default to dry up attribute initialization. Re…

…ferences #6538. [Stuart Halloway]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5540 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit 1d31a043e09761f260499b0bb5d3aa0396a4cf39 1 parent 309a6bd
Marcel Molina authored
View
2  activeresource/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Use attr_accessor_with_default to dry up attribute initialization. References #6538. [Stuart Halloway]
+
* Add basic logging support for logging outgoing requests. [Jamis Buck]
* Add Base.delete for deleting resources without having to instantiate them first. [Jamis Buck]
View
29 activeresource/lib/active_resource/base.rb
@@ -20,14 +20,10 @@ def connection(refresh = false)
@connection
end
- def element_name
- self.to_s.underscore
- end
-
- def collection_name
- element_name.pluralize
- end
-
+ attr_accessor_with_default(:element_name) { to_s.underscore }
+ attr_accessor_with_default(:collection_name) { element_name.pluralize }
+ attr_accessor_with_default(:primary_key, 'id')
+
def prefix(options={})
default = site.path
default << '/' unless default[-1..-1] == '/'
@@ -42,16 +38,7 @@ def prefix=(value = '/')
end
alias_method :set_prefix, :prefix=
- def element_name=(value)
- class << self ; attr_reader :element_name ; end
- @element_name = value
- end
alias_method :set_element_name, :element_name=
-
- def collection_name=(value)
- class << self ; attr_reader :collection_name ; end
- @collection_name = value
- end
alias_method :set_collection_name, :collection_name=
def element_path(id, options = {})
@@ -62,14 +49,6 @@ def collection_path(options = {})
"#{prefix(options)}#{collection_name}.xml"
end
- def primary_key
- self.primary_key = 'id'
- end
-
- def primary_key=(value)
- class << self ; attr_reader :primary_key ; end
- @primary_key = value
- end
alias_method :set_primary_key, :primary_key=
# Person.find(1) # => GET /people/1.xml
Please sign in to comment.
Something went wrong with that request. Please try again.