Class: DatashiftJourney::SetupGenerator
- Inherits:
-
Rails::Generators::NamedBase
- Object
- Rails::Generators::NamedBase
- DatashiftJourney::SetupGenerator
- Defined in:
- lib/generators/datashift_journey/setup/setup_generator.rb
Instance Method Summary collapse
- #add_engine_to_routes ⇒ Object
- #create_files ⇒ Object
-
#generate_model ⇒ Object
This class automatically runs every method defined in it,.
Instance Method Details
#add_engine_to_routes ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/generators/datashift_journey/setup/setup_generator.rb', line 23 def add_engine_to_routes return if File.readlines(File.join(destination_root, "config/routes.rb")).grep(/mount DatashiftJourney::Engine =>/).present? route("mount DatashiftJourney::Engine => '/journey'") puts '*' * 50 puts "We added the following line to your application's config/routes.rb file:\n" puts " mount DatashiftJourney::Engine => '/journey'" end |
#create_files ⇒ Object
19 20 21 |
# File 'lib/generators/datashift_journey/setup/setup_generator.rb', line 19 def create_files template 'initializer.rb', 'config/initializers/datashift_journey.rb' end |
#generate_model ⇒ Object
This class automatically runs every method defined in it,
9 10 11 12 13 14 15 16 17 |
# File 'lib/generators/datashift_journey/setup/setup_generator.rb', line 9 def generate_model Rails::Generators.invoke "active_record:model", [name, 'state:string', 'reference:string:index:unique'], migration: [:migration] unless model_exists? && behavior == :invoke plan = File.open(File.join(SetupGenerator.source_root, "model_concern.rb.tt")).read inject_into_file model_path, :after => /class.* < ApplicationRecord/ do "\n\tinclude DatashiftJourney::ReferenceGenerator.new(prefix: 'C')\n\tvalidates_presence_of :reference\n\tvalidates_uniqueness_of :reference\n\n#{plan}" end end |