Class: Nyauth::NyauthGenerator
- Inherits:
-
ActiveRecord::Generators::Base
- Object
- ActiveRecord::Generators::Base
- Nyauth::NyauthGenerator
- Defined in:
- lib/generators/nyauth/nyauth_generator.rb
Instance Method Summary collapse
- #copy_nyauth_migration ⇒ Object
- #inject_devise_content ⇒ Object
- #migration_data ⇒ Object
- #model_contents ⇒ Object
Instance Method Details
#copy_nyauth_migration ⇒ Object
6 7 8 |
# File 'lib/generators/nyauth/nyauth_generator.rb', line 6 def copy_nyauth_migration migration_template "migration.rb", "db/migrate/add_nyauth_to_#{table_name}.rb" end |
#inject_devise_content ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/generators/nyauth/nyauth_generator.rb', line 10 def inject_devise_content content = model_contents class_path = if namespaced? class_name.to_s.split("::") else [class_name] end indent_depth = class_path.size - 1 content = content.split("\n").map { |line| " " * indent_depth + line } .join("\n") << "\n" inject_into_class(model_path, class_path.last, content) if model_exists? end |
#migration_data ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/generators/nyauth/nyauth_generator.rb', line 25 def migration_data <<RUBY # Authenticatable t.string :email, null: false t.string :password_digest, null: false t.string :password_salt, null: false t.string :reset_password_key t.datetime :reset_password_key_expired_at # Confirmable #t.datetime :confirmed_at #t.string :confirmation_key #t.datetime :confirmation_key_expired_at RUBY end |
#model_contents ⇒ Object
40 41 42 43 44 45 |
# File 'lib/generators/nyauth/nyauth_generator.rb', line 40 def model_contents <<RUBY include Nyauth::Authenticatable #include Nyauth::Confirmable RUBY end |