class Rails::Generators::RidgepoleGenerator

Constants

IGNORE_ATTRIBUTE_OPTIONS

Public Class Methods

source_paths() click to toggle source
# File lib/generators/rails/ridgepole/ridgepole_generator.rb, line 10
def self.source_paths
  [ActiveRecord::Generators::ModelGenerator.source_root, File.expand_path('../templates', __FILE__)]
end

Public Instance Methods

create_migration_file() click to toggle source
# File lib/generators/rails/ridgepole/ridgepole_generator.rb, line 14
def create_migration_file
  return unless options[:migration] && options[:parent].nil?
  attributes.each { |a| a.attr_options.delete(:index) if a.reference? && !a.has_index? } if options[:indexes] == false

  template 'schema.rb', File.join('db/schema', class_path, "#{file_name}.rb")
end

Private Instance Methods

options_for_attribute(attribute) click to toggle source
# File lib/generators/rails/ridgepole/ridgepole_generator.rb, line 23
def options_for_attribute(attribute)
  opts = attribute.options_for_migration.
    except(*IGNORE_ATTRIBUTE_OPTIONS).
    map { |k, v| "#{k}: #{v.inspect}" }.
    join(', ')

  opts.present? ? ", #{opts}" : ""
end