Class: TestUnit::Generators::ScaffoldGenerator
| Relationships & Source Files | |
| Super Chains via Extension / Inclusion / Inheritance | |
| 
         Class Chain: 
        
       | 
    |
| 
         Instance Chain: 
        
          self,
           
      ::Rails::Generators::ResourceHelpers,
          Base,
          ::Rails::Generators::NamedBase,
          ::Rails::Generators::Base,
          ::Rails::Generators::Actions,
          Thor::Actions,
          Thor::Group
         | 
    |
| Inherits: | 
        TestUnit::Generators::Base
        
  | 
    
| Defined in: | railties/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb | 
Class Attribute Summary
::Rails::Generators::Base - Inherited
Class Method Summary
::Rails::Generators::NamedBase - Inherited
| .check_class_collision | Add a class collisions name to be checked on class initialization.  | 
    
| .new | |
::Rails::Generators::Base - Inherited
| .base_root | Returns the base root for a common set of generators.  | 
    
| .default_source_root | Returns the default source root for a given generator.  | 
    
| .desc | Tries to get the description from a USAGE file one folder above the source root otherwise uses a default description.  | 
    
| .hide! | Convenience method to hide this generator from the available ones when running rails generator command.  | 
    
| .hook_for | Invoke a generator based on the value supplied by the user to the given option named “name”.  | 
    
| .namespace | Convenience method to get the namespace from the class name.  | 
    
| .remove_hook_for | Remove a previously added hook.  | 
    
| .source_root | Returns the source root for this generator using default_source_root as default.  | 
    
| .add_shebang_option! | Small macro to add ruby as an option to the generator with proper default value plus an instance helper method called shebang.  | 
    
| .banner | Use Rails default banner.  | 
    
| .base_name | Sets the base_name taking into account the current class namespace.  | 
    
| .default_aliases_for_option | Returns default aliases for the option name given doing a lookup in Rails::Generators.aliases.  | 
    
| .default_for_option | Returns default for the option name given doing a lookup in config.  | 
    
| .default_generator_root, | |
| .default_value_for_option | Returns the default value for the option name given doing a lookup in Rails::Generators.options.  | 
    
| .generator_name | Removes the namespaces and get the generator name.  | 
    
| .usage_path, | |
| .class_option | Make class option aware of Rails::Generators.options and Rails::Generators.aliases.  | 
    
| .inherited | Cache source root and add lib/generators/base/generator/templates to source paths.  | 
    
| .hooks | Keep hooks configuration that are used on prepare_for_invocation.  | 
    
| .prepare_for_invocation | Prepare class invocation to search on   | 
    
Instance Attribute Summary
::Rails::Generators::ResourceHelpers - Included
::Rails::Generators::NamedBase - Inherited
| #file_name, #inside_template, #inside_template?, #mountable_engine?, #pluralize_table_names?, #uncountable? | 
::Rails::Generators::Base - Inherited
Instance Method Summary
- #create_test_files
 - #fixture_name
 - #attributes_hash private
 - #attributes_string private
 - #boolean?(name) ⇒ Boolean private
 - #datetime?(name) ⇒ Boolean private
 - #time?(name) ⇒ Boolean private
 - #virtual?(name) ⇒ Boolean private
 
::Rails::Generators::ResourceHelpers - Included
| #initialize | Set controller variables on initialization.  | 
    
| #assign_controller_names!, #controller_class_name, #controller_class_path, #controller_file_path, #controller_i18n_scope, | |
| #orm_class | Loads the   | 
    
| #orm_instance | Initialize   | 
    
::Rails::Generators::NamedBase - Inherited
| #application_name | Tries to retrieve the application name or simply return application.  | 
    
| #assign_names!, #attributes_names, #class_name, #class_path, #edit_helper, #file_path, #fixture_file_name, #human_name, #i18n_scope, #index_helper, #model_resource_name, #namespaced_class_path, #new_helper, | |
| #parse_attributes! | Convert attributes array into GeneratedAttribute objects.  | 
    
| #plural_file_name, #plural_name, #plural_route_name, #plural_table_name, #redirect_resource_name, #regular_class_path, #route_url, #show_helper, | |
| #singular_name | FIXME: We are avoiding to use alias because a bug on thor that make this method public and add it to the task list.  | 
    
| #singular_route_name, #singular_table_name, #table_name, #url_helper_prefix | |
::Rails::Generators::Base - Inherited
| #class_collisions | Check whether the given class names are already taken by user application or Ruby on   | 
    
| #extract_last_module | Takes in an array of nested modules and extracts the last module.  | 
    
| #indent, | |
| #module_namespacing | Wrap block with namespace of current application if namespace exists and is not skipped.  | 
    
| #namespace, #namespace_dirs, #namespaced_path, #wrap_with_namespace | |
::Rails::Generators::Actions - Included
| #add_source | Add the given source to   | 
    
| #application | Alias for Rails::Generators::Actions#environment.  | 
    
| #environment | Adds configuration code to a Rails runtime environment.  | 
    
| #gem | Adds a   | 
    
| #gem_group | Wraps gem entries inside a group.  | 
    
| #generate | Runs another generator.  | 
    
| #git | Runs one or more git commands.  | 
    
| #github, | |
| #initializer | Creates an initializer file in   | 
    
| #lib | Creates a file in   | 
    
| #rails_command | Runs the specified Rails command.  | 
    
| #rake | Runs the specified Rake task.  | 
    
| #rakefile | Creates a Rake tasks file in   | 
    
| #readme | Reads the given file at the source root and prints it in the console.  | 
    
| #route | Make an entry in Rails routing file   | 
    
| #vendor | Creates a file in   | 
    
| #append_file_with_newline | Append string to a file with a newline if necessary.  | 
    
| #execute_command | Runs the supplied command using either   | 
    
| #indentation | Returns a string corresponding to the current indentation level (i.e. 2 *   | 
    
| #log | Define log for backwards compatibility.  | 
    
| #match_file, | |
| #optimize_indentation | Returns optimized string with indentation.  | 
    
| #quote | Always returns value in double quotes.  | 
    
| #rebase_indentation | |
| #route_namespace_pattern, | |
| #with_indentation | Increases the current indentation indentation level for the duration of the given block, and decreases it after the block ends.  | 
    
| #initialize | |
Constructor Details
This class inherits a constructor from Rails::Generators::NamedBase
Instance Method Details
#attributes_hash (private)
[ GitHub ]# File 'railties/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb', line 51
def attributes_hash return {} if attributes_names.empty? attributes_names.filter_map do |name| if %w(password password_confirmation).include?(name) && attributes.any?(&:password_digest?) ["#{name}", '"secret"'] elsif !virtual?(name) ["#{name}", "@#{singular_table_name}.#{name}"] end end.sort.to_h end
#attributes_string (private)
[ GitHub ]# File 'railties/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb', line 43
def attributes_string if attributes_hash.empty? "{}" else "{ #{attributes_hash.map { |k, v| "#{k}: #{v}" }.join(", ")} }" end end
    #boolean?(name)  ⇒ Boolean  (private)
  
# File 'railties/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb', line 63
def boolean?(name) attribute = attributes.find { |attr| attr.name == name } attribute&.type == :boolean end
#create_test_files
[ GitHub ]# File 'railties/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb', line 21
def create_test_files template_file = .api? ? "api_functional_test.rb" : "functional_test.rb" template template_file, File.join("test/controllers", controller_class_path, "#{controller_file_name}_controller_test.rb") # Generate system tests if this isn't an API only app and the system # tests option is true if !.api? && [:system_tests] == "true" template "system_test.rb", File.join("test/system", class_path, "#{file_name.pluralize}_test.rb") end end
    #datetime?(name)  ⇒ Boolean  (private)
  
# File 'railties/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb', line 73
def datetime?(name) attribute = attributes.find { |attr| attr.name == name } attribute&.type == :datetime end
#fixture_name
[ GitHub ]# File 'railties/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb', line 33
def fixture_name @fixture_name ||= if mountable_engine? (namespace_dirs + [table_name]).join("_") else table_name end end
    #time?(name)  ⇒ Boolean  (private)
  
# File 'railties/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb', line 78
def time?(name) attribute = attributes.find { |attr| attr.name == name } attribute&.type == :time end
    #virtual?(name)  ⇒ Boolean  (private)
  
# File 'railties/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb', line 68
def virtual?(name) attribute = attributes.find { |attr| attr.name == name } attribute&.virtual? end