Class: Sorcery::Generators::InstallGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Sorcery::Generators::InstallGenerator
- Includes:
- Rails::Generators::Migration, Helpers
- Defined in:
- lib/generators/sorcery/install_generator.rb
Class Method Summary collapse
-
.next_migration_number(dirname) ⇒ Object
Define the next_migration_number method (necessary for the migration_template method to work).
Instance Method Summary collapse
- #configure_initializer_file ⇒ Object
- #configure_model ⇒ Object
-
#copy_initializer_file ⇒ Object
Copy the initializer file to config/initializers folder.
-
#copy_migration_files ⇒ Object
Copy the migrations files to db/migrate folder.
- #inject_sorcery_to_model ⇒ Object
Class Method Details
.next_migration_number(dirname) ⇒ Object
Define the next_migration_number method (necessary for the migration_template method to work)
70 71 72 73 74 75 76 77 |
# File 'lib/generators/sorcery/install_generator.rb', line 70 def self.next_migration_number(dirname) if ActiveRecord::Base. sleep 1 # make sure each time we get a different timestamp Time.new.utc.strftime("%Y%m%d%H%M%S") else "%.3d" % (current_migration_number(dirname) + 1) end end |
Instance Method Details
#configure_initializer_file ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/generators/sorcery/install_generator.rb', line 26 def configure_initializer_file # Add submodules to the initializer file. if submodules submodule_names = submodules.collect{ |submodule| ':' + submodule } gsub_file sorcery_config_path, /submodules = \[.*\]/ do |str| current_submodule_names = (str =~ /\[(.*)\]/ ? $1 : '').delete(' ').split(',') "submodules = [#{(current_submodule_names | submodule_names).join(', ')}]" end end end |
#configure_model ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/generators/sorcery/install_generator.rb', line 38 def configure_model # Generate the model and add 'authenticates_with_sorcery!' unless you passed --migrations unless [:migrations] generate "model #{model_class_name} --skip-migration" inject_sorcery_to_model end end |
#copy_initializer_file ⇒ Object
Copy the initializer file to config/initializers folder.
22 23 24 |
# File 'lib/generators/sorcery/install_generator.rb', line 22 def copy_initializer_file template "initializer.rb", sorcery_config_path unless [:migrations] end |
#copy_migration_files ⇒ Object
Copy the migrations files to db/migrate folder
54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/generators/sorcery/install_generator.rb', line 54 def copy_migration_files # Copy core migration file in all cases except when you pass --migrations. return unless defined?(Sorcery::Generators::InstallGenerator::ActiveRecord) migration_template "migration/core.rb", "db/migrate/sorcery_core.rb" unless [:migrations] if submodules submodules.each do |submodule| unless submodule == "http_basic_auth" || submodule == "session_timeout" || submodule == "core" migration_template "migration/#{submodule}.rb", "db/migrate/sorcery_#{submodule}.rb" end end end end |
#inject_sorcery_to_model ⇒ Object
47 48 49 50 51 |
# File 'lib/generators/sorcery/install_generator.rb', line 47 def inject_sorcery_to_model indents = " " * (namespaced? ? 2 : 1) inject_into_class(model_path, model_class_name, "#{indents}authenticates_with_sorcery!\n") end |