diff options
Diffstat (limited to 'railties/lib/rails')
13 files changed, 70 insertions, 41 deletions
diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index bf3a26d400..8439d4864d 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -1,5 +1,4 @@ require 'fileutils' -require 'active_support/queueing' # FIXME remove DummyKeyGenerator and this require in 4.1 require 'active_support/key_generator' require 'rails/engine' @@ -68,10 +67,9 @@ module Rails end end - attr_accessor :assets, :sandbox, :queue_consumer + attr_accessor :assets, :sandbox alias_method :sandbox?, :sandbox attr_reader :reloaders - attr_writer :queue delegate :default_url_options, :default_url_options=, to: :routes @@ -83,7 +81,6 @@ module Rails @env_config = nil @ordered_railties = nil @railties = nil - @queue = nil end # Returns true if the application is initialized. @@ -135,8 +132,6 @@ module Rails # * "action_dispatch.encrypted_cookie_salt" => config.action_dispatch.encrypted_cookie_salt # * "action_dispatch.encrypted_signed_cookie_salt" => config.action_dispatch.encrypted_signed_cookie_salt # - # These parameters will be used by middlewares and engines to configure themselves - # def env_config @env_config ||= begin if config.secret_key_base.nil? @@ -228,10 +223,6 @@ module Rails @config ||= Application::Configuration.new(find_root_with_flag("config.ru", Dir.pwd)) end - def queue #:nodoc: - @queue ||= config.queue || ActiveSupport::Queue.new - end - def to_app #:nodoc: self end diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb index f15fc9296d..086fd5ed95 100644 --- a/railties/lib/rails/application/configuration.rb +++ b/railties/lib/rails/application/configuration.rb @@ -1,6 +1,5 @@ require 'active_support/core_ext/kernel/reporting' require 'active_support/file_update_checker' -require 'active_support/queueing' require 'rails/engine/configuration' module Rails @@ -13,7 +12,7 @@ module Rails :railties_order, :relative_url_root, :secret_key_base, :secret_token, :serve_static_assets, :ssl_options, :static_cache_control, :session_options, :time_zone, :reload_classes_only_on_change, - :queue, :queue_consumer, :beginning_of_week, :filter_redirect + :beginning_of_week, :filter_redirect attr_writer :log_level attr_reader :encoding @@ -44,8 +43,6 @@ module Rails @exceptions_app = nil @autoflush_log = true @log_formatter = ActiveSupport::Logger::SimpleFormatter.new - @queue = ActiveSupport::SynchronousQueue.new - @queue_consumer = nil @eager_load = nil @secret_token = nil @secret_key_base = nil diff --git a/railties/lib/rails/application/finisher.rb b/railties/lib/rails/application/finisher.rb index 09902ad597..872d78d9a4 100644 --- a/railties/lib/rails/application/finisher.rb +++ b/railties/lib/rails/application/finisher.rb @@ -96,15 +96,6 @@ module Rails ActiveSupport::Dependencies.unhook! end end - - initializer :activate_queue_consumer do |app| - if config.queue.class == ActiveSupport::Queue - app.queue_consumer = config.queue_consumer || config.queue.consumer - app.queue_consumer.logger ||= Rails.logger if app.queue_consumer.respond_to?(:logger=) - app.queue_consumer.start - at_exit { app.queue_consumer.shutdown } - end - end end end end diff --git a/railties/lib/rails/commands/application.rb b/railties/lib/rails/commands/application.rb index ff0eda3413..2d9708e5b5 100644 --- a/railties/lib/rails/commands/application.rb +++ b/railties/lib/rails/commands/application.rb @@ -14,8 +14,7 @@ else extra_args_string = File.open(railsrc).read extra_args = extra_args_string.split(/\n+/).map {|l| l.split}.flatten puts "Using #{extra_args.join(" ")} from #{railsrc}" - ARGV << extra_args - ARGV.flatten! + ARGV.insert(1, *extra_args) end end diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb index edd1e8cbdf..9b9ae72e18 100644 --- a/railties/lib/rails/generators/app_base.rb +++ b/railties/lib/rails/generators/app_base.rb @@ -261,7 +261,14 @@ module Rails end def run_bundle - bundle_command('install') unless options[:skip_gemfile] || options[:skip_bundle] || options[:pretend] + command = "install --binstubs" + command << " --shebang ruby-local-exec" if detect_ruby_local_exec + + bundle_command(command) unless options[:skip_gemfile] || options[:skip_bundle] || options[:pretend] + end + + def detect_ruby_local_exec + ENV["PATH"].split(":").find { |path| File.file?(File.join(path, "ruby-local-exec")) } end def empty_directory_with_keep_file(destination, config = {}) diff --git a/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt index 593d2acfc7..68df1d1ec8 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +++ b/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt @@ -84,8 +84,4 @@ # Use default logging formatter so that PID and timestamp are not suppressed. config.log_formatter = ::Logger::Formatter.new - - # Default the production mode queue to an synchronous queue. You will probably - # want to replace this with an out-of-process queueing solution. - # config.queue = ActiveSupport::SynchronousQueue.new end diff --git a/railties/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt index a5ef0cd9cd..3c9c787948 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +++ b/railties/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt @@ -33,7 +33,4 @@ # Print deprecation notices to the stderr. config.active_support.deprecation = :stderr - - # Use the synchronous queue to run jobs immediately. - config.queue = ActiveSupport::SynchronousQueue.new end diff --git a/railties/lib/rails/generators/rails/app/templates/gitignore b/railties/lib/rails/generators/rails/app/templates/gitignore index 52abb32479..25a742dff0 100644 --- a/railties/lib/rails/generators/rails/app/templates/gitignore +++ b/railties/lib/rails/generators/rails/app/templates/gitignore @@ -4,7 +4,7 @@ # or operating system, you probably want to add a global ignore instead: # git config --global core.excludesfile '~/.gitignore_global' -# Ignore bundler config +# Ignore bundler config. /.bundle # Ignore the default SQLite database. diff --git a/railties/lib/rails/generators/rails/scaffold/scaffold_generator.rb b/railties/lib/rails/generators/rails/scaffold/scaffold_generator.rb index 60d202c5ef..dd636ed3cf 100644 --- a/railties/lib/rails/generators/rails/scaffold/scaffold_generator.rb +++ b/railties/lib/rails/generators/rails/scaffold/scaffold_generator.rb @@ -9,6 +9,15 @@ module Rails class_option :stylesheets, type: :boolean, desc: "Generate Stylesheets" class_option :stylesheet_engine, desc: "Engine for Stylesheets" + class_option :html, type: :boolean, default: true, + desc: "Generate a scaffold with HTML output" + + def handle_skip + if !options[:html] || !options[:stylesheets] + @options = @options.merge(stylesheet_engine: false) + end + end + hook_for :scaffold_controller, required: true hook_for :assets do |assets| @@ -16,7 +25,9 @@ module Rails end hook_for :stylesheet_engine do |stylesheet_engine| - invoke stylesheet_engine, [controller_name] if options[:stylesheets] && behavior == :invoke + if behavior == :invoke + invoke stylesheet_engine, [controller_name] + end end end end diff --git a/railties/lib/rails/generators/rails/scaffold_controller/scaffold_controller_generator.rb b/railties/lib/rails/generators/rails/scaffold_controller/scaffold_controller_generator.rb index 4f36b612ae..32fa54a362 100644 --- a/railties/lib/rails/generators/rails/scaffold_controller/scaffold_controller_generator.rb +++ b/railties/lib/rails/generators/rails/scaffold_controller/scaffold_controller_generator.rb @@ -10,8 +10,17 @@ module Rails class_option :orm, banner: "NAME", type: :string, required: true, desc: "ORM to generate the controller for" + class_option :html, type: :boolean, default: true, + desc: "Generate a scaffold with HTML output" + argument :attributes, type: :array, default: [], banner: "field:type field:type" + def handle_skip + unless options[:html] + @options = @options.merge(template_engine: false, helper: false) + end + end + def create_controller_files template "controller.rb", File.join('app/controllers', class_path, "#{controller_file_name}_controller.rb") end diff --git a/railties/lib/rails/generators/rails/scaffold_controller/templates/controller.rb b/railties/lib/rails/generators/rails/scaffold_controller/templates/controller.rb index 4d08b01e60..4baad85e9e 100644 --- a/railties/lib/rails/generators/rails/scaffold_controller/templates/controller.rb +++ b/railties/lib/rails/generators/rails/scaffold_controller/templates/controller.rb @@ -12,7 +12,9 @@ class <%= controller_class_name %>Controller < ApplicationController @<%= plural_table_name %> = <%= orm_class.all(class_name) %> respond_to do |format| + <%- if options[:html] -%> format.html # index.html.erb + <%- end -%> format.json { render json: <%= "@#{plural_table_name}" %> } end end @@ -21,11 +23,14 @@ class <%= controller_class_name %>Controller < ApplicationController # GET <%= route_url %>/1.json def show respond_to do |format| + <%- if options[:html] -%> format.html # show.html.erb + <%- end -%> format.json { render json: <%= "@#{singular_table_name}" %> } end end + <%- if options[:html] -%> # GET <%= route_url %>/new # GET <%= route_url %>/new.json def new @@ -40,6 +45,7 @@ class <%= controller_class_name %>Controller < ApplicationController # GET <%= route_url %>/1/edit def edit end + <%- end -%> # POST <%= route_url %> # POST <%= route_url %>.json @@ -48,10 +54,14 @@ class <%= controller_class_name %>Controller < ApplicationController respond_to do |format| if @<%= orm_instance.save %> + <%- if options[:html] -%> format.html { redirect_to @<%= singular_table_name %>, notice: <%= "'#{human_name} was successfully created.'" %> } + <%- end -%> format.json { render json: <%= "@#{singular_table_name}" %>, status: :created, location: <%= "@#{singular_table_name}" %> } else + <%- if options[:html] -%> format.html { render action: "new" } + <%- end -%> format.json { render json: <%= "@#{orm_instance.errors}" %>, status: :unprocessable_entity } end end @@ -62,10 +72,14 @@ class <%= controller_class_name %>Controller < ApplicationController def update respond_to do |format| if @<%= orm_instance.update_attributes("#{singular_table_name}_params") %> + <%- if options[:html] -%> format.html { redirect_to @<%= singular_table_name %>, notice: <%= "'#{human_name} was successfully updated.'" %> } + <%- end -%> format.json { head :no_content } else + <%- if options[:html] -%> format.html { render action: "edit" } + <%- end -%> format.json { render json: <%= "@#{orm_instance.errors}" %>, status: :unprocessable_entity } end end @@ -77,7 +91,9 @@ class <%= controller_class_name %>Controller < ApplicationController @<%= orm_instance.destroy %> respond_to do |format| + <%- if options[:html] -%> format.html { redirect_to <%= index_helper %>_url } + <%- end -%> format.json { head :no_content } end end @@ -88,8 +104,11 @@ class <%= controller_class_name %>Controller < ApplicationController @<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %> end - # Use this method to whitelist the permissible parameters. Example: params.require(:person).permit(:name, :age) - # Also, you can specialize this method with per-user checking of permissible attributes. + # Use this method to whitelist the permissible parameters. Example: + # params.require(:person).permit(:name, :age) + # + # Also, you can specialize this method with per-user checking of permissible + # attributes. def <%= "#{singular_table_name}_params" %> <%- if attributes_names.empty? -%> params[<%= ":#{singular_table_name}" %>] diff --git a/railties/lib/rails/generators/test_unit/model/model_generator.rb b/railties/lib/rails/generators/test_unit/model/model_generator.rb index 2801749ffe..2826a3ffa1 100644 --- a/railties/lib/rails/generators/test_unit/model/model_generator.rb +++ b/railties/lib/rails/generators/test_unit/model/model_generator.rb @@ -3,6 +3,9 @@ require 'rails/generators/test_unit' module TestUnit # :nodoc: module Generators # :nodoc: class ModelGenerator < Base # :nodoc: + + RESERVED_YAML_KEYWORDS = %w(y yes n no true false on off null) + argument :attributes, type: :array, default: [], banner: "field:type field:type" class_option :fixture, type: :boolean @@ -19,6 +22,15 @@ module TestUnit # :nodoc: template 'fixtures.yml', File.join('test/fixtures', class_path, "#{plural_file_name}.yml") end end + + private + def yaml_key_value(key, value) + if RESERVED_YAML_KEYWORDS.include?(key.downcase) + "'#{key}': #{value}" + else + "#{key}: #{value}" + end + end end end end diff --git a/railties/lib/rails/generators/test_unit/model/templates/fixtures.yml b/railties/lib/rails/generators/test_unit/model/templates/fixtures.yml index 7625ff975c..c9d505c84a 100644 --- a/railties/lib/rails/generators/test_unit/model/templates/fixtures.yml +++ b/railties/lib/rails/generators/test_unit/model/templates/fixtures.yml @@ -3,17 +3,17 @@ <% unless attributes.empty? -%> one: <% attributes.each do |attribute| -%> - <%= attribute.column_name %>: <%= attribute.default %> + <%= yaml_key_value(attribute.column_name, attribute.default) %> <%- if attribute.polymorphic? -%> - <%= "#{attribute.name}_type: #{attribute.human_name}" %> + <%= yaml_key_value("#{attribute.name}_type", attribute.human_name) %> <%- end -%> <% end -%> two: <% attributes.each do |attribute| -%> - <%= attribute.column_name %>: <%= attribute.default %> + <%= yaml_key_value(attribute.column_name, attribute.default) %> <%- if attribute.polymorphic? -%> - <%= "#{attribute.name}_type: #{attribute.human_name}" %> + <%= yaml_key_value("#{attribute.name}_type", attribute.human_name) %> <%- end -%> <% end -%> <% else -%> |