Class: Caffeinate::Generators::InstallGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Caffeinate::Generators::InstallGenerator
- Defined in:
- lib/generators/caffeinate/install_generator.rb
Overview
Installs Caffeinate
Class Method Summary collapse
Instance Method Summary collapse
-
#copy_application_campaign ⇒ Object
:nodoc:.
-
#copy_initializer ⇒ Object
:nodoc:.
-
#copy_migrations ⇒ Object
:nodoc:.
- #install_routes ⇒ Object
- #migration_version ⇒ Object
- #rails5_and_up? ⇒ Boolean
Class Method Details
.next_migration_number(_path) ⇒ Object
:nodoc:
26 27 28 29 30 31 32 33 |
# File 'lib/generators/caffeinate/install_generator.rb', line 26 def self.next_migration_number(_path) if @prev_migration_nr @prev_migration_nr += 1 else @prev_migration_nr = Time.now.utc.strftime('%Y%m%d%H%M%S').to_i end @prev_migration_nr.to_s end |
Instance Method Details
#copy_application_campaign ⇒ Object
:nodoc:
17 18 19 |
# File 'lib/generators/caffeinate/install_generator.rb', line 17 def copy_application_campaign template 'application_dripper.rb', 'app/drippers/application_dripper.rb' end |
#copy_initializer ⇒ Object
:nodoc:
12 13 14 |
# File 'lib/generators/caffeinate/install_generator.rb', line 12 def copy_initializer template 'caffeinate.rb', 'config/initializers/caffeinate.rb' end |
#copy_migrations ⇒ Object
:nodoc:
46 47 48 49 50 |
# File 'lib/generators/caffeinate/install_generator.rb', line 46 def copy_migrations template 'migrations/create_caffeinate_campaigns.rb', "db/migrate/#{self.class.next_migration_number("")}_create_caffeinate_campaigns.rb" template 'migrations/create_caffeinate_campaign_subscriptions.rb', "db/migrate/#{self.class.next_migration_number("")}_create_caffeinate_campaign_subscriptions.rb" template 'migrations/create_caffeinate_mailings.rb', "db/migrate/#{self.class.next_migration_number("")}_create_caffeinate_mailings.rb" end |
#install_routes ⇒ Object
21 22 23 |
# File 'lib/generators/caffeinate/install_generator.rb', line 21 def install_routes inject_into_file 'config/routes.rb', "\n mount ::Caffeinate::Engine => '/caffeinate'", after: /Rails.application.routes.draw do/ end |
#migration_version ⇒ Object
35 36 37 38 39 |
# File 'lib/generators/caffeinate/install_generator.rb', line 35 def migration_version if rails5_and_up? "[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]" end end |
#rails5_and_up? ⇒ Boolean
41 42 43 |
# File 'lib/generators/caffeinate/install_generator.rb', line 41 def rails5_and_up? Rails::VERSION::MAJOR >= 5 end |