class ActiveRecord::Generators::ModelGenerator
:nodoc:
:nodoc:
def abstract_class_name
def abstract_class_name "#{database.camelize}Record" end
def attributes_with_index
def attributes_with_index attributes.select { |a| !a.reference? && a.has_index? } end
def create_migration_file
def create_migration_file return if skip_migration_creation? attributes.each { |a| a.attr_options.delete(:index) if a.reference? && !a.has_index? } if options[:indexes] == false migration_template "create_table_migration.rb", File.join(db_migrate_path, "create_#{table_name}.rb") end
def create_model_file
def create_model_file generate_abstract_class if database && !custom_parent? template "model.rb", File.join("app/models", class_path, "#{file_name}.rb") end
def create_module_file
def create_module_file return if regular_class_path.empty? template "module.rb", File.join("app/models", "#{class_path.join('/')}.rb") if behavior == :invoke end
def custom_parent?
def custom_parent? parent != self.class.class_options[:parent].default end
def database
def database options[:database] end
def generate_abstract_class
def generate_abstract_class path = File.join("app/models", "#{database.underscore}_record.rb") return if File.exist?(path) template "abstract_base_class.rb", path end
def migration
def migration options[:migration] end
def parent
def parent options[:parent] end
def parent_class_name
def parent_class_name if custom_parent? parent elsif database abstract_class_name else parent end end
def skip_migration_creation?
- options parent is present and database option is not present
Skip creating migration file if:
def skip_migration_creation? custom_parent? && !database || !migration end