Class: Sequel::Generators::DeviseGenerator

Inherits:
Rails::Generators::NamedBase
  • Object
show all
Includes:
Devise::Generators::OrmHelpers, Rails::Generators::Migration
Defined in:
lib/sequel/devise/generators/devise_generator.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.next_migration_number(path) ⇒ Object



18
19
20
# File 'lib/sequel/devise/generators/devise_generator.rb', line 18

def self.next_migration_number(path)
  Sequel::Generators::Base.next_migration_number(path)
end

Instance Method Details

#class_partsObject



46
47
48
49
50
51
52
# File 'lib/sequel/devise/generators/devise_generator.rb', line 46

def class_parts
  if namespaced?
    class_name.to_s.split("::")
  else
    [class_name]
  end
end

#copy_devise_migrationObject



22
23
24
25
26
27
28
# File 'lib/sequel/devise/generators/devise_generator.rb', line 22

def copy_devise_migration
  if (behavior == :invoke && model_exists?) || (behavior == :revoke && migration_exists?(table_name))
    migration_template "migration_existing.rb.erb", "db/migrate/add_devise_to_#{table_name}"
  else
    migration_template "migration.rb.erb", "db/migrate/devise_create_#{table_name}"
  end
end

#generate_modelObject



30
31
32
# File 'lib/sequel/devise/generators/devise_generator.rb', line 30

def generate_model
  invoke "sequel:model", [name], :migration => false unless model_exists? && behavior == :invoke
end

#indent_depthObject



54
55
56
# File 'lib/sequel/devise/generators/devise_generator.rb', line 54

def indent_depth
  class_parts.size - 1
end

#inject_devise_contentObject



34
35
36
37
# File 'lib/sequel/devise/generators/devise_generator.rb', line 34

def inject_devise_content
  content = ("#{sequel_plugins}#{model_contents}").split("\n").map { |line| "  " * indent_depth + line } .join("\n") << "\n"
  inject_into_class(model_path, class_parts.last, content) if model_exists?
end

#migration_dataObject



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/sequel/devise/generators/devise_generator.rb', line 58

def migration_data
"## Database authenticatable\nString :email,              :null => false, :default => \"\"\nString :encrypted_password, :null => false, :default => \"\"\n\n## Recoverable\nString :reset_password_token\nString :reset_password_sent_at\n\n## Rememberable\nDateTime :remember_created_at\n\n## Trackable\nInteger  :sign_in_count, :default => 0, :null => false\nDateTime :current_sign_in_at\nDateTime :last_sign_in_at\nString   :current_sign_in_ip\nString   :last_sign_in_ip\n\n## Confirmable\n# String   :confirmation_token\n# DateTime :confirmed_at\n# DateTime :confirmation_sent_at\n# String   :unconfirmed_email # Only if using reconfirmable\n\n## Lockable\n# Integer  :failed_attempts, :default => 0, :null => false # Only if lock strategy is :failed_attempts\n# String   :unlock_token # Only if unlock strategy is :email or :both\n# DateTime :locked_at\n"
end

#sequel_pluginsObject



39
40
41
42
43
44
# File 'lib/sequel/devise/generators/devise_generator.rb', line 39

def sequel_plugins
  [
    ':devise', 
    ':timestamps, :update_on_create => true'
  ].map { |p| "  plugin #{p}\n" }.join('')
end