Class: Tokenable::Generators::VerifierGenerator

Inherits:
ActiveRecord::Generators::Base
  • Object
show all
Defined in:
lib/generators/tokenable/verifier_generator.rb

Instance Method Summary collapse

Instance Method Details

#add_migrationObject



25
26
27
# File 'lib/generators/tokenable/verifier_generator.rb', line 25

def add_migration
  migration_template 'verifier_migration.rb.erb', "db/migrate/add_tokenable_verifier_to_#{table_name}.rb"
end

#add_to_modelObject



14
15
16
17
18
19
20
21
22
23
# File 'lib/generators/tokenable/verifier_generator.rb', line 14

def add_to_model
  model_path = "app/models/#{file_name}.rb"
  already_injected = File.open(File.join(destination_root, model_path)).grep(/Tokenable::Verifier/).any?

  if already_injected
    say_status :skip, 'verifier is already in this model', :yellow
  else
    inject_into_file "app/models/#{file_name}.rb", "  include Tokenable::Verifier\n", after: " < ApplicationRecord\n"
  end
end

#generate_modelObject



10
11
12
# File 'lib/generators/tokenable/verifier_generator.rb', line 10

def generate_model
  invoke 'active_record:model', [name], migration: false unless model_exists? && behavior == :invoke
end