Permalink
Browse files

Use Ruby 1.9 Hash syntax in railties

  • Loading branch information...
robin850 committed Oct 14, 2012
1 parent ca618d4 commit 5ad7f8ab418f0c760dbb584f7c78d94ce32e9ee3
Showing with 447 additions and 447 deletions.
  1. +1 −1 railties/lib/rails.rb
  2. +5 −5 railties/lib/rails/application.rb
  3. +7 −7 railties/lib/rails/application/bootstrap.rb
  4. +3 −3 railties/lib/rails/application/configuration.rb
  5. +2 −2 railties/lib/rails/application/finisher.rb
  6. +1 −1 railties/lib/rails/application/routes_reloader.rb
  7. +1 −1 railties/lib/rails/commands/destroy.rb
  8. +1 −1 railties/lib/rails/commands/generate.rb
  9. +1 −1 railties/lib/rails/commands/runner.rb
  10. +7 −7 railties/lib/rails/commands/server.rb
  11. +1 −1 railties/lib/rails/commands/update.rb
  12. +8 −8 railties/lib/rails/engine.rb
  13. +15 −15 railties/lib/rails/engine/configuration.rb
  14. +29 −29 railties/lib/rails/generators.rb
  15. +22 −22 railties/lib/rails/generators/actions.rb
  16. +8 −8 railties/lib/rails/generators/base.rb
  17. +1 −1 railties/lib/rails/generators/erb/controller/controller_generator.rb
  18. +1 −1 railties/lib/rails/generators/erb/scaffold/scaffold_generator.rb
  19. +4 −4 railties/lib/rails/generators/generated_attribute.rb
  20. +4 −4 railties/lib/rails/generators/named_base.rb
  21. +4 −4 railties/lib/rails/generators/rails/app/app_generator.rb
  22. +4 −4 railties/lib/rails/generators/rails/assets/assets_generator.rb
  23. +2 −2 railties/lib/rails/generators/rails/controller/controller_generator.rb
  24. +3 −3 railties/lib/rails/generators/rails/generator/generator_generator.rb
  25. +1 −1 railties/lib/rails/generators/rails/helper/helper_generator.rb
  26. +1 −1 railties/lib/rails/generators/rails/integration_test/integration_test_generator.rb
  27. +2 −2 railties/lib/rails/generators/rails/migration/migration_generator.rb
  28. +2 −2 railties/lib/rails/generators/rails/model/model_generator.rb
  29. +1 −1 railties/lib/rails/generators/rails/observer/observer_generator.rb
  30. +1 −1 railties/lib/rails/generators/rails/performance_test/performance_test_generator.rb
  31. +16 −16 railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb
  32. +1 −1 .../lib/rails/generators/rails/plugin_new/templates/app/views/layouts/%name%/application.html.erb.tt
  33. +4 −4 railties/lib/rails/generators/rails/resource/resource_generator.rb
  34. +3 −3 railties/lib/rails/generators/rails/scaffold/scaffold_generator.rb
  35. +6 −6 railties/lib/rails/generators/rails/scaffold_controller/scaffold_controller_generator.rb
  36. +1 −1 railties/lib/rails/generators/rails/task/task_generator.rb
  37. +1 −1 railties/lib/rails/generators/rails/task/templates/task.rb
  38. +1 −1 railties/lib/rails/generators/resource_helpers.rb
  39. +2 −2 railties/lib/rails/generators/test_case.rb
  40. +2 −2 railties/lib/rails/generators/test_unit/controller/controller_generator.rb
  41. +1 −1 railties/lib/rails/generators/test_unit/helper/helper_generator.rb
  42. +1 −1 railties/lib/rails/generators/test_unit/integration/integration_generator.rb
  43. +2 −2 railties/lib/rails/generators/test_unit/mailer/mailer_generator.rb
  44. +3 −3 railties/lib/rails/generators/test_unit/model/model_generator.rb
  45. +1 −1 railties/lib/rails/generators/test_unit/observer/observer_generator.rb
  46. +1 −1 railties/lib/rails/generators/test_unit/performance/performance_generator.rb
  47. +2 −2 railties/lib/rails/generators/test_unit/performance/templates/performance_test.rb
  48. +1 −1 railties/lib/rails/generators/test_unit/plugin/plugin_generator.rb
  49. +2 −2 railties/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb
  50. +1 −1 railties/lib/rails/info_controller.rb
  51. +3 −3 railties/lib/rails/paths.rb
  52. +1 −1 railties/lib/rails/railtie.rb
  53. +1 −1 railties/lib/rails/railtie/configurable.rb
  54. +4 −4 railties/lib/rails/railtie/configuration.rb
  55. +1 −1 railties/lib/rails/tasks/annotations.rake
  56. +5 −5 railties/lib/rails/tasks/framework.rake
  57. +1 −1 railties/lib/rails/tasks/middleware.rake
  58. +2 −2 railties/lib/rails/tasks/misc.rake
  59. +1 −1 railties/lib/rails/tasks/routes.rake
  60. +2 −2 railties/lib/rails/tasks/tmp.rake
  61. +2 −2 railties/lib/rails/test_unit/railtie.rb
  62. +14 −14 railties/lib/rails/test_unit/testing.rake
  63. +2 −2 railties/test/application/asset_debugging_test.rb
  64. +3 −3 railties/test/application/assets_test.rb
  65. +15 −15 railties/test/application/configuration_test.rb
  66. +15 −15 railties/test/application/generators_test.rb
  67. +7 −7 railties/test/application/initializers/i18n_test.rb
  68. +1 −1 railties/test/application/initializers/notifications_test.rb
  69. +14 −14 railties/test/application/loading_test.rb
  70. +12 −12 railties/test/application/middleware/cache_test.rb
  71. +1 −1 railties/test/application/middleware/session_test.rb
  72. +4 −4 railties/test/application/middleware_test.rb
  73. +5 −5 railties/test/application/rake_test.rb
  74. +14 −14 railties/test/application/routing_test.rb
  75. +3 −3 railties/test/application/url_generation_test.rb
  76. +4 −4 railties/test/commands/console_test.rb
  77. +1 −1 railties/test/fixtures/lib/plugin_builders/spec_builder.rb
  78. +18 −18 railties/test/generators/actions_test.rb
  79. +3 −3 railties/test/generators/app_generator_test.rb
  80. +3 −3 railties/test/generators/model_generator_test.rb
  81. +3 −3 railties/test/generators/namespaced_generators_test.rb
  82. +2 −2 railties/test/generators/orm_test.rb
  83. +1 −1 railties/test/generators/plugin_new_generator_test.rb
  84. +1 −1 railties/test/generators/resource_generator_test.rb
  85. +1 −1 railties/test/generators/scaffold_generator_test.rb
  86. +7 −7 railties/test/generators/shared_generator_tests.rb
  87. +4 −4 railties/test/generators_test.rb
  88. +9 −9 railties/test/initializable_test.rb
  89. +4 −4 railties/test/isolation/abstract_unit.rb
  90. +14 −14 railties/test/paths_test.rb
  91. +3 −3 railties/test/rails_info_controller_test.rb
  92. +21 −21 railties/test/railties/engine_test.rb
  93. +1 −1 railties/test/railties/generators_test.rb
  94. +19 −19 railties/test/railties/mounted_engine_test.rb
View
@@ -106,7 +106,7 @@ def cache=(cache)
# * The environment variable RAILS_GROUPS;
# * The optional envs given as argument and the hash with group dependencies;
#
- # groups :assets => [:development, :test]
+ # groups assets: [:development, :test]
#
# # Returns
# # => [:default, :development, :assets] for Rails.env == "development"
@@ -71,7 +71,7 @@ def inherited(base)
attr_reader :reloaders
attr_writer :queue
- delegate :default_url_options, :default_url_options=, :to => :routes
+ delegate :default_url_options, :default_url_options=, to: :routes
def initialize
super
@@ -106,7 +106,7 @@ def reload_routes!
def key_generator
# number of iterations selected based on consultation with the google security
# team. Details at https://github.com/rails/rails/pull/6952#issuecomment-7661220
- @key_generator ||= ActiveSupport::KeyGenerator.new(config.secret_token, :iterations=>1000)
+ @key_generator ||= ActiveSupport::KeyGenerator.new(config.secret_token, iterations: 1000)
end
# Stores some of the Rails initial environment parameters which
@@ -296,9 +296,9 @@ def default_middleware_stack #:nodoc:
if rack_cache == true
rack_cache = {
- :metastore => "rails:/",
- :entitystore => "rails:/",
- :verbose => false
+ metastore: "rails:/",
+ entitystore: "rails:/",
+ verbose: false
}
end
@@ -7,13 +7,13 @@ class Application
module Bootstrap
include Initializable
- initializer :load_environment_hook, :group => :all do end
+ initializer :load_environment_hook, group: :all do end
- initializer :load_active_support, :group => :all do
+ initializer :load_active_support, group: :all do
require "active_support/all" unless config.active_support.bare
end
- initializer :set_eager_load, :group => :all do
+ initializer :set_eager_load, group: :all do
if config.eager_load.nil?
warn <<-INFO
config.eager_load is set to nil. Please update your config/environments/*.rb files accordingly:
@@ -28,7 +28,7 @@ module Bootstrap
end
# Initialize the logger early in the stack in case we need to log some deprecation.
- initializer :initialize_logger, :group => :all do
+ initializer :initialize_logger, group: :all do
Rails.logger ||= config.logger || begin
path = config.paths["log"].first
unless File.exist? File.dirname path
@@ -56,7 +56,7 @@ module Bootstrap
end
# Initialize cache early in the stack so railties can make use of it.
- initializer :initialize_cache, :group => :all do
+ initializer :initialize_cache, group: :all do
unless Rails.cache
Rails.cache = ActiveSupport::Cache.lookup_store(config.cache_store)
@@ -67,11 +67,11 @@ module Bootstrap
end
# Sets the dependency loading mechanism.
- initializer :initialize_dependency_mechanism, :group => :all do
+ initializer :initialize_dependency_mechanism, group: :all do
ActiveSupport::Dependencies.mechanism = config.cache_classes ? :require : :load
end
- initializer :bootstrap_hook, :group => :all do |app|
+ initializer :bootstrap_hook, group: :all do |app|
ActiveSupport.run_load_hooks(:before_initialize, app)
end
end
@@ -79,10 +79,10 @@ def encoding=(value)
def paths
@paths ||= begin
paths = super
- paths.add "config/database", :with => "config/database.yml"
- paths.add "config/environment", :with => "config/environment.rb"
+ paths.add "config/database", with: "config/database.yml"
+ paths.add "config/environment", with: "config/environment.rb"
paths.add "lib/templates"
- paths.add "log", :with => "log/#{Rails.env}.log"
+ paths.add "log", with: "log/#{Rails.env}.log"
paths.add "public"
paths.add "public/javascripts"
paths.add "public/stylesheets"
@@ -72,7 +72,7 @@ module Finisher
# Set app reload just after the finisher hook to ensure
# paths added in the hook are still loaded.
- initializer :set_clear_dependencies_hook, :group => :all do
+ initializer :set_clear_dependencies_hook, group: :all do
callback = lambda do
ActiveSupport::DescendantsTracker.clear
ActiveSupport::Dependencies.clear
@@ -83,7 +83,7 @@ module Finisher
self.reloaders << reloader
# We need to set a to_prepare callback regardless of the reloader result, i.e.
# models should be reloaded if any of the reloaders (i18n, routes) were updated.
- ActionDispatch::Reloader.to_prepare(:prepend => true){ reloader.execute }
+ ActionDispatch::Reloader.to_prepare(prepend: true){ reloader.execute }
else
ActionDispatch::Reloader.to_cleanup(&callback)
end
@@ -4,7 +4,7 @@ module Rails
class Application
class RoutesReloader
attr_reader :route_sets, :paths
- delegate :execute_if_updated, :execute, :updated?, :to => :updater
+ delegate :execute_if_updated, :execute, :updated?, to: :updater
def initialize
@paths = []
@@ -6,4 +6,4 @@
end
name = ARGV.shift
-Rails::Generators.invoke name, ARGV, :behavior => :revoke, :destination_root => Rails.root
+Rails::Generators.invoke name, ARGV, behavior: :revoke, destination_root: Rails.root
@@ -8,4 +8,4 @@
name = ARGV.shift
root = defined?(ENGINE_ROOT) ? ENGINE_ROOT : Rails.root
-Rails::Generators.invoke name, ARGV, :behavior => :invoke, :destination_root => root
+Rails::Generators.invoke name, ARGV, behavior: :invoke, destination_root: root
@@ -1,7 +1,7 @@
require 'optparse'
require 'rbconfig'
-options = { :environment => (ENV['RAILS_ENV'] || "development").dup }
+options = { environment: (ENV['RAILS_ENV'] || "development").dup }
code_or_file = nil
if ARGV.first.nil?
@@ -105,13 +105,13 @@ def log_path
def default_options
super.merge({
- :Port => 3000,
- :DoNotReverseLookup => true,
- :environment => (ENV['RAILS_ENV'] || "development").dup,
- :daemonize => false,
- :debugger => false,
- :pid => File.expand_path("tmp/pids/server.pid"),
- :config => File.expand_path("config.ru")
+ Port: 3000,
+ DoNotReverseLookup: true,
+ environment: (ENV['RAILS_ENV'] || "development").dup,
+ daemonize: false,
+ debugger: false,
+ pid: File.expand_path("tmp/pids/server.pid"),
+ config: File.expand_path("config.ru")
})
end
end
@@ -6,4 +6,4 @@
end
name = ARGV.shift
-Rails::Generators.invoke name, ARGV, :behavior => :skip
+Rails::Generators.invoke name, ARGV, behavior: :skip
@@ -251,7 +251,7 @@ module Rails
#
# # config/routes.rb
# MyApplication::Application.routes.draw do
- # mount MyEngine::Engine => "/my_engine", :as => "my_engine"
+ # mount MyEngine::Engine => "/my_engine", as: "my_engine"
# get "/foo" => "foo#index"
# end
#
@@ -368,7 +368,7 @@ def endpoint(endpoint = nil)
def isolate_namespace(mod)
engine_name(generate_railtie_name(mod))
- self.routes.default_scope = { :module => ActiveSupport::Inflector.underscore(mod.name) }
+ self.routes.default_scope = { module: ActiveSupport::Inflector.underscore(mod.name) }
self.isolated = true
unless mod.respond_to?(:railtie_namespace)
@@ -407,8 +407,8 @@ def find(path)
end
end
- delegate :middleware, :root, :paths, :to => :config
- delegate :engine_name, :isolated?, :to => "self.class"
+ delegate :middleware, :root, :paths, to: :config
+ delegate :engine_name, :isolated?, to: "self.class"
def initialize
@_all_autoload_paths = nil
@@ -536,7 +536,7 @@ def load_seed
end
# Add configured load paths to ruby load paths and remove duplicates.
- initializer :set_load_path, :before => :bootstrap_hook do
+ initializer :set_load_path, before: :bootstrap_hook do
_all_load_paths.reverse_each do |path|
$LOAD_PATH.unshift(path) if File.directory?(path)
end
@@ -548,7 +548,7 @@ def load_seed
#
# This needs to be an initializer, since it needs to run once
# per engine and get the engine as a block parameter
- initializer :set_autoload_paths, :before => :bootstrap_hook do |app|
+ initializer :set_autoload_paths, before: :bootstrap_hook do |app|
ActiveSupport::Dependencies.autoload_paths.unshift(*_all_autoload_paths)
ActiveSupport::Dependencies.autoload_once_paths.unshift(*_all_autoload_once_paths)
@@ -581,13 +581,13 @@ def load_seed
end
end
- initializer :load_environment_config, :before => :load_environment_hook, :group => :all do
+ initializer :load_environment_config, before: :load_environment_hook, group: :all do
paths["config/environments"].existent.each do |environment|
require environment
end
end
- initializer :append_assets_path, :group => :all do |app|
+ initializer :append_assets_path, group: :all do |app|
app.config.assets.paths.unshift(*paths["vendor/assets"].existent_directories)
app.config.assets.paths.unshift(*paths["lib/assets"].existent_directories)
app.config.assets.paths.unshift(*paths["app/assets"].existent_directories)
@@ -20,7 +20,7 @@ def middleware
# Holds generators configuration:
#
# config.generators do |g|
- # g.orm :data_mapper, :migration => true
+ # g.orm :data_mapper, migration: true
# g.template_engine :haml
# g.test_framework :rspec
# end
@@ -38,26 +38,26 @@ def generators #:nodoc:
def paths
@paths ||= begin
paths = Rails::Paths::Root.new(@root)
- paths.add "app", :eager_load => true, :glob => "*"
- paths.add "app/assets", :glob => "*"
- paths.add "app/controllers", :eager_load => true
- paths.add "app/helpers", :eager_load => true
- paths.add "app/models", :eager_load => true
- paths.add "app/mailers", :eager_load => true
+ paths.add "app", eager_load: true, glob: "*"
+ paths.add "app/assets", glob: "*"
+ paths.add "app/controllers", eager_load: true
+ paths.add "app/helpers", eager_load: true
+ paths.add "app/models", eager_load: true
+ paths.add "app/mailers", eager_load: true
paths.add "app/views"
- paths.add "lib", :load_path => true
- paths.add "lib/assets", :glob => "*"
- paths.add "lib/tasks", :glob => "**/*.rake"
+ paths.add "lib", load_path: true
+ paths.add "lib/assets", glob: "*"
+ paths.add "lib/tasks", glob: "**/*.rake"
paths.add "config"
- paths.add "config/environments", :glob => "#{Rails.env}.rb"
- paths.add "config/initializers", :glob => "**/*.rb"
- paths.add "config/locales", :glob => "*.{rb,yml}"
+ paths.add "config/environments", glob: "#{Rails.env}.rb"
+ paths.add "config/initializers", glob: "**/*.rb"
+ paths.add "config/locales", glob: "*.{rb,yml}"
paths.add "config/routes.rb"
paths.add "db"
paths.add "db/migrate"
paths.add "db/seeds.rb"
- paths.add "vendor", :load_path => true
- paths.add "vendor/assets", :glob => "*"
+ paths.add "vendor", load_path: true
+ paths.add "vendor/assets", glob: "*"
paths
end
end
@@ -23,41 +23,41 @@ module Generators
mattr_accessor :namespace
DEFAULT_ALIASES = {
- :rails => {
- :actions => '-a',
- :orm => '-o',
- :javascripts => '-j',
- :javascript_engine => '-je',
- :resource_controller => '-c',
- :scaffold_controller => '-c',
- :stylesheets => '-y',
- :stylesheet_engine => '-se',
- :template_engine => '-e',
- :test_framework => '-t'
+ rails: {
+ actions: '-a',
+ orm: '-o',
+ javascripts: '-j',
+ javascript_engine: '-je',
+ resource_controller: '-c',
+ scaffold_controller: '-c',
+ stylesheets: '-y',
+ stylesheet_engine: '-se',
+ template_engine: '-e',
+ test_framework: '-t'
},
- :test_unit => {
- :fixture_replacement => '-r',
+ test_unit: {
+ fixture_replacement: '-r',
}
}
DEFAULT_OPTIONS = {
- :rails => {
- :assets => true,
- :force_plural => false,
- :helper => true,
- :integration_tool => nil,
- :javascripts => true,
- :javascript_engine => :js,
- :orm => false,
- :performance_tool => nil,
- :resource_controller => :controller,
- :resource_route => true,
- :scaffold_controller => :scaffold_controller,
- :stylesheets => true,
- :stylesheet_engine => :css,
- :test_framework => false,
- :template_engine => :erb
+ rails: {
+ assets: true,
+ force_plural: false,
+ helper: true,
+ integration_tool: nil,
+ javascripts: true,
+ javascript_engine: :js,
+ orm: false,
+ performance_tool: nil,
+ resource_controller: :controller,
+ resource_route: true,
+ scaffold_controller: :scaffold_controller,
+ stylesheets: true,
+ stylesheet_engine: :css,
+ test_framework: false,
+ template_engine: :erb
}
}
Oops, something went wrong.

4 comments on commit 5ad7f8a

@claudiob

This comment has been minimized.

Show comment Hide comment
@claudiob

claudiob Oct 15, 2012

Member

I was just wondering if this change should be limited to Railties, or if it can be applied to the whole Rails codebase.
In other words, would this kind of commit be accepted today? #4691 (comment)

Member

claudiob replied Oct 15, 2012

I was just wondering if this change should be limited to Railties, or if it can be applied to the whole Rails codebase.
In other words, would this kind of commit be accepted today? #4691 (comment)

@rafaelfranca

This comment has been minimized.

Show comment Hide comment
@rafaelfranca

rafaelfranca Oct 15, 2012

Owner

No, and the reason is still the same. We applied only to Action Mailer and Railties because the number of open pull requests is very low. But we don't want to do the same with Active Record and Action Pack

Owner

rafaelfranca replied Oct 15, 2012

No, and the reason is still the same. We applied only to Action Mailer and Railties because the number of open pull requests is very low. But we don't want to do the same with Active Record and Action Pack

@claudiob

This comment has been minimized.

Show comment Hide comment
@claudiob

claudiob Oct 15, 2012

Member

Fair enough

Member

claudiob replied Oct 15, 2012

Fair enough

@miclovich

This comment has been minimized.

Show comment Hide comment
@miclovich

miclovich Oct 19, 2012

awesome stuff... :-)

awesome stuff... :-)

Please sign in to comment.