Class: SufiaGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- SufiaGenerator
- Includes:
- Rails::Generators::Migration
- Defined in:
- lib/generators/sufia/sufia_generator.rb
Class Method Summary collapse
-
.next_migration_number(path) ⇒ Object
Implement the required interface for Rails::Generators::Migration.
Instance Method Summary collapse
- #catalog_controller ⇒ Object
-
#copy_migrations ⇒ Object
Setup the database migrations.
- #create_configuration_files ⇒ Object
-
#inject_routes ⇒ Object
The engine routes have to come after the devise routes so that /users/sign_in will work.
-
#inject_sufia_controller_behavior ⇒ Object
Add behaviors to the application controller.
-
#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
24 25 26 27 28 29 30 31 |
# File 'lib/generators/sufia/sufia_generator.rb', line 24 def self.next_migration_number(path) unless @prev_migration_nr @prev_migration_nr = Time.now.utc.strftime("%Y%m%d%H%M%S").to_i else @prev_migration_nr += 1 end @prev_migration_nr.to_s end |
Instance Method Details
#catalog_controller ⇒ Object
78 79 80 |
# File 'lib/generators/sufia/sufia_generator.rb', line 78 def catalog_controller copy_file "catalog_controller.rb", "app/controllers/catalog_controller.rb" end |
#copy_migrations ⇒ Object
Setup the database migrations
34 35 36 37 38 39 40 41 |
# File 'lib/generators/sufia/sufia_generator.rb', line 34 def copy_migrations # Can't get this any more DRY, because we need this order. %w{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 |f| better_migration_template f end end |
#create_configuration_files ⇒ Object
71 72 73 74 75 76 |
# File 'lib/generators/sufia/sufia_generator.rb', line 71 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" end |
#inject_routes ⇒ Object
The engine routes have to come after the devise routes so that /users/sign_in will work
84 85 86 87 88 89 90 91 92 93 |
# File 'lib/generators/sufia/sufia_generator.rb', line 84 def inject_routes routing_code = "Hydra::BatchEdit.add_routes(self)" sentinel = /HydraHead.add_routes\(self\)/ inject_into_file 'config/routes.rb', "\n #{routing_code}\n", { :after => sentinel, :verbose => false } routing_code = "mount Sufia::Engine => '/'" sentinel = /devise_for :users/ inject_into_file 'config/routes.rb', "\n #{routing_code}\n", { :after => sentinel, :verbose => false } end |
#inject_sufia_controller_behavior ⇒ Object
Add behaviors to the application controller
57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/generators/sufia/sufia_generator.rb', line 57 def inject_sufia_controller_behavior controller_name = "ApplicationController" file_path = "app/controllers/application_controller.rb" if File.exists?(file_path) insert_into_file file_path, :after => 'include Blacklight::Controller' do " \n# Adds Sufia behaviors into the application controller \n" + " include Sufia::Controller\n" end gsub_file file_path, "layout 'blacklight'", "layout 'sufia-one-column'" else puts " \e[31mFailure\e[0m Could not find #{file_path}. To add Sufia behaviors to your Controllers, you must include the Sufia::Controller module in the Controller class definition." end end |
#inject_sufia_solr_document_behavior ⇒ Object
Add behaviors to the SolrDocument model
96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/generators/sufia/sufia_generator.rb', line 96 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
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/generators/sufia/sufia_generator.rb', line 44 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
108 109 110 |
# File 'lib/generators/sufia/sufia_generator.rb', line 108 def install_mailboxer generate "mailboxer:install" end |