diff options
5 files changed, 31 insertions, 12 deletions
diff --git a/railties/lib/generators/active_record/model/model_generator.rb b/railties/lib/generators/active_record/model/model_generator.rb index 59310f6c61..42ff48c75c 100644 --- a/railties/lib/generators/active_record/model/model_generator.rb +++ b/railties/lib/generators/active_record/model/model_generator.rb @@ -23,6 +23,8 @@ module ActiveRecord end end + hook_for :test_framework + protected def parent_class_name diff --git a/railties/lib/generators/active_record/observer/observer_generator.rb b/railties/lib/generators/active_record/observer/observer_generator.rb index fa51c23336..a6b57423b8 100644 --- a/railties/lib/generators/active_record/observer/observer_generator.rb +++ b/railties/lib/generators/active_record/observer/observer_generator.rb @@ -8,6 +8,8 @@ module ActiveRecord def create_observer_file template 'observer.rb', File.join('app/models', class_path, "#{file_name}_observer.rb") end + + hook_for :test_framework end end end diff --git a/railties/lib/generators/base.rb b/railties/lib/generators/base.rb index a734ab764f..1bd8154e8c 100644 --- a/railties/lib/generators/base.rb +++ b/railties/lib/generators/base.rb @@ -313,13 +313,28 @@ module Rails end # Overwrite class options help to allow invoked generators options to be - # shown when invoking a generator. Only first level options and options - # that belongs to the default group are shown. + # shown when invoking a generator. Only first and second level options + # are shown, for instance, if a generator invokes an ORM that invokes + # a test framework, both options are shown, but if a third one is + # involved, those options do not appear. # def self.class_options_help(shell, ungrouped_name=nil, extra_group=nil) - klass_options = Thor::CoreExt::OrderedHash.new + group_options = Thor::CoreExt::OrderedHash.new - invocations.each do |args| + get_options_from_invocations(group_options, class_options) do |klass| + klass.send(:get_options_from_invocations, group_options, class_options) + end + + group_options.merge!(extra_group) if extra_group + super(shell, ungrouped_name, group_options) + end + + # Get invocations array and merge options from invocations. Those + # options are added to group_options hash. Options that already exists + # in base_options are not added twice. + # + def self.get_options_from_invocations(group_options, base_options) + invocations.sort{ |a,b| a[0].to_s <=> b[0].to_s }.each do |args| name, base, generator = args option = class_options[name] @@ -330,15 +345,15 @@ module Rails next unless klass human_name = klass_name.to_s.classify + group_options[human_name] ||= [] - klass_options[human_name] ||= [] - klass_options[human_name] += klass.class_options.values.select do |option| - class_options[option.human_name.to_sym].nil? && option.group.nil? + group_options[human_name] += klass.class_options.values.select do |option| + base_options[option.name.to_sym].nil? && option.group.nil? && + !group_options[human_name].any? { |i| i.name == option.name } end - end - klass_options.merge!(extra_group) if extra_group - super(shell, ungrouped_name, klass_options) + yield klass if block_given? + end end # Small macro to add ruby as an option to the generator with proper diff --git a/railties/lib/generators/rails/model/model_generator.rb b/railties/lib/generators/rails/model/model_generator.rb index 36354c5638..e05c89517e 100644 --- a/railties/lib/generators/rails/model/model_generator.rb +++ b/railties/lib/generators/rails/model/model_generator.rb @@ -2,7 +2,7 @@ module Rails module Generators class ModelGenerator < NamedBase argument :attributes, :type => :hash, :default => {}, :banner => "field:type field:type" - hook_for :orm, :test_framework + hook_for :orm end end end diff --git a/railties/lib/generators/rails/observer/observer_generator.rb b/railties/lib/generators/rails/observer/observer_generator.rb index e33247959b..1d99f309e0 100644 --- a/railties/lib/generators/rails/observer/observer_generator.rb +++ b/railties/lib/generators/rails/observer/observer_generator.rb @@ -1,7 +1,7 @@ module Rails module Generators class ObserverGenerator < NamedBase - hook_for :orm, :test_framework + hook_for :orm end end end |