Permalink
Browse files

Use new hash syntax for generators gem method

The Gemfile of new application uses ruby 1.9 hashes. Gem method of
generators should use them too. It prevents from mixing two kinds of
syntax in one file.
  • Loading branch information...
1 parent 0638e6b commit fe7038eac8c1a4df57a0aacf4dd77da5ef87f6df @avakhov avakhov committed May 22, 2012
@@ -27,7 +27,7 @@ def gem(*args)
log :gemfile, message
options.each do |option, value|
- parts << ":#{option} => #{value.inspect}"
+ parts << "#{option}: #{value.inspect}"
end
in_root do
@@ -139,7 +139,7 @@ def gemfile_entry
gemfile_in_app_path = File.join(rails_app_path, "Gemfile")
if File.exist? gemfile_in_app_path
- entry = "gem '#{name}', :path => '#{relative_path}'"
+ entry = "gem '#{name}', path: '#{relative_path}'"
append_file gemfile_in_app_path, entry
end
end
@@ -67,6 +67,14 @@ def test_gem_should_insert_on_separate_lines
assert_file 'Gemfile', /^gem "rspec-rails"$/
end
+ def test_gem_should_include_options
+ run_generator
+
+ action :gem, 'rspec', github: 'dchelimsky/rspec', tag: '1.2.9.rc1'
+
+ assert_file 'Gemfile', /gem "rspec", github: "dchelimsky\/rspec", tag: "1\.2\.9\.rc1"/
+ end
+
def test_gem_group_should_wrap_gems_in_a_group
run_generator
@@ -279,7 +279,7 @@ def test_creating_plugin_in_app_directory_adds_gemfile_entry
run_generator [destination_root]
- assert_file gemfile_path, /gem 'bukkits', :path => 'tmp\/bukkits'/
+ assert_file gemfile_path, /gem 'bukkits', path: 'tmp\/bukkits'/
ensure
Object.send(:remove_const, 'APP_PATH')
FileUtils.rm gemfile_path
@@ -294,7 +294,7 @@ def test_skipping_gemfile_entry
run_generator [destination_root, "--skip-gemfile-entry"]
assert_file gemfile_path do |contents|
- assert_no_match(/gem 'bukkits', :path => 'tmp\/bukkits'/, contents)
+ assert_no_match(/gem 'bukkits', path: 'tmp\/bukkits'/, contents)
end
ensure
Object.send(:remove_const, 'APP_PATH')

10 comments on commit fe7038e

Contributor
iHiD commented on fe7038e May 22, 2012

Are we moving the whole of Rails to the new syntax?

Contributor

@ihid : yup

Member

To be clear, we are not changing rails source code to the new syntax yet (we will do it in steps) , but all generated code will use the new syntax.

Contributor
iHiD replied May 22, 2012

@josevalim Thanks for the reply. What's the logic behind the stepped approach? Just to try and keep consistency throughout files etc? Is it targeted for Rails 4, or just some time in the future?

Member

@ihid generally rails doesn't accept 'cosmetic' patches, and that'd fall under cosmetics.

Contributor
iHiD replied May 22, 2012

@steveklabnik Is that to stop you guys getting a load of extra work in having to validate all the patches (which makes total sense) or is there some other reason? For new code that's written, should we stick to the old syntax for the sake of consistency?

Owner

@ihid it makes it hard to track down the original reason for some code if you have to track back through formatting commits.

Contributor
iHiD replied May 22, 2012

@pixeltrix Makes perfect sense.

Contributor

So, should new code be written with the new hash syntax?

Owner

If it is part of a bugfix no, because this will make harder to backport. If is only a new feature you can use it.

Please sign in to comment.