Class: Seedie::Generators::InstallGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Includes:
PolymorphicAssociationHelper
Defined in:
lib/generators/seedie/install_generator.rb

Constant Summary collapse

EXCLUDED_MODELS =
%w[
  ActiveRecord::SchemaMigration
  ActiveRecord::InternalMetadata
  ActiveStorage::Attachment
  ActiveStorage::Blob
  ActiveStorage::VariantRecord
  ActionText::RichText
  ActionMailbox::InboundEmail
  ActionText::EncryptedRichText
].freeze

Instance Method Summary collapse

Methods included from PolymorphicAssociationHelper

#find_polymorphic_types, #has_association?, #select_associations

Instance Method Details

#generate_seedie_file(output = $stdout) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/generators/seedie/install_generator.rb', line 30

def generate_seedie_file(output = $stdout)
  if options[:include_only_models].present? && options[:excluded_models].present?
    raise ArgumentError, "Cannot use both --include_only_models and --excluded_models together."
  end

  # This needs to be generated before anything else.
  template "seedie_initializer.rb", "config/initializers/seedie.rb"

  @excluded_models = options[:excluded_models] + EXCLUDED_MODELS
  @output = output

  if options[:blank]
    template "blank_seedie.yml", "config/seedie.yml"
  else
    Rails.application.eager_load! # Load all models. This is required!!

    @models = collect_models
    @models_config = build_models_config
    template "seedie.yml", "config/seedie.yml"
  end

  output_seedie_warning
end