diff options
author | Emilio Tagua <miloops@gmail.com> | 2009-09-01 15:45:43 -0300 |
---|---|---|
committer | Emilio Tagua <miloops@gmail.com> | 2009-09-01 15:45:43 -0300 |
commit | 39e4e76d15233bb1cb0b778d920f54efe86bb4f0 (patch) | |
tree | 7e9cab343139c79acc36715f4f24c579a207fbc6 /railties/lib | |
parent | 6b67df70ab1bc42d9a05571144cdf5614a7d4a6a (diff) | |
parent | da636809daca9c338200811d3590e446f57c8e81 (diff) | |
download | rails-39e4e76d15233bb1cb0b778d920f54efe86bb4f0.tar.gz rails-39e4e76d15233bb1cb0b778d920f54efe86bb4f0.tar.bz2 rails-39e4e76d15233bb1cb0b778d920f54efe86bb4f0.zip |
Merge commit 'rails/master'
Conflicts:
activerecord/lib/active_record/associations.rb
Diffstat (limited to 'railties/lib')
-rw-r--r-- | railties/lib/generators.rb | 3 | ||||
-rw-r--r-- | railties/lib/generators/actions.rb | 12 | ||||
-rw-r--r-- | railties/lib/generators/base.rb | 52 | ||||
-rw-r--r-- | railties/lib/generators/erb/scaffold/scaffold_generator.rb | 5 | ||||
-rw-r--r-- | railties/lib/generators/erb/scaffold/templates/_form.html.erb | 17 | ||||
-rw-r--r-- | railties/lib/generators/erb/scaffold/templates/edit.html.erb | 16 | ||||
-rw-r--r-- | railties/lib/generators/erb/scaffold/templates/layout.html.erb | 2 | ||||
-rw-r--r-- | railties/lib/generators/erb/scaffold/templates/new.html.erb | 16 | ||||
-rw-r--r-- | railties/lib/generators/named_base.rb | 62 | ||||
-rw-r--r-- | railties/lib/generators/rails/generator/generator_generator.rb | 2 | ||||
-rw-r--r-- | railties/lib/generators/rails/resource/resource_generator.rb | 16 | ||||
-rw-r--r-- | railties/lib/generators/rails/scaffold/scaffold_generator.rb | 3 | ||||
-rw-r--r-- | railties/lib/generators/rails/scaffold_controller/scaffold_controller_generator.rb | 5 | ||||
-rw-r--r-- | railties/lib/generators/rails/stylesheets/templates/scaffold.css | 8 | ||||
-rw-r--r-- | railties/lib/generators/resource_helpers.rb | 74 | ||||
-rw-r--r-- | railties/lib/generators/test_unit/scaffold/scaffold_generator.rb | 3 | ||||
-rw-r--r-- | railties/lib/rails/configuration.rb | 1 | ||||
-rw-r--r-- | railties/lib/rails/plugin.rb | 12 | ||||
-rw-r--r-- | railties/lib/rails/plugin/loader.rb | 9 | ||||
-rw-r--r-- | railties/lib/tasks/databases.rake | 2 | ||||
-rw-r--r-- | railties/lib/vendor/thor-0.11.6/CHANGELOG.rdoc (renamed from railties/lib/vendor/thor-0.11.5/CHANGELOG.rdoc) | 0 | ||||
-rw-r--r-- | railties/lib/vendor/thor-0.11.6/LICENSE (renamed from railties/lib/vendor/thor-0.11.5/LICENSE) | 0 | ||||
-rw-r--r-- | railties/lib/vendor/thor-0.11.6/README.rdoc (renamed from railties/lib/vendor/thor-0.11.5/README.rdoc) | 0 | ||||
-rwxr-xr-x | railties/lib/vendor/thor-0.11.6/bin/rake2thor (renamed from railties/lib/vendor/thor-0.11.5/bin/rake2thor) | 0 | ||||
-rwxr-xr-x | railties/lib/vendor/thor-0.11.6/bin/thor (renamed from railties/lib/vendor/thor-0.11.5/bin/thor) | 0 | ||||
-rw-r--r-- | railties/lib/vendor/thor-0.11.6/lib/thor.rb (renamed from railties/lib/vendor/thor-0.11.5/lib/thor.rb) | 2 | ||||
-rw-r--r-- | railties/lib/vendor/thor-0.11.6/lib/thor/actions.rb (renamed from railties/lib/vendor/thor-0.11.5/lib/thor/actions.rb) | 31 | ||||
-rw-r--r-- | railties/lib/vendor/thor-0.11.6/lib/thor/actions/create_file.rb (renamed from railties/lib/vendor/thor-0.11.5/lib/thor/actions/create_file.rb) | 0 | ||||
-rw-r--r-- | railties/lib/vendor/thor-0.11.6/lib/thor/actions/directory.rb (renamed from railties/lib/vendor/thor-0.11.5/lib/thor/actions/directory.rb) | 0 | ||||
-rw-r--r-- | railties/lib/vendor/thor-0.11.6/lib/thor/actions/empty_directory.rb (renamed from railties/lib/vendor/thor-0.11.5/lib/thor/actions/empty_directory.rb) | 0 | ||||
-rw-r--r-- | railties/lib/vendor/thor-0.11.6/lib/thor/actions/file_manipulation.rb (renamed from railties/lib/vendor/thor-0.11.5/lib/thor/actions/file_manipulation.rb) | 58 | ||||
-rw-r--r-- | railties/lib/vendor/thor-0.11.6/lib/thor/actions/inject_into_file.rb (renamed from railties/lib/vendor/thor-0.11.5/lib/thor/actions/inject_into_file.rb) | 63 | ||||
-rw-r--r-- | railties/lib/vendor/thor-0.11.6/lib/thor/base.rb (renamed from railties/lib/vendor/thor-0.11.5/lib/thor/base.rb) | 7 | ||||
-rw-r--r-- | railties/lib/vendor/thor-0.11.6/lib/thor/core_ext/hash_with_indifferent_access.rb (renamed from railties/lib/vendor/thor-0.11.5/lib/thor/core_ext/hash_with_indifferent_access.rb) | 0 | ||||
-rw-r--r-- | railties/lib/vendor/thor-0.11.6/lib/thor/core_ext/ordered_hash.rb (renamed from railties/lib/vendor/thor-0.11.5/lib/thor/core_ext/ordered_hash.rb) | 0 | ||||
-rw-r--r-- | railties/lib/vendor/thor-0.11.6/lib/thor/error.rb (renamed from railties/lib/vendor/thor-0.11.5/lib/thor/error.rb) | 0 | ||||
-rw-r--r-- | railties/lib/vendor/thor-0.11.6/lib/thor/group.rb (renamed from railties/lib/vendor/thor-0.11.5/lib/thor/group.rb) | 0 | ||||
-rw-r--r-- | railties/lib/vendor/thor-0.11.6/lib/thor/invocation.rb (renamed from railties/lib/vendor/thor-0.11.5/lib/thor/invocation.rb) | 2 | ||||
-rw-r--r-- | railties/lib/vendor/thor-0.11.6/lib/thor/parser.rb (renamed from railties/lib/vendor/thor-0.11.5/lib/thor/parser.rb) | 0 | ||||
-rw-r--r-- | railties/lib/vendor/thor-0.11.6/lib/thor/parser/argument.rb (renamed from railties/lib/vendor/thor-0.11.5/lib/thor/parser/argument.rb) | 0 | ||||
-rw-r--r-- | railties/lib/vendor/thor-0.11.6/lib/thor/parser/arguments.rb (renamed from railties/lib/vendor/thor-0.11.5/lib/thor/parser/arguments.rb) | 0 | ||||
-rw-r--r-- | railties/lib/vendor/thor-0.11.6/lib/thor/parser/option.rb (renamed from railties/lib/vendor/thor-0.11.5/lib/thor/parser/option.rb) | 0 | ||||
-rw-r--r-- | railties/lib/vendor/thor-0.11.6/lib/thor/parser/options.rb (renamed from railties/lib/vendor/thor-0.11.5/lib/thor/parser/options.rb) | 0 | ||||
-rw-r--r-- | railties/lib/vendor/thor-0.11.6/lib/thor/rake_compat.rb (renamed from railties/lib/vendor/thor-0.11.5/lib/thor/rake_compat.rb) | 0 | ||||
-rw-r--r-- | railties/lib/vendor/thor-0.11.6/lib/thor/runner.rb (renamed from railties/lib/vendor/thor-0.11.5/lib/thor/runner.rb) | 4 | ||||
-rw-r--r-- | railties/lib/vendor/thor-0.11.6/lib/thor/shell.rb (renamed from railties/lib/vendor/thor-0.11.5/lib/thor/shell.rb) | 0 | ||||
-rw-r--r-- | railties/lib/vendor/thor-0.11.6/lib/thor/shell/basic.rb (renamed from railties/lib/vendor/thor-0.11.5/lib/thor/shell/basic.rb) | 5 | ||||
-rw-r--r-- | railties/lib/vendor/thor-0.11.6/lib/thor/shell/color.rb (renamed from railties/lib/vendor/thor-0.11.5/lib/thor/shell/color.rb) | 0 | ||||
-rw-r--r-- | railties/lib/vendor/thor-0.11.6/lib/thor/task.rb (renamed from railties/lib/vendor/thor-0.11.5/lib/thor/task.rb) | 20 | ||||
-rw-r--r-- | railties/lib/vendor/thor-0.11.6/lib/thor/util.rb (renamed from railties/lib/vendor/thor-0.11.5/lib/thor/util.rb) | 17 |
50 files changed, 334 insertions, 195 deletions
diff --git a/railties/lib/generators.rb b/railties/lib/generators.rb index a2f462ae81..879abb1c41 100644 --- a/railties/lib/generators.rb +++ b/railties/lib/generators.rb @@ -11,7 +11,7 @@ end $:.unshift(File.dirname(__FILE__)) -require 'vendor/thor-0.11.5/lib/thor' +require 'vendor/thor-0.11.6/lib/thor' require 'generators/base' require 'generators/named_base' @@ -45,7 +45,6 @@ module Rails }, :erb => { - :form => false, :layout => true }, diff --git a/railties/lib/generators/actions.rb b/railties/lib/generators/actions.rb index 03d0d11a07..c4552dd399 100644 --- a/railties/lib/generators/actions.rb +++ b/railties/lib/generators/actions.rb @@ -89,13 +89,11 @@ module Rails # git :add => "onefile.rb", :rm => "badfile.cxx" # def git(command={}) - in_root do - if command.is_a?(Symbol) - run "git #{command}" - else - command.each do |command, options| - run "git #{command} #{options}" - end + if command.is_a?(Symbol) + run "git #{command}" + else + command.each do |command, options| + run "git #{command} #{options}" end end end diff --git a/railties/lib/generators/base.rb b/railties/lib/generators/base.rb index cbe9c0a49d..c5d769b6ed 100644 --- a/railties/lib/generators/base.rb +++ b/railties/lib/generators/base.rb @@ -9,6 +9,8 @@ module Rails include Thor::Actions include Rails::Generators::Actions + add_runtime_options! + # Automatically sets the source root based on the class name. # def self.source_root @@ -45,8 +47,10 @@ module Rails # # ==== Examples # - # class ControllerGenerator < Rails::Generators::Base - # hook_for :test_framework, :aliases => "-t" + # module Rails::Generators + # class ControllerGenerator < Base + # hook_for :test_framework, :aliases => "-t" + # end # end # # The example above will create a test framework option and will invoke @@ -64,7 +68,49 @@ module Rails # invoked. This allows any test framework to hook into Rails as long as it # provides any of the hooks above. # - # Finally, if the user don't want to use any test framework, he can do: + # ==== Options + # + # This lookup can be customized with two options: :base and :as. The first + # is the root module value and in the example above defaults to "rails". + # The later defaults to the generator name, without the "Generator" ending. + # + # Let's suppose you are creating a generator that needs to invoke the + # controller generator from test unit. Your first attempt is: + # + # class AwesomeGenerator < Rails::Generators::Base + # hook_for :test_framework + # end + # + # The lookup in this case for test_unit as input is: + # + # "test_unit:generators:awesome", "test_unit" + # + # Which is not the desired the lookup. You can change it by providing the + # :as option: + # + # class AwesomeGenerator < Rails::Generators::Base + # hook_for :test_framework, :as => :controller + # end + # + # And now it will lookup at: + # + # "test_unit:generators:awesome", "test_unit" + # + # Similarly, if you want it to also lookup in the rails namespace, you just + # need to provide the :base value: + # + # class AwesomeGenerator < Rails::Generators::Base + # hook_for :test_framework, :base => :rails, :as => :controller + # end + # + # And the lookup is exactly the same as previously: + # + # "rails:generators:test_unit", "test_unit:generators:controller", "test_unit" + # + # ==== Switches + # + # All hooks come with switches for user interface. If the user don't want + # to use any test framework, he can do: # # ruby script/generate controller Account --skip-test-framework # diff --git a/railties/lib/generators/erb/scaffold/scaffold_generator.rb b/railties/lib/generators/erb/scaffold/scaffold_generator.rb index 955f22192a..d51dc7d725 100644 --- a/railties/lib/generators/erb/scaffold/scaffold_generator.rb +++ b/railties/lib/generators/erb/scaffold/scaffold_generator.rb @@ -1,13 +1,13 @@ require 'generators/erb' +require 'generators/resource_helpers' module Erb module Generators class ScaffoldGenerator < Base - include Rails::Generators::ScaffoldBase + include Rails::Generators::ResourceHelpers argument :attributes, :type => :array, :default => [], :banner => "field:type field:type" - class_option :form, :type => :boolean class_option :layout, :type => :boolean class_option :singleton, :type => :boolean, :desc => "Supply to skip index view" @@ -33,7 +33,6 @@ module Erb end def copy_form_file - return unless options[:form] copy_view :_form end diff --git a/railties/lib/generators/erb/scaffold/templates/_form.html.erb b/railties/lib/generators/erb/scaffold/templates/_form.html.erb new file mode 100644 index 0000000000..d02028d983 --- /dev/null +++ b/railties/lib/generators/erb/scaffold/templates/_form.html.erb @@ -0,0 +1,17 @@ +<%% form_for(@<%= singular_name %>) do |f| %> + <%%= f.error_messages %> + +<% for attribute in attributes -%> + <div class="field"> + <%%= f.label :<%= attribute.name %> %><br /> + <%%= f.<%= attribute.field_type %> :<%= attribute.name %> %> + </div> +<% end -%> + <div class="actions"> + <%% if @<%= singular_name %>.new_record? %> + <%%= f.submit 'Create' %> + <%% else %> + <%%= f.submit 'Update' %> + <%% end %> + </div> +<%% end %> diff --git a/railties/lib/generators/erb/scaffold/templates/edit.html.erb b/railties/lib/generators/erb/scaffold/templates/edit.html.erb index cca1d61c68..5bc507ffc8 100644 --- a/railties/lib/generators/erb/scaffold/templates/edit.html.erb +++ b/railties/lib/generators/erb/scaffold/templates/edit.html.erb @@ -1,18 +1,6 @@ <h1>Editing <%= singular_name %></h1> -<%% form_for(@<%= singular_name %>) do |f| %> - <%%= f.error_messages %> - -<% for attribute in attributes -%> - <p> - <%%= f.label :<%= attribute.name %> %><br /> - <%%= f.<%= attribute.field_type %> :<%= attribute.name %> %> - </p> -<% end -%> - <p> - <%%= f.submit 'Update' %> - </p> -<%% end %> +<%%= render 'form' %> <%%= link_to 'Show', @<%= singular_name %> %> | -<%%= link_to 'Back', <%= plural_name %>_path %>
\ No newline at end of file +<%%= link_to 'Back', <%= plural_name %>_path %> diff --git a/railties/lib/generators/erb/scaffold/templates/layout.html.erb b/railties/lib/generators/erb/scaffold/templates/layout.html.erb index aacfbe4a8f..6460e5b599 100644 --- a/railties/lib/generators/erb/scaffold/templates/layout.html.erb +++ b/railties/lib/generators/erb/scaffold/templates/layout.html.erb @@ -7,7 +7,7 @@ </head> <body> -<p style="color: green"><%%= flash[:notice] %></p> +<p class="notice"><%%= flash[:notice] %></p> <%%= yield %> diff --git a/railties/lib/generators/erb/scaffold/templates/new.html.erb b/railties/lib/generators/erb/scaffold/templates/new.html.erb index 96c89fc50e..9a1c489331 100644 --- a/railties/lib/generators/erb/scaffold/templates/new.html.erb +++ b/railties/lib/generators/erb/scaffold/templates/new.html.erb @@ -1,17 +1,5 @@ <h1>New <%= singular_name %></h1> -<%% form_for(@<%= singular_name %>) do |f| %> - <%%= f.error_messages %> +<%%= render 'form' %> -<% for attribute in attributes -%> - <p> - <%%= f.label :<%= attribute.name %> %><br /> - <%%= f.<%= attribute.field_type %> :<%= attribute.name %> %> - </p> -<% end -%> - <p> - <%%= f.submit 'Create' %> - </p> -<%% end %> - -<%%= link_to 'Back', <%= plural_name %>_path %>
\ No newline at end of file +<%%= link_to 'Back', <%= plural_name %>_path %> diff --git a/railties/lib/generators/named_base.rb b/railties/lib/generators/named_base.rb index cd7aa61b50..b6ac05f482 100644 --- a/railties/lib/generators/named_base.rb +++ b/railties/lib/generators/named_base.rb @@ -97,67 +97,5 @@ module Rails end end end - - # Deal with controller names on scaffold. Also provide helpers to deal with - # ActionORM. - # - module ScaffoldBase - def self.included(base) #:nodoc: - base.send :attr_reader, :controller_name, :controller_class_name, :controller_file_name, - :controller_class_path, :controller_file_path - end - - # Set controller variables on initialization. - # - def initialize(*args) #:nodoc: - super - @controller_name = name.pluralize - - base_name, @controller_class_path, @controller_file_path, class_nesting, class_nesting_depth = extract_modules(@controller_name) - class_name_without_nesting, @controller_file_name, controller_plural_name = inflect_names(base_name) - - @controller_class_name = if class_nesting.empty? - class_name_without_nesting - else - "#{class_nesting}::#{class_name_without_nesting}" - end - end - - protected - - # Loads the ORM::Generators::ActiveModel class. This class is responsable - # to tell scaffold entities how to generate an specific method for the - # ORM. Check Rails::Generators::ActiveModel for more information. - # - def orm_class - @orm_class ||= begin - # Raise an error if the class_option :orm was not defined. - unless self.class.class_options[:orm] - raise "You need to have :orm as class option to invoke orm_class and orm_instance" - end - - action_orm = "#{options[:orm].to_s.classify}::Generators::ActiveModel" - - # If the orm was not loaded, try to load it at "generators/orm", - # for example "generators/active_record" or "generators/sequel". - begin - klass = action_orm.constantize - rescue NameError - require "generators/#{options[:orm]}" - end - - # Try once again after loading the file with success. - klass ||= action_orm.constantize - rescue Exception => e - raise Error, "Could not load #{action_orm}, skipping controller. Error: #{e.message}." - end - end - - # Initialize ORM::Generators::ActiveModel to access instance methods. - # - def orm_instance(name=file_name) - @orm_instance ||= @orm_class.new(name) - end - end end end diff --git a/railties/lib/generators/rails/generator/generator_generator.rb b/railties/lib/generators/rails/generator/generator_generator.rb index 2fc97b20d3..5b5d1884bc 100644 --- a/railties/lib/generators/rails/generator/generator_generator.rb +++ b/railties/lib/generators/rails/generator/generator_generator.rb @@ -6,7 +6,7 @@ module Rails class_option :namespace, :type => :boolean, :default => true, :desc => "Namespace generator under lib/generators/name" - def craete_generator_files + def create_generator_files directory '.', generator_dir end diff --git a/railties/lib/generators/rails/resource/resource_generator.rb b/railties/lib/generators/rails/resource/resource_generator.rb index 70babc0550..9abb8bbeaf 100644 --- a/railties/lib/generators/rails/resource/resource_generator.rb +++ b/railties/lib/generators/rails/resource/resource_generator.rb @@ -1,25 +1,19 @@ require 'generators/rails/model/model_generator' +require 'generators/resource_helpers' module Rails module Generators class ResourceGenerator < ModelGenerator #metagenerator + include ResourceHelpers + hook_for :resource_controller, :required => true do |base, controller| - base.invoke controller, [ base.name.pluralize, base.options[:actions] ] + base.invoke controller, [ base.controller_name, base.options[:actions] ] end class_option :actions, :type => :array, :banner => "ACTION ACTION", :default => [], :desc => "Actions for the resource controller" - class_option :singleton, :type => :boolean, :desc => "Supply to create a singleton controller" - class_option :force_plural, :type => :boolean, :desc => "Forces the use of a plural ModelName" - - def initialize(*args) - super - if name == name.pluralize && !options[:force_plural] - say "Plural version of the model detected, using singularized version. Override with --force-plural." - name.replace name.singularize - end - end + class_option :singleton, :type => :boolean, :desc => "Supply to create a singleton controller" def add_resource_route route "map.resource#{:s unless options[:singleton]} :#{pluralize?(file_name)}" diff --git a/railties/lib/generators/rails/scaffold/scaffold_generator.rb b/railties/lib/generators/rails/scaffold/scaffold_generator.rb index af44c8ba65..fdea5bf52b 100644 --- a/railties/lib/generators/rails/scaffold/scaffold_generator.rb +++ b/railties/lib/generators/rails/scaffold/scaffold_generator.rb @@ -3,7 +3,8 @@ require 'generators/rails/resource/resource_generator' module Rails module Generators class ScaffoldGenerator < ResourceGenerator #metagenerator - remove_hook_for :actions, :resource_controller + remove_hook_for :resource_controller + remove_class_option :actions hook_for :scaffold_controller, :required => true hook_for :stylesheets diff --git a/railties/lib/generators/rails/scaffold_controller/scaffold_controller_generator.rb b/railties/lib/generators/rails/scaffold_controller/scaffold_controller_generator.rb index 972be5a33b..228cdecb14 100644 --- a/railties/lib/generators/rails/scaffold_controller/scaffold_controller_generator.rb +++ b/railties/lib/generators/rails/scaffold_controller/scaffold_controller_generator.rb @@ -1,8 +1,9 @@ +require 'generators/resource_helpers' + module Rails module Generators class ScaffoldControllerGenerator < NamedBase - # Add controller methods and ActionORM settings. - include ScaffoldBase + include ResourceHelpers check_class_collision :suffix => "Controller" diff --git a/railties/lib/generators/rails/stylesheets/templates/scaffold.css b/railties/lib/generators/rails/stylesheets/templates/scaffold.css index 093c20994d..d9fa2cf2dc 100644 --- a/railties/lib/generators/rails/stylesheets/templates/scaffold.css +++ b/railties/lib/generators/rails/stylesheets/templates/scaffold.css @@ -16,6 +16,14 @@ a { color: #000; } a:visited { color: #666; } a:hover { color: #fff; background-color:#000; } +div.field, div.actions { + margin-bottom: 10px; +} + +.notice { + color: green; +} + .fieldWithErrors { padding: 2px; background-color: red; diff --git a/railties/lib/generators/resource_helpers.rb b/railties/lib/generators/resource_helpers.rb new file mode 100644 index 0000000000..ba1444652d --- /dev/null +++ b/railties/lib/generators/resource_helpers.rb @@ -0,0 +1,74 @@ +module Rails + module Generators + # Deal with controller names on scaffold and add some helpers to deal with + # ActiveModel. + # + module ResourceHelpers + def self.included(base) #:nodoc: + base.send :attr_reader, :controller_name, :controller_class_name, :controller_file_name, + :controller_class_path, :controller_file_path + + base.send :class_option, :force_plural, :type => :boolean, :desc => "Forces the use of a plural ModelName" + end + + # Set controller variables on initialization. + # + def initialize(*args) #:nodoc: + super + + if name == name.pluralize && !options[:force_plural] + say "Plural version of the model detected, using singularized version. Override with --force-plural." + name.replace name.singularize + assign_names!(self.name) + end + + @controller_name = name.pluralize + + base_name, @controller_class_path, @controller_file_path, class_nesting, class_nesting_depth = extract_modules(@controller_name) + class_name_without_nesting, @controller_file_name, controller_plural_name = inflect_names(base_name) + + @controller_class_name = if class_nesting.empty? + class_name_without_nesting + else + "#{class_nesting}::#{class_name_without_nesting}" + end + end + + protected + + # Loads the ORM::Generators::ActiveModel class. This class is responsable + # to tell scaffold entities how to generate an specific method for the + # ORM. Check Rails::Generators::ActiveModel for more information. + # + def orm_class + @orm_class ||= begin + # Raise an error if the class_option :orm was not defined. + unless self.class.class_options[:orm] + raise "You need to have :orm as class option to invoke orm_class and orm_instance" + end + + active_model = "#{options[:orm].to_s.classify}::Generators::ActiveModel" + + # If the orm was not loaded, try to load it at "generators/orm", + # for example "generators/active_record" or "generators/sequel". + begin + klass = active_model.constantize + rescue NameError + require "generators/#{options[:orm]}" + end + + # Try once again after loading the file with success. + klass ||= active_model.constantize + rescue Exception => e + raise Error, "Could not load #{active_model}, skipping controller. Error: #{e.message}." + end + end + + # Initialize ORM::Generators::ActiveModel to access instance methods. + # + def orm_instance(name=file_name) + @orm_instance ||= @orm_class.new(name) + end + end + end +end diff --git a/railties/lib/generators/test_unit/scaffold/scaffold_generator.rb b/railties/lib/generators/test_unit/scaffold/scaffold_generator.rb index 78fcea1e9c..a8f9c8bd79 100644 --- a/railties/lib/generators/test_unit/scaffold/scaffold_generator.rb +++ b/railties/lib/generators/test_unit/scaffold/scaffold_generator.rb @@ -1,9 +1,10 @@ require 'generators/test_unit' +require 'generators/resource_helpers' module TestUnit module Generators class ScaffoldGenerator < Base - include Rails::Generators::ScaffoldBase + include Rails::Generators::ResourceHelpers class_option :singleton, :type => :boolean, :desc => "Supply to create a singleton controller" check_class_collision :suffix => "ControllerTest" diff --git a/railties/lib/rails/configuration.rb b/railties/lib/rails/configuration.rb index 5cc4f80684..2b362a9c50 100644 --- a/railties/lib/rails/configuration.rb +++ b/railties/lib/rails/configuration.rb @@ -109,6 +109,7 @@ module Rails # TODO: Fix this when there is an application object def middleware + require 'action_controller' ActionController::Dispatcher.middleware end diff --git a/railties/lib/rails/plugin.rb b/railties/lib/rails/plugin.rb index 49ec5c7fba..1c0af6411a 100644 --- a/railties/lib/rails/plugin.rb +++ b/railties/lib/rails/plugin.rb @@ -71,6 +71,10 @@ module Rails File.exist?(routing_file) end + # Returns true if there is any localization file in locale_path + def localized? + locale_files.any? + end def view_path File.join(directory, 'app', 'views') @@ -87,6 +91,14 @@ module Rails def routing_file File.join(directory, 'config', 'routes.rb') end + + def locale_path + File.join(directory, 'config', 'locales') + end + + def locale_files + Dir[ File.join(locale_path, '*.{rb,yml}') ] + end private diff --git a/railties/lib/rails/plugin/loader.rb b/railties/lib/rails/plugin/loader.rb index 7ea9c7c0f3..0d16cbd7c3 100644 --- a/railties/lib/rails/plugin/loader.rb +++ b/railties/lib/rails/plugin/loader.rb @@ -73,6 +73,7 @@ module Rails def configure_engines if engines.any? add_engine_routing_configurations + add_engine_locales add_engine_controller_paths add_engine_view_paths end @@ -84,6 +85,14 @@ module Rails end end + def add_engine_locales + localized_engines = engines.select { |engine| engine.localized? } + + # reverse it such that the last engine can overwrite translations from the first, like with routes + locale_files = localized_engines.collect { |engine| engine.locale_files }.reverse.flatten + I18n.load_path += locale_files - I18n.load_path + end + def add_engine_controller_paths ActionController::Routing.controller_paths += engines.collect {|engine| engine.controller_path } end diff --git a/railties/lib/tasks/databases.rake b/railties/lib/tasks/databases.rake index 687bc00b3c..8401cf0590 100644 --- a/railties/lib/tasks/databases.rake +++ b/railties/lib/tasks/databases.rake @@ -55,7 +55,7 @@ namespace :db do case config['adapter'] when 'mysql' @charset = ENV['CHARSET'] || 'utf8' - @collation = ENV['COLLATION'] || 'utf8_general_ci' + @collation = ENV['COLLATION'] || 'utf8_unicode_ci' creation_options = {:charset => (config['charset'] || @charset), :collation => (config['collation'] || @collation)} begin ActiveRecord::Base.establish_connection(config.merge('database' => nil)) diff --git a/railties/lib/vendor/thor-0.11.5/CHANGELOG.rdoc b/railties/lib/vendor/thor-0.11.6/CHANGELOG.rdoc index dba25b7205..dba25b7205 100644 --- a/railties/lib/vendor/thor-0.11.5/CHANGELOG.rdoc +++ b/railties/lib/vendor/thor-0.11.6/CHANGELOG.rdoc diff --git a/railties/lib/vendor/thor-0.11.5/LICENSE b/railties/lib/vendor/thor-0.11.6/LICENSE index 98722da459..98722da459 100644 --- a/railties/lib/vendor/thor-0.11.5/LICENSE +++ b/railties/lib/vendor/thor-0.11.6/LICENSE diff --git a/railties/lib/vendor/thor-0.11.5/README.rdoc b/railties/lib/vendor/thor-0.11.6/README.rdoc index f1106f02b6..f1106f02b6 100644 --- a/railties/lib/vendor/thor-0.11.5/README.rdoc +++ b/railties/lib/vendor/thor-0.11.6/README.rdoc diff --git a/railties/lib/vendor/thor-0.11.5/bin/rake2thor b/railties/lib/vendor/thor-0.11.6/bin/rake2thor index 50c7410d80..50c7410d80 100755 --- a/railties/lib/vendor/thor-0.11.5/bin/rake2thor +++ b/railties/lib/vendor/thor-0.11.6/bin/rake2thor diff --git a/railties/lib/vendor/thor-0.11.5/bin/thor b/railties/lib/vendor/thor-0.11.6/bin/thor index eaf849fb4a..eaf849fb4a 100755 --- a/railties/lib/vendor/thor-0.11.5/bin/thor +++ b/railties/lib/vendor/thor-0.11.6/bin/thor diff --git a/railties/lib/vendor/thor-0.11.5/lib/thor.rb b/railties/lib/vendor/thor-0.11.6/lib/thor.rb index 8dfcfd4c5b..3b45c4e9b7 100644 --- a/railties/lib/vendor/thor-0.11.5/lib/thor.rb +++ b/railties/lib/vendor/thor-0.11.6/lib/thor.rb @@ -135,7 +135,7 @@ class Thor args, opts = given_args, {} end - task ||= Task.dynamic(meth) + task ||= Thor::Task::Dynamic.new(meth) trailing = args[Range.new(arguments.size, -1)] new(args, opts, config).invoke(task, trailing || []) end diff --git a/railties/lib/vendor/thor-0.11.5/lib/thor/actions.rb b/railties/lib/vendor/thor-0.11.6/lib/thor/actions.rb index 1d09dc38ae..d561ccb2aa 100644 --- a/railties/lib/vendor/thor-0.11.5/lib/thor/actions.rb +++ b/railties/lib/vendor/thor-0.11.6/lib/thor/actions.rb @@ -8,23 +8,8 @@ class Thor module Actions attr_accessor :behavior - # On inclusion, add some options to base. - # def self.included(base) #:nodoc: base.extend ClassMethods - return unless base.respond_to?(:class_option) - - base.class_option :pretend, :type => :boolean, :aliases => "-p", :group => :runtime, - :desc => "Run but do not make any changes" - - base.class_option :force, :type => :boolean, :aliases => "-f", :group => :runtime, - :desc => "Overwrite files that already exist" - - base.class_option :skip, :type => :boolean, :aliases => "-s", :group => :runtime, - :desc => "Skip files that already exist" - - base.class_option :quiet, :type => :boolean, :aliases => "-q", :group => :runtime, - :desc => "Supress status output" end module ClassMethods @@ -49,6 +34,22 @@ class Thor paths += from_superclass(:source_paths, []) paths end + + # Add runtime options that help actions execution. + # + def add_runtime_options! + class_option :pretend, :type => :boolean, :aliases => "-p", :group => :runtime, + :desc => "Run but do not make any changes" + + class_option :force, :type => :boolean, :aliases => "-f", :group => :runtime, + :desc => "Overwrite files that already exist" + + class_option :skip, :type => :boolean, :aliases => "-s", :group => :runtime, + :desc => "Skip files that already exist" + + class_option :quiet, :type => :boolean, :aliases => "-q", :group => :runtime, + :desc => "Supress status output" + end end # Extends initializer to add more configuration options. diff --git a/railties/lib/vendor/thor-0.11.5/lib/thor/actions/create_file.rb b/railties/lib/vendor/thor-0.11.6/lib/thor/actions/create_file.rb index 8f6badee27..8f6badee27 100644 --- a/railties/lib/vendor/thor-0.11.5/lib/thor/actions/create_file.rb +++ b/railties/lib/vendor/thor-0.11.6/lib/thor/actions/create_file.rb diff --git a/railties/lib/vendor/thor-0.11.5/lib/thor/actions/directory.rb b/railties/lib/vendor/thor-0.11.6/lib/thor/actions/directory.rb index be5eb822ac..be5eb822ac 100644 --- a/railties/lib/vendor/thor-0.11.5/lib/thor/actions/directory.rb +++ b/railties/lib/vendor/thor-0.11.6/lib/thor/actions/directory.rb diff --git a/railties/lib/vendor/thor-0.11.5/lib/thor/actions/empty_directory.rb b/railties/lib/vendor/thor-0.11.6/lib/thor/actions/empty_directory.rb index 03c1fe4af1..03c1fe4af1 100644 --- a/railties/lib/vendor/thor-0.11.5/lib/thor/actions/empty_directory.rb +++ b/railties/lib/vendor/thor-0.11.6/lib/thor/actions/empty_directory.rb diff --git a/railties/lib/vendor/thor-0.11.5/lib/thor/actions/file_manipulation.rb b/railties/lib/vendor/thor-0.11.6/lib/thor/actions/file_manipulation.rb index 74c157ba8c..d77d90d448 100644 --- a/railties/lib/vendor/thor-0.11.5/lib/thor/actions/file_manipulation.rb +++ b/railties/lib/vendor/thor-0.11.6/lib/thor/actions/file_manipulation.rb @@ -100,7 +100,7 @@ class Thor FileUtils.chmod_R(mode, path) unless options[:pretend] end - # Prepend text to a file. + # Prepend text to a file. Since it depends on inject_into_file, it's reversible. # # ==== Parameters # path<String>:: path of the file to be changed @@ -111,19 +111,17 @@ class Thor # # prepend_file 'config/environments/test.rb', 'config.gem "rspec"' # - def prepend_file(path, data=nil, config={}, &block) - return unless behavior == :invoke - path = File.expand_path(path, destination_root) - say_status :prepend, relative_to_original_destination_root(path), config.fetch(:verbose, true) - - unless options[:pretend] - content = data || block.call - content << File.read(path) - File.open(path, 'wb') { |file| file.write(content) } - end + # prepend_file 'config/environments/test.rb' do + # 'config.gem "rspec"' + # end + # + def prepend_file(path, *args, &block) + config = args.last.is_a?(Hash) ? args.pop : {} + config.merge!(:after => /\A/) + inject_into_file(path, *(args << config), &block) end - # Append text to a file. + # Append text to a file. Since it depends on inject_into_file, it's reversible. # # ==== Parameters # path<String>:: path of the file to be changed @@ -134,11 +132,37 @@ class Thor # # append_file 'config/environments/test.rb', 'config.gem "rspec"' # - def append_file(path, data=nil, config={}, &block) - return unless behavior == :invoke - path = File.expand_path(path, destination_root) - say_status :append, relative_to_original_destination_root(path), config.fetch(:verbose, true) - File.open(path, 'ab') { |file| file.write(data || block.call) } unless options[:pretend] + # append_file 'config/environments/test.rb' do + # 'config.gem "rspec"' + # end + # + def append_file(path, *args, &block) + config = args.last.is_a?(Hash) ? args.pop : {} + config.merge!(:before => /\z/) + inject_into_file(path, *(args << config), &block) + end + + # Injects text right after the class definition. Since it depends on + # inject_into_file, it's reversible. + # + # ==== Parameters + # path<String>:: path of the file to be changed + # klass<String|Class>:: the class to be manipulated + # data<String>:: the data to append to the class, can be also given as a block. + # config<Hash>:: give :verbose => false to not log the status. + # + # ==== Examples + # + # inject_into_class "app/controllers/application_controller.rb", " filter_parameter :password\n" + # + # inject_into_class "app/controllers/application_controller.rb", ApplicationController do + # " filter_parameter :password\n" + # end + # + def inject_into_class(path, klass, *args, &block) + config = args.last.is_a?(Hash) ? args.pop : {} + config.merge!(:after => /class #{klass}\n|class #{klass} .*\n/) + inject_into_file(path, *(args << config), &block) end # Run a regular expression replacement on a file. diff --git a/railties/lib/vendor/thor-0.11.5/lib/thor/actions/inject_into_file.rb b/railties/lib/vendor/thor-0.11.6/lib/thor/actions/inject_into_file.rb index 66dd1f5fc1..0636ec6591 100644 --- a/railties/lib/vendor/thor-0.11.5/lib/thor/actions/inject_into_file.rb +++ b/railties/lib/vendor/thor-0.11.6/lib/thor/actions/inject_into_file.rb @@ -3,10 +3,8 @@ require 'thor/actions/empty_directory' class Thor module Actions - # Injects the given content into a file. Different from append_file, - # prepend_file and gsub_file, this method is reversible. By this reason, - # the flag can only be strings. gsub_file is your friend if you need to - # deal with more complex cases. + # Injects the given content into a file. Different from gsub_file, this + # method is reversible. # # ==== Parameters # destination<String>:: Relative path to the destination root @@ -16,11 +14,11 @@ class Thor # # ==== Examples # - # inject_into_file "config/environment.rb", "config.gem thor", :after => "Rails::Initializer.run do |config|\n" + # inject_into_file "config/environment.rb", "config.gem :thor", :after => "Rails::Initializer.run do |config|\n" # # inject_into_file "config/environment.rb", :after => "Rails::Initializer.run do |config|\n" do # gems = ask "Which gems would you like to add?" - # gems.split(" ").map{ |gem| " config.gem #{gem}" }.join("\n") + # gems.split(" ").map{ |gem| " config.gem :#{gem}" }.join("\n") # end # def inject_into_file(destination, *args, &block) @@ -29,40 +27,65 @@ class Thor else data, config = args.shift, args.shift end - - log_status = args.empty? || args.pop action InjectIntoFile.new(self, destination, data, config) end class InjectIntoFile < EmptyDirectory #:nodoc: - attr_reader :flag, :replacement + attr_reader :replacement, :flag, :behavior def initialize(base, destination, data, config) super(base, destination, { :verbose => true }.merge(config)) - data = data.call if data.is_a?(Proc) - - @replacement = if @config.key?(:after) - @flag = @config.delete(:after) - @flag + data + @behavior, @flag = if @config.key?(:after) + [:after, @config.delete(:after)] else - @flag = @config.delete(:before) - data + @flag + [:before, @config.delete(:before)] end + + @replacement = data.is_a?(Proc) ? data.call : data + @flag = Regexp.escape(@flag) unless @flag.is_a?(Regexp) end def invoke! - say_status :inject, config[:verbose] - replace!(flag, replacement) + say_status :invoke + + content = if @behavior == :after + '\0' + replacement + else + replacement + '\0' + end + + replace!(/#{flag}/, content) end def revoke! - say_status :deinject, config[:verbose] - replace!(replacement, flag) + say_status :revoke + + regexp = if @behavior == :after + content = '\1\2' + /(#{flag})(.*)(#{Regexp.escape(replacement)})/m + else + content = '\2\3' + /(#{Regexp.escape(replacement)})(.*)(#{flag})/m + end + + replace!(regexp, content) end protected + def say_status(behavior) + status = if flag == /\A/ + behavior == :invoke ? :prepend : :unprepend + elsif flag == /\z/ + behavior == :invoke ? :append : :unappend + else + behavior == :invoke ? :inject : :deinject + end + + super(status, config[:verbose]) + end + # Adds the content to the file. # def replace!(regexp, string) diff --git a/railties/lib/vendor/thor-0.11.5/lib/thor/base.rb b/railties/lib/vendor/thor-0.11.6/lib/thor/base.rb index 0fa87f8162..700d794123 100644 --- a/railties/lib/vendor/thor-0.11.5/lib/thor/base.rb +++ b/railties/lib/vendor/thor-0.11.6/lib/thor/base.rb @@ -355,6 +355,7 @@ class Thor else config[:shell].error e.message end + exit(1) if exit_on_failure? end protected @@ -491,6 +492,12 @@ class Thor end end + # A flag that makes the process exit with status 1 if any error happens. + # + def exit_on_failure? + false + end + # SIGNATURE: Sets the baseclass. This is where the superclass lookup # finishes. def baseclass #:nodoc: diff --git a/railties/lib/vendor/thor-0.11.5/lib/thor/core_ext/hash_with_indifferent_access.rb b/railties/lib/vendor/thor-0.11.6/lib/thor/core_ext/hash_with_indifferent_access.rb index 78bc5cf4bf..78bc5cf4bf 100644 --- a/railties/lib/vendor/thor-0.11.5/lib/thor/core_ext/hash_with_indifferent_access.rb +++ b/railties/lib/vendor/thor-0.11.6/lib/thor/core_ext/hash_with_indifferent_access.rb diff --git a/railties/lib/vendor/thor-0.11.5/lib/thor/core_ext/ordered_hash.rb b/railties/lib/vendor/thor-0.11.6/lib/thor/core_ext/ordered_hash.rb index 27fea5bb35..27fea5bb35 100644 --- a/railties/lib/vendor/thor-0.11.5/lib/thor/core_ext/ordered_hash.rb +++ b/railties/lib/vendor/thor-0.11.6/lib/thor/core_ext/ordered_hash.rb diff --git a/railties/lib/vendor/thor-0.11.5/lib/thor/error.rb b/railties/lib/vendor/thor-0.11.6/lib/thor/error.rb index f9b31a35d1..f9b31a35d1 100644 --- a/railties/lib/vendor/thor-0.11.5/lib/thor/error.rb +++ b/railties/lib/vendor/thor-0.11.6/lib/thor/error.rb diff --git a/railties/lib/vendor/thor-0.11.5/lib/thor/group.rb b/railties/lib/vendor/thor-0.11.6/lib/thor/group.rb index 1e59df2313..1e59df2313 100644 --- a/railties/lib/vendor/thor-0.11.5/lib/thor/group.rb +++ b/railties/lib/vendor/thor-0.11.6/lib/thor/group.rb diff --git a/railties/lib/vendor/thor-0.11.5/lib/thor/invocation.rb b/railties/lib/vendor/thor-0.11.6/lib/thor/invocation.rb index c0388dd863..32e6a72454 100644 --- a/railties/lib/vendor/thor-0.11.5/lib/thor/invocation.rb +++ b/railties/lib/vendor/thor-0.11.6/lib/thor/invocation.rb @@ -153,7 +153,7 @@ class Thor raise "Expected Thor class, got #{klass}" unless klass <= Thor::Base task ||= klass.default_task if klass <= Thor - task = klass.all_tasks[task.to_s] || Task.dynamic(task) if task && !task.is_a?(Thor::Task) + task = klass.all_tasks[task.to_s] || Thor::Task::Dynamic.new(task) if task && !task.is_a?(Thor::Task) task end diff --git a/railties/lib/vendor/thor-0.11.5/lib/thor/parser.rb b/railties/lib/vendor/thor-0.11.6/lib/thor/parser.rb index 57a3f6e1a5..57a3f6e1a5 100644 --- a/railties/lib/vendor/thor-0.11.5/lib/thor/parser.rb +++ b/railties/lib/vendor/thor-0.11.6/lib/thor/parser.rb diff --git a/railties/lib/vendor/thor-0.11.5/lib/thor/parser/argument.rb b/railties/lib/vendor/thor-0.11.6/lib/thor/parser/argument.rb index aa8ace4719..aa8ace4719 100644 --- a/railties/lib/vendor/thor-0.11.5/lib/thor/parser/argument.rb +++ b/railties/lib/vendor/thor-0.11.6/lib/thor/parser/argument.rb diff --git a/railties/lib/vendor/thor-0.11.5/lib/thor/parser/arguments.rb b/railties/lib/vendor/thor-0.11.6/lib/thor/parser/arguments.rb index fb5d965e06..fb5d965e06 100644 --- a/railties/lib/vendor/thor-0.11.5/lib/thor/parser/arguments.rb +++ b/railties/lib/vendor/thor-0.11.6/lib/thor/parser/arguments.rb diff --git a/railties/lib/vendor/thor-0.11.5/lib/thor/parser/option.rb b/railties/lib/vendor/thor-0.11.6/lib/thor/parser/option.rb index 9e40ec73fa..9e40ec73fa 100644 --- a/railties/lib/vendor/thor-0.11.5/lib/thor/parser/option.rb +++ b/railties/lib/vendor/thor-0.11.6/lib/thor/parser/option.rb diff --git a/railties/lib/vendor/thor-0.11.5/lib/thor/parser/options.rb b/railties/lib/vendor/thor-0.11.6/lib/thor/parser/options.rb index 75092308b5..75092308b5 100644 --- a/railties/lib/vendor/thor-0.11.5/lib/thor/parser/options.rb +++ b/railties/lib/vendor/thor-0.11.6/lib/thor/parser/options.rb diff --git a/railties/lib/vendor/thor-0.11.5/lib/thor/rake_compat.rb b/railties/lib/vendor/thor-0.11.6/lib/thor/rake_compat.rb index 3ab6bb21f5..3ab6bb21f5 100644 --- a/railties/lib/vendor/thor-0.11.5/lib/thor/rake_compat.rb +++ b/railties/lib/vendor/thor-0.11.6/lib/thor/rake_compat.rb diff --git a/railties/lib/vendor/thor-0.11.5/lib/thor/runner.rb b/railties/lib/vendor/thor-0.11.6/lib/thor/runner.rb index 3639ac0aa9..43da09b336 100644 --- a/railties/lib/vendor/thor-0.11.5/lib/thor/runner.rb +++ b/railties/lib/vendor/thor-0.11.6/lib/thor/runner.rb @@ -175,6 +175,10 @@ class Thor::Runner < Thor #:nodoc: File.open(yaml_file, "w") { |f| f.puts yaml.to_yaml } end + def self.exit_on_failure? + true + end + # Load the thorfiles. If relevant_to is supplied, looks for specific files # in the thor_root instead of loading them all. # diff --git a/railties/lib/vendor/thor-0.11.5/lib/thor/shell.rb b/railties/lib/vendor/thor-0.11.6/lib/thor/shell.rb index 0d3f4d5951..0d3f4d5951 100644 --- a/railties/lib/vendor/thor-0.11.5/lib/thor/shell.rb +++ b/railties/lib/vendor/thor-0.11.6/lib/thor/shell.rb diff --git a/railties/lib/vendor/thor-0.11.5/lib/thor/shell/basic.rb b/railties/lib/vendor/thor-0.11.6/lib/thor/shell/basic.rb index 3c02e47c33..ea9665380b 100644 --- a/railties/lib/vendor/thor-0.11.5/lib/thor/shell/basic.rb +++ b/railties/lib/vendor/thor-0.11.6/lib/thor/shell/basic.rb @@ -34,12 +34,11 @@ class Thor # ==== Example # say("I know you knew that.") # - def say(message="", color=nil, force_new_line=false) + def say(message="", color=nil, force_new_line=(message.to_s !~ /( |\t)$/)) message = message.to_s - new_line = force_new_line || !(message[-1, 1] == " " || message[-1, 1] == "\t") message = set_color(message, color) if color - if new_line + if force_new_line $stdout.puts(message) else $stdout.print(message) diff --git a/railties/lib/vendor/thor-0.11.5/lib/thor/shell/color.rb b/railties/lib/vendor/thor-0.11.6/lib/thor/shell/color.rb index 24704f7885..24704f7885 100644 --- a/railties/lib/vendor/thor-0.11.5/lib/thor/shell/color.rb +++ b/railties/lib/vendor/thor-0.11.6/lib/thor/shell/color.rb diff --git a/railties/lib/vendor/thor-0.11.5/lib/thor/task.rb b/railties/lib/vendor/thor-0.11.6/lib/thor/task.rb index 23d35b883c..91c7564d3f 100644 --- a/railties/lib/vendor/thor-0.11.5/lib/thor/task.rb +++ b/railties/lib/vendor/thor-0.11.6/lib/thor/task.rb @@ -1,11 +1,19 @@ class Thor class Task < Struct.new(:name, :description, :usage, :options) - # Creates a dynamic task. Dynamic tasks are created on demand to allow method - # missing calls (since a method missing does not have a task object for it). + # A dynamic task that handles method missing scenarios. # - def self.dynamic(name) - new(name, "A dynamically-generated task", name.to_s) + class Dynamic < Task + def initialize(name) + super(name.to_s, "A dynamically-generated task", name.to_s) + end + + def run(instance, args=[]) + unless (instance.methods & [name.to_s, name.to_sym]).empty? + raise Error, "could not find Thor class or task '#{name}'" + end + super + end end def initialize(name, description, usage, options=nil) @@ -37,8 +45,6 @@ class Thor # injected in the usage. # def formatted_usage(klass=nil, namespace=false, show_options=true) - formatted = '' - formatted = if namespace.is_a?(String) "#{namespace}:" elsif klass && namespace @@ -77,7 +83,7 @@ class Thor # def public_method?(instance) #:nodoc: collection = instance.private_methods + instance.protected_methods - !(collection).include?(name.to_s) && !(collection).include?(name.to_sym) # For Ruby 1.9 + (collection & [name.to_s, name.to_sym]).empty? end # Clean everything that comes from the Thor gempath and remove the caller. diff --git a/railties/lib/vendor/thor-0.11.5/lib/thor/util.rb b/railties/lib/vendor/thor-0.11.6/lib/thor/util.rb index 4938dc4aca..fd820d7462 100644 --- a/railties/lib/vendor/thor-0.11.5/lib/thor/util.rb +++ b/railties/lib/vendor/thor-0.11.6/lib/thor/util.rb @@ -22,7 +22,7 @@ class Thor # namespace<String>:: The namespace to search for. # def self.find_by_namespace(namespace) - namespace = 'default' if namespace.empty? + namespace = "default#{namespace}" if namespace.empty? || namespace =~ /^:/ Thor::Base.subclasses.find do |klass| klass.namespace == namespace @@ -137,17 +137,18 @@ class Thor # inherit from Thor or Thor::Group. # def self.namespace_to_thor_class_and_task(namespace, raise_if_nil=true) - klass, task_name = Thor::Util.find_by_namespace(namespace), nil + if namespace.include?(?:) + pieces = namespace.split(":") + task = pieces.pop + klass = Thor::Util.find_by_namespace(pieces.join(":")) + end - if klass.nil? && namespace.include?(?:) - namespace = namespace.split(":") - task_name = namespace.pop - klass = Thor::Util.find_by_namespace(namespace.join(":")) + unless klass + klass, task = Thor::Util.find_by_namespace(namespace), nil end raise Error, "could not find Thor class or task '#{namespace}'" if raise_if_nil && klass.nil? - - return klass, task_name + return klass, task end # Receives a path and load the thor file in the path. The file is evaluated |