Class: McmsAuthenticationGenerator
- Inherits:
-
Rails::Generators::NamedBase
- Object
- Rails::Generators::NamedBase
- McmsAuthenticationGenerator
- Defined in:
- lib/generators/mcms_authentication/mcms_authentication_generator.rb
Overview
@File Name :mcms_authentication_generator.rb
@Company Name :Mindfire Solutions Pvt. Ltd.
@Creator Name :Indranil Mukherjee
@Date Created :2012-06-14
@Date Modified :2012-06-25
@Last Modification Details :Making it as mcms project standard
@Purpose :This file is responsible to install mcms_authentication module in other application/module
Instance Method Summary collapse
-
#add_migrations ⇒ Object
@Params : No parameter @Returns : Nothing is returned @Purpose : Copies all the migrations.
-
#configure ⇒ Object
@Params : No parameter @Returns : Nothing is returned @Purpose : Configurations are done here.
-
#copy_core_libraries ⇒ Object
@Params : No parameter @Returns : Nothing is returned @Purpose : Copies all the libraries required.
-
#prompt_user ⇒ Object
@Params : No parameter @Returns : Nothing is returned @Purpose : Final instructions for developers who will use the gem.
Instance Method Details
#add_migrations ⇒ Object
@Params : No parameter
@Returns : Nothing is returned
@Purpose : Copies all the migrations
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/generators/mcms_authentication/mcms_authentication_generator.rb', line 29 def add_migrations say "Copying migrations........." rake("mcms_authentication_engine:install:migrations") # create file deb/seeds.rb to parent app if not exists create_file "db/seeds.rb" unless File.exists?(File.join(destination_root, 'db', 'seeds.rb')) # append data to app's seeds.rb append_file 'db/seeds.rb', :verbose => true do <<-EOH McmsAuthentication::Engine.load_seed EOH end # end block end |
#configure ⇒ Object
@Params : No parameter
@Returns : Nothing is returned
@Purpose : Configurations are done here
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 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/generators/mcms_authentication/mcms_authentication_generator.rb', line 65 def configure original_app = File.binread("app/controllers/application_controller.rb") if((original_app.include?("include ApplicationHelper")) && (original_app.include?("def after_sign_in_path_for(resource)"))) say_status("skipped", "insert into app/controllers/application_controller.rb", :yellow) else insert_into_file File.join('app/controllers', 'application_controller.rb'), :after => "ActionController::Base\n" do ' include ApplicationHelper #including application_helper for the availability of filters # The following snippet is responsible for rescuing from exception generated by CanCan gem # for denying a particular module access with a notice to user and redirecting to root_url rescue_from CanCan::AccessDenied do |exception| flash[:error] = t(:access_denied,:default => "You are not authorized for doing this operation") if Gem.available? ("mcms") redirect_to "/mcms/dashboard" else "/" end end def after_sign_in_path_for(resource) if Gem.available? ("mcms") "/mcms/dashboard" # <- Path you want to redirect the user to. else "/" end end #end of configuration ' end end end |
#copy_core_libraries ⇒ Object
@Params : No parameter
@Returns : Nothing is returned
@Purpose : Copies all the libraries required
55 56 57 58 59 |
# File 'lib/generators/mcms_authentication/mcms_authentication_generator.rb', line 55 def copy_core_libraries copy_file "models.rb", "lib/mcms_authentication/models.rb" # module logic end |
#prompt_user ⇒ Object
@Params : No parameter
@Returns : Nothing is returned
@Purpose : Final instructions for developers who will use the gem
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/generators/mcms_authentication/mcms_authentication_generator.rb', line 114 def prompt_user unless Gem.available? ("mcms") say "\ndon't forget to run the following \n rake db:migrate\n in the controllers where you want to apply auth\n prepend_before_filter :authenticate_user! \n load_and_authorize_resource \n Enjoy!\n\n" end end |