Class: ScaffoldPlus::Generators::AuthorityGenerator
- Inherits:
-
ActiveRecord::Generators::Base
- Object
- ActiveRecord::Generators::Base
- ScaffoldPlus::Generators::AuthorityGenerator
- Defined in:
- lib/generators/scaffold_plus/authority/authority_generator.rb
Instance Method Summary collapse
Instance Method Details
#add_authorizer ⇒ Object
33 34 35 36 |
# File 'lib/generators/scaffold_plus/authority/authority_generator.rb', line 33 def return if ..present? template "authorizer.rb", "app/authorizers/#{name}_authorizer.rb" end |
#update_controller ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/generators/scaffold_plus/authority/authority_generator.rb', line 38 def update_controller return unless .controller? file = "app/controllers/#{table_name}_controller.rb" inject_into_file file, after: /before_action :set_#{name}.*$/ do "\n authorize_actions_for #{class_name}, only: [:index, :new, :create]" end inject_into_file file, after: /private$/ do "\n def authority_forbidden(error)" + "\n Authority.logger.warn(error.message)" + "\n redirect_to root_path, alert: 'Forbidden'" + "\n end\n" end inject_into_file file, after: /@#{name} = #{class_name}.find.*$/ do "\n authorize_action_for(@#{name})" end inject_into_file file, after: /@#{name} = #{class_name}.friendly.find.*$/ do "\n authorize_action_for(@#{name})" end end |
#update_model ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/generators/scaffold_plus/authority/authority_generator.rb', line 19 def update_model inject_into_class "app/models/#{name}.rb", class_name do text = .before? ? "\n" : "" text << " include Authority::Abilities\n" if ..present? text << " self.authorizer_name = '#{.}'\n" else text << " self.authorizer_name = '#{class_name}Authorizer'\n" end text << "\n" if .after? text end end |