Class: Trestle::Auth::Otp::Generators::InstallGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Trestle::Auth::Otp::Generators::InstallGenerator
- Includes:
- Rails::Generators::Migration
- Defined in:
- lib/generators/trestle/auth/otp/install/install_generator.rb
Class Method Summary collapse
Instance Method Summary collapse
- #check_trestle_installed ⇒ Object
- #devise? ⇒ Boolean
- #generate_admin ⇒ Object
- #generate_migration ⇒ Object
- #generate_model ⇒ Object
- #insert_configuration ⇒ Object
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_installed ⇒ Object
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
47 48 49 |
# File 'lib/generators/trestle/auth/otp/install/install_generator.rb', line 47 def devise? [:devise] end |
#generate_admin ⇒ Object
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_migration ⇒ Object
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.(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_model ⇒ Object
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_configuration ⇒ Object
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 |