aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib
diff options
context:
space:
mode:
authoralexbel <alexbel@lavabit.com>2014-05-26 00:50:11 -0400
committeralexbel <alexbel@lavabit.com>2014-05-26 19:08:03 -0400
commit6aaf4bff188d498928bc936ef8d47c32bce03e9c (patch)
tree198b8c011104063a1a8e9e8222fe95eb6ac85ca9 /railties/lib
parent9a6ed049144de5b91b521b79c373f7cd90cc430c (diff)
downloadrails-6aaf4bff188d498928bc936ef8d47c32bce03e9c.tar.gz
rails-6aaf4bff188d498928bc936ef8d47c32bce03e9c.tar.bz2
rails-6aaf4bff188d498928bc936ef8d47c32bce03e9c.zip
Replace double quotes with single quotes while adding an entry into Gemfile
Diffstat (limited to 'railties/lib')
-rw-r--r--railties/lib/rails/generators/actions.rb18
1 files changed, 14 insertions, 4 deletions
diff --git a/railties/lib/rails/generators/actions.rb b/railties/lib/rails/generators/actions.rb
index 625f031c94..abcbe7068d 100644
--- a/railties/lib/rails/generators/actions.rb
+++ b/railties/lib/rails/generators/actions.rb
@@ -20,9 +20,9 @@ module Rails
# Set the message to be shown in logs. Uses the git repo if one is given,
# otherwise use name (version).
- parts, message = [ name.inspect ], name
+ parts, message = [ quote(name) ], name
if version ||= options.delete(:version)
- parts << version.inspect
+ parts << quote(version)
message << " (#{version})"
end
message = options[:git] if options[:git]
@@ -30,7 +30,7 @@ module Rails
log :gemfile, message
options.each do |option, value|
- parts << "#{option}: #{value.inspect}"
+ parts << "#{option}: #{quote(value)}"
end
in_root do
@@ -68,7 +68,7 @@ module Rails
log :source, source
in_root do
- prepend_file "Gemfile", "source #{source.inspect}\n", verbose: false
+ prepend_file "Gemfile", "source #{quote(source)}\n", verbose: false
end
end
@@ -255,6 +255,16 @@ module Rails
end
end
+ # Surround string with single quotes if there is no quotes.
+ # Otherwise fall back to double quotes
+ def quote(str)
+ if str.class == String && str.scan("'").size > 0
+ str.inspect
+ else
+ "'#{str}'"
+ end
+ end
+
end
end
end