diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2009-02-06 12:18:24 -0800 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2009-02-06 12:18:24 -0800 |
commit | f7d509882ef1d5a54cb2b15e871cd70e4af3c5ed (patch) | |
tree | e4d1c4019694bf10e989b988bdd7389bebaf0cd7 /activeresource | |
parent | 95dfcc4f3c4bda74efe220e6dd5a11f58f29a501 (diff) | |
download | rails-f7d509882ef1d5a54cb2b15e871cd70e4af3c5ed.tar.gz rails-f7d509882ef1d5a54cb2b15e871cd70e4af3c5ed.tar.bz2 rails-f7d509882ef1d5a54cb2b15e871cd70e4af3c5ed.zip |
Prefer tap to returning
Diffstat (limited to 'activeresource')
-rw-r--r-- | activeresource/lib/active_resource/base.rb | 12 | ||||
-rw-r--r-- | activeresource/test/setter_trap.rb | 5 |
2 files changed, 8 insertions, 9 deletions
diff --git a/activeresource/lib/active_resource/base.rb b/activeresource/lib/active_resource/base.rb index 94418fb559..a8c0da31f2 100644 --- a/activeresource/lib/active_resource/base.rb +++ b/activeresource/lib/active_resource/base.rb @@ -462,7 +462,7 @@ module ActiveResource # that_guy.valid? # => false # that_guy.new? # => true def create(attributes = {}) - returning(self.new(attributes)) { |res| res.save } + self.new(attributes).tap { |resource| resource.save } end # Core method for finding resources. Used similarly to Active Record's +find+ method. @@ -600,7 +600,7 @@ module ActiveResource end def instantiate_record(record, prefix_options = {}) - returning new(record) do |resource| + new(record).tap do |resource| resource.prefix_options = prefix_options end end @@ -747,7 +747,7 @@ module ActiveResource # def ==(other) other.equal?(self) || (other.instance_of?(self.class) && other.id == id && other.prefix_options == prefix_options) - end + end # Tests for equality (delegates to ==). def eql?(other) @@ -773,7 +773,7 @@ module ActiveResource # my_invoice.customer # => That Company # next_invoice.customer # => That Company def dup - returning self.class.new do |resource| + self.class.new.tap do |resource| resource.attributes = @attributes resource.prefix_options = @prefix_options end @@ -985,14 +985,14 @@ module ActiveResource # Update the resource on the remote service. def update - returning connection.put(element_path(prefix_options), encode, self.class.headers) do |response| + connection.put(element_path(prefix_options), encode, self.class.headers).tap do |response| load_attributes_from_response(response) end end # Create (i.e., \save to the remote service) the \new resource. def create - returning connection.post(collection_path, encode, self.class.headers) do |response| + connection.post(collection_path, encode, self.class.headers).tap do |response| self.id = id_from_response(response) load_attributes_from_response(response) end diff --git a/activeresource/test/setter_trap.rb b/activeresource/test/setter_trap.rb index 9a899b0fa0..7cfd9ca111 100644 --- a/activeresource/test/setter_trap.rb +++ b/activeresource/test/setter_trap.rb @@ -1,9 +1,8 @@ class SetterTrap < ActiveSupport::BasicObject class << self def rollback_sets(obj) - returning yield(setter_trap = new(obj)) do - setter_trap.rollback_sets - end + trapped = new(obj) + yield(trapped).tap { trapped.rollback_sets } end end |