Class: Settings::InstallGenerator

Inherits:
Rails::Generators::NamedBase
  • Object
show all
Includes:
Rails::Generators::Migration
Defined in:
lib/generators/settings/install_generator.rb

Constant Summary collapse

@@migrations =
false

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.next_migration_number(dirname) ⇒ Object

:nodoc:



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/generators/settings/install_generator.rb', line 15

def self.next_migration_number(dirname) #:nodoc:
  if ActiveRecord::Base.timestamped_migrations
    if @@migrations
      (current_migration_number(dirname) + 1)
    else
      @@migrations = true
      Time.now.utc.strftime("%Y%m%d%H%M%S")
    end
  else
    format "%.3d", current_migration_number(dirname) + 1
  end
end

Instance Method Details

#install_settingObject



28
29
30
31
32
# File 'lib/generators/settings/install_generator.rb', line 28

def install_setting
  template "model.rb", File.join("app/models", class_path, "#{file_name}.rb")
  template "app.yml", File.join("config", "app.yml")
  migration_template "migration.rb", "db/migrate/create_settings.rb", migration_version: migration_version
end

#migration_versionObject



38
39
40
# File 'lib/generators/settings/install_generator.rb', line 38

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

#rails5?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/generators/settings/install_generator.rb', line 34

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