class Effective::Generators::AbilityGenerator
Public Instance Methods
create_ability()
click to toggle source
# File lib/generators/effective/ability_generator.rb, line 26 def create_ability unless File.exists?(resource.abilities_file) say_status(:skipped, :ability, :yellow) and return end Effective::CodeWriter.new(resource.abilities_file) do |w| if w.find { |line, depth| (depth == 2 || depth == 3) && line == ability } say_status :identical, ability, :blue else w.insert_into_first(ability + "\n") { |line, depth| line.start_with?('def initialize') || line.end_with?('abilities(user)') } say_status :ability, ability end end end
invoke_ability()
click to toggle source
# File lib/generators/effective/ability_generator.rb, line 22 def invoke_ability say_status :invoke, :ability, :white end
validate_resource()
click to toggle source
# File lib/generators/effective/ability_generator.rb, line 18 def validate_resource exit unless resource_valid? end
Private Instance Methods
ability()
click to toggle source
# File lib/generators/effective/ability_generator.rb, line 44 def ability @ability ||= ( abilities = [] if (crud_actions - invoked_actions).present? abilities += (crud_actions & invoked_actions) end if non_crud_actions.present? abilities += non_crud_actions end abilities = ['manage'] if abilities.blank? || abilities == (crud_actions - ['show']) if abilities.length == 1 abilities = ":#{abilities.first}" else abilities = '[' + abilities.map { |action| ':' + action }.join(', ') + ']' end name = if resource.module_name.present? resource.class_name.split('::').last else resource.class_name end "can #{abilities}, #{name}" ) end