Skip to content

Commit

Permalink
Fix deprecation notices from the 'returning' function which is now .t…
Browse files Browse the repository at this point in the history
…ap on whatever it was using.
  • Loading branch information
parndt committed Oct 13, 2010
1 parent 3543a93 commit 9248a80
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 18 deletions.
Expand Up @@ -237,15 +237,15 @@ def thumbnail_class

# Copies the given file path to a new tempfile, returning the closed tempfile.
def copy_to_temp_file(file, temp_base_name)
returning Tempfile.new(temp_base_name, Technoweenie::AttachmentFu.tempfile_path) do |tmp|
Tempfile.new(temp_base_name, Technoweenie::AttachmentFu.tempfile_path).tap do |tmp|
tmp.close
FileUtils.cp file, tmp.path
end
end

# Writes the given data to a new tempfile, returning the closed tempfile.
def write_to_temp_file(data, temp_base_name)
returning Tempfile.new(temp_base_name, Technoweenie::AttachmentFu.tempfile_path) do |tmp|
Tempfile.new(temp_base_name, Technoweenie::AttachmentFu.tempfile_path).tap do |tmp|
tmp.binmode
tmp.write data
tmp.close
Expand Down Expand Up @@ -288,7 +288,7 @@ def thumbnail_name_for(thumbnail = nil)
# Creates or updates the thumbnail for the current attachment.
def create_or_update_thumbnail(temp_file, file_name_suffix, *size)
thumbnailable? || raise(ThumbnailError.new("Can't create a thumbnail if the content type is not an image or there is no parent_id column"))
returning find_or_initialize_thumbnail(file_name_suffix) do |thumb|
find_or_initialize_thumbnail(file_name_suffix).tap do |thumb|
thumb.temp_paths.unshift temp_file
thumb.send(:'attributes=', {
:content_type => content_type,
Expand Down Expand Up @@ -409,7 +409,7 @@ def random_tempfile_filename

def sanitize_filename(filename)
return unless filename
returning filename.strip do |name|
filename.strip.tap do |name|
# NOTE: File.basename doesn't work right with Windows paths on Unix
# get only the filename, not the whole path
name.gsub! /^.*(\\|\/)/, ''
Expand Down
2 changes: 1 addition & 1 deletion vendor/plugins/i18n-js/lib/i18n-js.rb
Expand Up @@ -116,7 +116,7 @@ def deep_merge!(target, hash) # :nodoc:
# Taken from http://seb.box.re/2010/1/15/deep-hash-ordering-with-ruby-1-8/
def sorted_hash(object, deep = false) # :nodoc:
if object.is_a?(Hash)
res = returning(ActiveSupport::OrderedHash.new) do |map|
res = ActiveSupport::OrderedHash.new.tap do |map|
object.each {|k, v| map[k] = deep ? sorted_hash(v, deep) : v }
end
return res.class[res.sort {|a, b| a[0].to_s <=> b[0].to_s } ]
Expand Down
8 changes: 4 additions & 4 deletions vendor/plugins/i18n/lib/i18n_filter.rb
Expand Up @@ -16,13 +16,13 @@ def around_recognize(path, env, &block)
::I18n.locale = ::Refinery::I18n.default_frontend_locale
end

returning yield do |params|
yield.tap do |params|
unless path =~ %r{^/(admin|refinery|wymiframe)} or ::I18n.locale == ::Refinery::I18n.default_frontend_locale
params[:locale] = (locale.presence || ::Refinery::I18n.current_frontend_locale)
end
end
else
returning yield do |result|
yield.tap do |result|
result
end
end
Expand All @@ -31,14 +31,14 @@ def around_recognize(path, env, &block)
def around_generate(*args, &block)
if ::Refinery::I18n.enabled?
locale = args.extract_options!.delete(:locale) || ::I18n.locale
returning yield do |result|
yield.tap do |result|
if (locale != ::Refinery::I18n.default_frontend_locale and result !~ %r{^/(refinery|wymiframe)})
result.sub!(%r(^(http.?://[^/]*)?(.*))){ "#{$1}/#{locale}#{$2}" }
end
result
end
else
returning yield do |result|
yield.tap do |result|
result
end
end
Expand Down
4 changes: 2 additions & 2 deletions vendor/plugins/i18n/lib/routing_filter/README.markdown
Expand Up @@ -22,7 +22,7 @@ The following would be a sceleton of an empty filter:
# Alter the path here before it gets recognized.
# Make sure to yield (calls the next around filter if present and
# eventually `recognize_path` on the routeset):
returning yield do |params|
yield.tap do |params|
# You can additionally modify the params here before they get passed
# to the controller.
end
Expand All @@ -32,7 +32,7 @@ The following would be a sceleton of an empty filter:
# Alter arguments here before they are passed to `url_for`.
# Make sure to yield (calls the next around filter if present and
# eventually `url_for` on the controller):
returning yield do |result|
yield.tap do |result|
# You can change the generated url_or_path here. Make sure to use
# one of the "in-place" modifying String methods though (like sub!
# and friends).
Expand Down
4 changes: 2 additions & 2 deletions vendor/plugins/i18n/lib/routing_filter/routing_filter.rb
Expand Up @@ -47,7 +47,7 @@ def generate_optimisation_block_with_filtering(*args)
if match = code.match(%r(^return (.*) if (.*)))
# returned string must not contain newlines, or we'll spill out of inline code comments in
# ActionController::Routing::RouteSet::NamedRouteCollection#define_url_helper
"returning(#{match[1]}) { |result|" +
"#{match[1]}.tap { |result|" +
" ActionController::Routing::Routes.filters.run_reverse(:around_generate, *args, &lambda{ result }) " +
"} if #{match[2]}"
end
Expand Down Expand Up @@ -85,7 +85,7 @@ def generate_with_filtering(*args)
# TODO move this ... where?
alias_method :extract_request_environment_without_host, :extract_request_environment unless method_defined? :extract_request_environment_without_host
def extract_request_environment(request)
returning extract_request_environment_without_host(request) do |env|
extract_request_environment_without_host(request).tap do |env|
env.merge! :host => request.host,
:port => request.port,
:host_with_port => request.host_with_port,
Expand Down
Expand Up @@ -16,7 +16,7 @@ def around_recognize(path, env, &block)
end

def around_generate(*args, &block)
returning yield do |result|
yield.tap do |result|
url = result.is_a?(Array) ? result.first : result
append_extension!(url) if append_extension?(url)
end
Expand Down
Expand Up @@ -4,14 +4,14 @@ module RoutingFilter
class Pagination < Base
def around_recognize(path, env, &block)
page = extract_page!(path)
returning yield(path, env) do |params|
yield.tap(path, env) do |params|
params[:page] = page.to_i if page
end
end

def around_generate(*args, &block)
page = args.extract_options!.delete(:page)
returning yield do |result|
yield.tap do |result|
if page && page != 1
url = result.is_a?(Array) ? result.first : result
append_page!(url, page)
Expand Down
Expand Up @@ -47,7 +47,7 @@ class UuidToken < Base

def around_recognize(path, env, &block)
token = extract_token!(path) # remove the token from the beginning of the path
returning yield do |params| # invoke the given block (calls more filters and finally routing)
yield.tap do |params| # invoke the given block (calls more filters and finally routing)
params[:uuid_token] = token if token # set recognized token to the resulting params hash
end
end
Expand All @@ -56,7 +56,7 @@ def around_generate(*args, &block)
token = args.extract_options!.delete(:uuid_token) # extract the passed :token option
token = AccessToken.current if AccessToken && token.nil? # default to AccessToken.current when token is nil (could also be false)

returning yield do |result|
yield.tap do |result|
if token
url = result.is_a?(Array) ? result.first : result
prepend_token!(url, token)
Expand Down

0 comments on commit 9248a80

Please sign in to comment.