Class: Sufia::Models::InstallGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Sufia::Models::InstallGenerator
- Includes:
- Rails::Generators::Migration
- Defined in:
- lib/generators/sufia/models/install_generator.rb
Class Method Summary collapse
-
.next_migration_number(path) ⇒ Object
Implement the required interface for Rails::Generators::Migration.
Instance Method Summary collapse
-
#copy_migrations ⇒ Object
Setup the database migrations.
- #create_configuration_files ⇒ Object
-
#inject_sufia_solr_document_behavior ⇒ Object
Add behaviors to the SolrDocument model.
-
#inject_sufia_user_behavior ⇒ Object
Add behaviors to the user model.
- #install_mailboxer ⇒ Object
Class Method Details
.next_migration_number(path) ⇒ Object
Implement the required interface for Rails::Generators::Migration. taken from github.com/rails/rails/blob/master/activerecord/lib/generators/active_record.rb
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/generators/sufia/models/install_generator.rb', line 22 def self.next_migration_number(path) if @prev_migration_nr @prev_migration_nr += 1 else if last_migration = Dir[File.join(path, '*.rb')].sort.last @prev_migration_nr = last_migration.sub(File.join(path, '/'), '').to_i + 1 else @prev_migration_nr = Time.now.utc.strftime("%Y%m%d%H%M%S").to_i end end @prev_migration_nr.to_s end |
Instance Method Details
#copy_migrations ⇒ Object
Setup the database migrations
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/generators/sufia/models/install_generator.rb', line 36 def copy_migrations # Can't get this any more DRY, because we need this order. [ "acts_as_follower_migration.rb", "add_social_to_users.rb", "create_single_use_links.rb", "add_ldap_attrs_to_user.rb", "add_avatars_to_users.rb", "create_checksum_audit_logs.rb", "create_version_committers.rb", "add_groups_to_users.rb", "create_local_authorities.rb", "create_trophies.rb" ].each do |file| better_migration_template file end end |
#create_configuration_files ⇒ Object
67 68 69 70 71 72 73 |
# File 'lib/generators/sufia/models/install_generator.rb', line 67 def create_configuration_files copy_file "config/sufia.rb", "config/initializers/sufia.rb" copy_file "config/redis.yml", "config/redis.yml" copy_file "config/redis_config.rb", "config/initializers/redis_config.rb" copy_file "config/resque_admin.rb", "config/initializers/resque_admin.rb" copy_file "config/resque_config.rb", "config/initializers/resque_config.rb" end |
#inject_sufia_solr_document_behavior ⇒ Object
Add behaviors to the SolrDocument model
76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/generators/sufia/models/install_generator.rb', line 76 def inject_sufia_solr_document_behavior file_path = "app/models/solr_document.rb" if File.exists?(file_path) inject_into_class file_path, "SolrDocument" do " # Adds Sufia behaviors to the SolrDocument.\n" + " include Sufia::SolrDocumentBehavior\n" end else puts " \e[31mFailure\e[0m Sufia requires a SolrDocument object. This generators assumes that the model is defined in the file #{file_path}, which does not exist." end end |
#inject_sufia_user_behavior ⇒ Object
Add behaviors to the user model
55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/generators/sufia/models/install_generator.rb', line 55 def inject_sufia_user_behavior file_path = "app/models/#{model_name.underscore}.rb" if File.exists?(file_path) inject_into_class file_path, model_name.classify do "# Connects this user object to Sufia behaviors. " + "\n include Sufia::User\n" end else puts " \e[31mFailure\e[0m Sufia requires a user object. This generators assumes that the model is defined in the file #{file_path}, which does not exist. If you used a different name, please re-run the generator and provide that name as an argument. Such as \b rails -g sufia client" end end |
#install_mailboxer ⇒ Object
88 89 90 |
# File 'lib/generators/sufia/models/install_generator.rb', line 88 def install_mailboxer generate "mailboxer:install" end |