Class: Rails::Generators::NamedBase
- Defined in:
- lib/rails/generators/named_base.rb
Direct Known Subclasses
Erb::Generators::Base, BenchmarkGenerator, ControllerGenerator, GeneratorGenerator, HelperGenerator, IntegrationTestGenerator, MigrationGenerator, ModelGenerator, ResourceRouteGenerator, ScaffoldControllerGenerator, ScriptGenerator, SystemTestGenerator, TaskGenerator, TestUnit::Generators::Base
Class Method Summary collapse
-
.check_class_collision(options = {}) ⇒ Object
Add a class collisions name to be checked on class initialization.
Instance Method Summary collapse
-
#initialize(args, *options) ⇒ NamedBase
constructor
:nodoc:.
Methods inherited from Base
add_shebang_option!, banner, base_name, base_root, class_option, default_aliases_for_option, default_for_option, default_generator_root, default_source_root, default_value_for_option, desc, exit_on_failure?, generator_name, hide!, hook_for, hooks, inherited, namespace, prepare_for_invocation, remove_hook_for, source_root, usage_path
Methods included from Actions
#add_source, #environment, #gem, #gem_group, #generate, #git, #github, #initializer, #lib, #rails_command, #rake, #rakefile, #readme, #route, #vendor
Constructor Details
#initialize(args, *options) ⇒ NamedBase
:nodoc:
11 12 13 14 15 16 17 18 |
# File 'lib/rails/generators/named_base.rb', line 11 def initialize(args, *) # :nodoc: @inside_template = nil # Unfreeze name in case it's given as a frozen string args[0] = args[0].dup if args[0].is_a?(String) && args[0].frozen? super assign_names!(name) parse_attributes! if respond_to?(:attributes) end |
Class Method Details
.check_class_collision(options = {}) ⇒ Object
Add a class collisions name to be checked on class initialization. You can supply a hash with a :prefix or :suffix to be tested.
Examples
check_class_collision suffix: "Decorator"
If the generator is invoked with class name Admin, it will check for the presence of “AdminDecorator”.
214 215 216 217 218 219 220 221 222 223 224 |
# File 'lib/rails/generators/named_base.rb', line 214 def self.check_class_collision( = {}) # :doc: define_method :check_class_collision do name = if respond_to?(:controller_class_name, true) # for ResourceHelpers controller_class_name else class_name end class_collisions "#{options[:prefix]}#{name}#{options[:suffix]}" end end |