Class: Trestle::Auth::Otp::Generators::InstallGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Includes:
Rails::Generators::Migration
Defined in:
lib/generators/trestle/auth/otp/install/install_generator.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.next_migration_number(dirname) ⇒ Object



51
52
53
54
# File 'lib/generators/trestle/auth/otp/install/install_generator.rb', line 51

def self.next_migration_number(dirname)
  next_migration_number = current_migration_number(dirname) + 1
  ActiveRecord::Migration.next_migration_number(next_migration_number)
end

Instance Method Details

#check_trestle_installedObject



17
18
19
20
21
# File 'lib/generators/trestle/auth/otp/install/install_generator.rb', line 17

def check_trestle_installed
  unless ::File.exist?("config/initializers/trestle.rb")
    raise Thor::Error, "The file config/initializers/trestle.rb does not appear to exist. Please run `trestle:install` first."
  end
end

#devise?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/generators/trestle/auth/otp/install/install_generator.rb', line 47

def devise?
  options[:devise]
end

#generate_adminObject



33
34
35
# File 'lib/generators/trestle/auth/otp/install/install_generator.rb', line 33

def generate_admin
  generate "trestle:auth:otp:admin", model, ("--devise" if devise?)
end

#generate_migrationObject



37
38
39
40
41
42
43
44
45
# File 'lib/generators/trestle/auth/otp/install/install_generator.rb', line 37

def generate_migration
  filename = 'migration.rb'
  path = File.expand_path(find_in_source_paths(filename.to_s))
  text = File.read(path)
  content = text.gsub('[]', "[#{ActiveRecord::Migration.current_version}]")
  File.open(path, "w") { |file| file << content }

  migration_template(filename, "db/migrate/add_otp_fields.rb")
end

#generate_modelObject



29
30
31
# File 'lib/generators/trestle/auth/otp/install/install_generator.rb', line 29

def generate_model
  generate "trestle:auth:otp:model", model unless devise?
end

#insert_configurationObject



23
24
25
26
27
# File 'lib/generators/trestle/auth/otp/install/install_generator.rb', line 23

def insert_configuration
  inject_into_file "config/initializers/trestle.rb", before: /^end/ do
    format_configuration(template_content("basic.rb.erb"))
  end
end