class ActiveRecord::Generators::ModelGenerator

Public Instance Methods

append_schema_file() click to toggle source
# File lib/core_ext/active_record.rb, line 12
def append_schema_file
  attributes.each { |a| a.attr_options.delete(:index) if a.reference? && !a.has_index? } if options[:indexes] == false
  append_file schema_file, schema_template(File.expand_path('../templates/schemafile.rb', __dir__)), { verbose: false }
end

Private Instance Methods

schema_file() click to toggle source
# File lib/core_ext/active_record.rb, line 28
def schema_file
  not_found = Proc.new { return }
  [Rails.root.join('db', 'Schemafile.rb'), ENV['SCHEMA_FILE']].find(not_found) { |f| File.file? f }
end
schema_template(source) click to toggle source
# File lib/core_ext/active_record.rb, line 19
def schema_template(source)
  context = instance_eval("binding")
  if ERB.instance_method(:initialize).parameters.assoc(:key) # Ruby 2.6+
    ERB.new(::File.binread(source), trim_mode: "-", eoutvar: "@output_buffer").result(context)
  else
    ERB.new(::File.binread(source), nil, "-", "@output_buffer").result(context)
  end
end