Class: PhrasingGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Includes:
Rails::Generators::Migration
Defined in:
lib/generators/phrasing/phrasing_generator.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.next_migration_number(path) ⇒ Object



22
23
24
25
# File 'lib/generators/phrasing/phrasing_generator.rb', line 22

def self.next_migration_number(path)
  sleep 1 # migration numbers should differentiate
  Time.now.utc.strftime("%Y%m%d%H%M%S")
end

Instance Method Details

#create_helper_fileObject



10
11
12
13
# File 'lib/generators/phrasing/phrasing_generator.rb', line 10

def create_helper_file
  helper_location = "app/helpers/phrasing_helper.rb"
  copy_file helper_location, helper_location
end

#create_initializer_fileObject



5
6
7
8
# File 'lib/generators/phrasing/phrasing_generator.rb', line 5

def create_initializer_file
  initializer_location = "config/initializers/phrasing.rb"
  copy_file initializer_location, initializer_location
end

#create_migrationsObject



15
16
17
18
19
20
# File 'lib/generators/phrasing/phrasing_generator.rb', line 15

def create_migrations
  phrasing_phrase_migration = "db/migrate/create_phrasing_phrases.rb"
  migration_template phrasing_phrase_migration, phrasing_phrase_migration
  phrase_versions_migration = "db/migrate/create_phrasing_phrase_versions.rb"
  migration_template phrase_versions_migration, phrase_versions_migration
end

#migration_versionObject



27
28
29
30
31
# File 'lib/generators/phrasing/phrasing_generator.rb', line 27

def migration_version
  if rails5?
    "[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]"
  end
end

#rails5?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/generators/phrasing/phrasing_generator.rb', line 33

def rails5?
  Rails.version.start_with? '5'
end