diff options
author | Marcel Molina <marcel@vernix.org> | 2006-11-16 19:36:50 +0000 |
---|---|---|
committer | Marcel Molina <marcel@vernix.org> | 2006-11-16 19:36:50 +0000 |
commit | 1d31a043e09761f260499b0bb5d3aa0396a4cf39 (patch) | |
tree | a44f09a63e827a3cd0cab50f4c5f0ad955861284 /activeresource | |
parent | 309a6bd550281b60f25be28ea76a5cce5f9b377b (diff) | |
download | rails-1d31a043e09761f260499b0bb5d3aa0396a4cf39.tar.gz rails-1d31a043e09761f260499b0bb5d3aa0396a4cf39.tar.bz2 rails-1d31a043e09761f260499b0bb5d3aa0396a4cf39.zip |
Use attr_accessor_with_default to dry up attribute initialization. References #6538. [Stuart Halloway]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5540 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activeresource')
-rw-r--r-- | activeresource/CHANGELOG | 2 | ||||
-rw-r--r-- | activeresource/lib/active_resource/base.rb | 29 |
2 files changed, 6 insertions, 25 deletions
diff --git a/activeresource/CHANGELOG b/activeresource/CHANGELOG index 43ab43c6cb..517e9a6458 100644 --- a/activeresource/CHANGELOG +++ b/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] diff --git a/activeresource/lib/active_resource/base.rb b/activeresource/lib/active_resource/base.rb index 9b5432ed37..5d72d98be6 100644 --- a/activeresource/lib/active_resource/base.rb +++ b/activeresource/lib/active_resource/base.rb @@ -20,14 +20,10 @@ module ActiveResource @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 @@ module ActiveResource 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 @@ module ActiveResource "#{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 |