Class: DeviseMultipleTokenAuth::InstallGenerator

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.next_migration_number(path) ⇒ Object



11
12
13
14
# File 'lib/generators/devise_multiple_token_auth/install_generator.rb', line 11

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

Instance Method Details

#copy_initializerObject



26
27
28
# File 'lib/generators/devise_multiple_token_auth/install_generator.rb', line 26

def copy_initializer
  template "devise_multiple_token_auth.rb", "config/initializers/devise_multiple_token_auth.rb"
end

#create_migrationsObject



30
31
32
33
34
35
36
37
38
39
# File 'lib/generators/devise_multiple_token_auth/install_generator.rb', line 30

def create_migrations
  filepath = "#{self.class.source_root}/migrations/create_devise_multiple_token_auth_devices.rb"
  name = File.basename(filepath)
  migration_template "migrations/#{name}", "db/migrate/#{name}"

  # Dir["#{self.class.source_root}/migrations/*.rb"].sort.each do |filepath|
  #   name = File.basename(filepath)
  #   migration_template "migrations/#{name}", "db/migrate/#{name}"
  # end
end

#insert_into_user_modelObject



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

def insert_into_user_model
  inject_into_file "app/models/user.rb", after: /^class\sUser < ActiveRecord::Base/ do
    <<-'RUBY'

  # Allows token auth devices to be created by calling user.create_device
  devise_token_authenticatable
    RUBY
  end
end