Class: Caffeinate::Generators::InstallGenerator

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

Overview

Installs Caffeinate

Class Method Summary collapse

Instance Method Summary collapse

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_campaignObject

: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_initializerObject

: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_migrationsObject

: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_routesObject



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_versionObject



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

Returns:

  • (Boolean)


41
42
43
# File 'lib/generators/caffeinate/install_generator.rb', line 41

def rails5_and_up?
  Rails::VERSION::MAJOR >= 5
end