Permalink
Browse files

Changes the usage of Object#returning with Object#tap

Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information...
1 parent dec2c4f commit a5d8c95a7c55f1756d944279f7f748af30b3c003 @spastorino spastorino committed with josevalim Jul 25, 2010
@@ -105,7 +105,7 @@ def inherited_with_helper(child)
private
# Extend the template class instance with our controller's helper module.
def initialize_template_class_with_helper(assigns)
- returning(template = initialize_template_class_without_helper(assigns)) do
+ initialize_template_class_without_helper(assigns).tap do |template|
template.extend self.class.master_helper_module
end
end
@@ -414,7 +414,7 @@ def requestify(parameters, prefix=nil)
end
def multipart_requestify(params, first=true)
- returning Array.new do |p|
+ Array.new.tap do |p|
params.each do |key, value|
k = first ? key.to_s : "[#{key.to_s}]"
if Hash === value
@@ -511,7 +511,7 @@ def reset!
reset! unless @integration_session
# reset the html_document variable, but only for new get/post calls
@html_document = nil unless %w(cookies assigns).include?(method)
- returning @integration_session.__send__(method, *args) do
+ @integration_session.__send__(method, *args).tap do
copy_session_variables!
end
end
@@ -567,7 +567,7 @@ def copy_session_variables! #:nodoc:
def method_missing(sym, *args, &block)
reset! unless @integration_session
if @integration_session.respond_to?(sym)
- returning @integration_session.__send__(sym, *args, &block) do
+ @integration_session.__send__(sym, *args, &block).tap do
copy_session_variables!
end
else
@@ -659,7 +659,7 @@ def map_resource_routes(map, resource, action, route_path, route_name = nil, met
end
def add_conditions_for(conditions, method)
- returning({:conditions => conditions.dup}) do |options|
+ ({:conditions => conditions.dup}).tap do |options|
options[:conditions][:method] = method unless method == :any
end
end
@@ -377,7 +377,7 @@ def controller_relative_to(controller, previous)
ActiveSupport::Inflector.module_eval do
# Ensures that routes are reloaded when Rails inflections are updated.
def inflections_with_route_reloading(&block)
- returning(inflections_without_route_reloading(&block)) {
+ (inflections_without_route_reloading(&block)).tap {
ActionController::Routing::Routes.reload! if block_given?
}
end
@@ -65,7 +65,7 @@ def build_query_string(hash, only_keys = nil)
# map.connect '/page/:id', :controller => 'pages', :action => 'show', :id => /\d+/
#
def parameter_shell
- @parameter_shell ||= returning({}) do |shell|
+ @parameter_shell ||= {}.tap do |shell|
requirements.each do |key, requirement|
shell[key] = requirement unless requirement.is_a? Regexp
end
@@ -76,7 +76,7 @@ def parameter_shell
# includes keys that appear inside the path, and keys that have requirements
# placed upon them.
def significant_keys
- @significant_keys ||= returning([]) do |sk|
+ @significant_keys ||= [].tap do |sk|
segments.each { |segment| sk << segment.key if segment.respond_to? :key }
sk.concat requirements.keys
sk.uniq!
@@ -86,7 +86,7 @@ def significant_keys
# Return a hash of key/value pairs representing the keys in the route that
# have defaults, or which are specified by non-regexp requirements.
def defaults
- @defaults ||= returning({}) do |hash|
+ @defaults ||= {}.tap do |hash|
segments.each do |segment|
next unless segment.respond_to? :default
hash[segment.key] = segment.default unless segment.default.nil?
@@ -450,7 +450,7 @@ def process(action, parameters = nil, session = nil, flash = nil, http_method =
def xml_http_request(request_method, action, parameters = nil, session = nil, flash = nil)
@request.env['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest'
@request.env['HTTP_ACCEPT'] = [Mime::JS, Mime::HTML, Mime::XML, 'text/xml', Mime::ALL].join(', ')
- returning __send__(request_method, action, parameters, session, flash) do
+ __send__(request_method, action, parameters, session, flash).tap do
@request.env.delete 'HTTP_X_REQUESTED_WITH'
@request.env.delete 'HTTP_ACCEPT'
end
@@ -440,7 +440,7 @@ def field_set_tag(legend = nil, options = nil, &block)
private
def html_options_for_form(url_for_options, options, *parameters_for_url)
- returning options.stringify_keys do |html_options|
+ options.stringify_keys.tap do |html_options|
html_options["enctype"] = "multipart/form-data" if html_options.delete("multipart")
html_options["action"] = url_for(url_for_options, *parameters_for_url)
end
@@ -653,7 +653,7 @@ def include_helpers_from_context
# <script> tag.
module GeneratorMethods
def to_s #:nodoc:
- returning javascript = @lines * $/ do
+ (@lines * $/).tap do |javascript|
if ActionView::Base.debug_rjs
source = javascript.dup
javascript.replace "try {\n#{source}\n} catch (e) "
@@ -981,8 +981,8 @@ def page
end
def record(line)
- returning line = "#{line.to_s.chomp.gsub(/\;\z/, '')};" do
- self << line
+ "#{line.to_s.chomp.gsub(/\;\z/, '')};".tap do |_line|
+ self << _line
end
end
@@ -45,8 +45,8 @@ def load!
end
def self.new_and_loaded(path)
- returning new(path) do |path|
- path.load!
+ new(path).tap do |_path|
+ _path.load!
end
end
@@ -2646,7 +2646,7 @@ def clone
# Note: The new instance will share a link to the same attributes as the original class. So any change to the attributes in either
# instance will affect the other.
def becomes(klass)
- returning klass.new do |became|
+ klass.new.tap do |became|
became.instance_variable_set("@attributes", @attributes)
became.instance_variable_set("@attributes_cache", @attributes_cache)
became.instance_variable_set("@new_record", new_record?)
@@ -25,7 +25,7 @@ def self.sqlite3_connection(config) # :nodoc:
module ConnectionAdapters #:nodoc:
class SQLite3Adapter < SQLiteAdapter # :nodoc:
def table_structure(table_name)
- returning structure = @connection.table_info(quote_table_name(table_name)) do
+ @connection.table_info(quote_table_name(table_name)).tap do |structure|
raise(ActiveRecord::StatementInvalid, "Could not find table '#{table_name}'") if structure.empty?
end
end
@@ -330,7 +330,7 @@ def select(sql, name = nil) #:nodoc:
end
def table_structure(table_name)
- returning structure = execute("PRAGMA table_info(#{quote_table_name(table_name)})") do
+ execute("PRAGMA table_info(#{quote_table_name(table_name)})").tap do |structure|
raise(ActiveRecord::StatementInvalid, "Could not find table '#{table_name}'") if structure.empty?
end
end
@@ -516,7 +516,7 @@ def migrations
raise DuplicateMigrationNameError.new(name.camelize)
end
- klasses << returning(MigrationProxy.new) do |migration|
+ klasses << (MigrationProxy.new).tap do |migration|
migration.name = name.camelize
migration.version = version
migration.filename = file
@@ -74,7 +74,7 @@ def add_includes(&block)
end
def serializable_record
- returning(serializable_record = {}) do
+ {}.tap do |serializable_record|
serializable_names.each { |name| serializable_record[name] = @record.send(name) }
add_includes do |association, records, opts|
if records.is_a?(Enumerable)
@@ -33,7 +33,7 @@ def in_groups_of(number, fill_with = nil)
if block_given?
collection.each_slice(number) { |slice| yield(slice) }
else
- returning [] do |groups|
+ [].tap do |groups|
collection.each_slice(number) { |group| groups << group }
end
end
@@ -75,7 +75,7 @@ def sum(identity = 0, &block)
# (1..5).each_with_object(1) { |value, memo| memo *= value } # => 1
#
def each_with_object(memo, &block)
- returning memo do |m|
+ memo.tap do |m|
each do |element|
block.call(element, m)
end
@@ -12,7 +12,7 @@ def step_with_blockless(value = 1, &block)
if block_given?
step_without_blockless(value, &block)
else
- returning [] do |array|
+ [].tap do |array|
step_without_blockless(value) { |step| array << step }
end
end
@@ -7,7 +7,7 @@ class Record
class << self
def callback_symbol(callback_method)
- returning("#{callback_method}_method") do |method_name|
+ "#{callback_method}_method".tap do |method_name|
define_method(method_name) do
history << [callback_method, :symbol]
end
@@ -55,7 +55,7 @@ def to_s
alias inspect to_s
def to_html
- returning table = '<table>' do
+ '<table>'.tap do |table|
properties.each do |(name, value)|
table << %(<tr><td class="name">#{CGI.escapeHTML(name.to_s)}</td>)
table << %(<td class="value">#{CGI.escapeHTML(value.to_s)}</td></tr>)
@@ -35,7 +35,7 @@ def valid?
def load_paths
report_nonexistant_or_empty_plugin! unless valid?
- returning [] do |load_paths|
+ [].tap do |load_paths|
load_paths << lib_path if has_lib_directory?
load_paths << app_paths if has_app_directory?
end.flatten
@@ -8,7 +8,7 @@ def manifest
private
def get_local_assigns
- returning(assigns = {}) do
+ {}.tap do |assigns|
if class_name.underscore =~ /^(add|remove)_.*_(?:to|from)_(.*)/
assigns[:migration_action] = $1
assigns[:table_name] = $2.pluralize

0 comments on commit a5d8c95

Please sign in to comment.