Module: Permissify::AbilityClass
- Included in:
- Ability
- Defined in:
- lib/permissify/ability_class.rb
Constant Summary collapse
- @@abilities =
[]
Instance Method Summary collapse
- #actions(category_prefix) ⇒ Object
- #add(category, section, action, applicability, requires_any_or_all, number_of_values, position, default_values, admin_expression = '', category_allows = :multiple) ⇒ Object
- #add_category(category, section, applicability, actions = %w(View Create Update Delete),, requires_any_or_all = :all?, category_allows = :multiple) ⇒ Object
- #all ⇒ Object
- #all_for(applicability_types) ⇒ Object
- #create_permissions_hash(view_only_categories = [], remove_categories = [], applicability_types = 'Role') ⇒ Object
- #current ⇒ Object
- #current_permissions_hash ⇒ Object
- #get(action, category) ⇒ Object
- #key_for(action, category) ⇒ Object
- #remove_permission(key_prefix) ⇒ Object
- #remove_permissions(key_prefixes) ⇒ Object
- #reset ⇒ Object
Instance Method Details
#actions(category_prefix) ⇒ Object
30 31 32 |
# File 'lib/permissify/ability_class.rb', line 30 def actions(category_prefix) all.collect{|a| a[:action] if a[:key].start_with?("#{key_token(category_prefix)}_")}.compact end |
#add(category, section, action, applicability, requires_any_or_all, number_of_values, position, default_values, admin_expression = '', category_allows = :multiple) ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/permissify/ability_class.rb', line 34 def add(category, section, action, applicability, requires_any_or_all, number_of_values, position, default_values, admin_expression='', category_allows = :multiple) applicability = applicability.to_set @@abilities << { :key => key_for(action, category), :category => category, :section => section, :action => action, :applicability => applicability, :number_of_values => number_of_values, :position => position, :default_values => default_values, :administration_expression => admin_expression, :category_allows => category_allows, :any_or_all => requires_any_or_all} end |
#add_category(category, section, applicability, actions = %w(View Create Update Delete),, requires_any_or_all = :all?, category_allows = :multiple) ⇒ Object
42 43 44 45 46 47 |
# File 'lib/permissify/ability_class.rb', line 42 def add_category(category, section, applicability, actions = %w(View Create Update Delete), requires_any_or_all = :all?, category_allows = :multiple) actions = [actions] unless actions.kind_of?(Array) actions.collect do |action| add(category, section, action, applicability, requires_any_or_all, 1, actions.index(action)+1, [false], '', category_allows) end end |
#all ⇒ Object
14 15 16 17 |
# File 'lib/permissify/ability_class.rb', line 14 def all seed if @@abilities.empty? current end |
#all_for(applicability_types) ⇒ Object
19 20 21 22 23 |
# File 'lib/permissify/ability_class.rb', line 19 def all_for(applicability_types) applicability_types = [applicability_types] if applicability_types.kind_of?(String) applicability_types = applicability_types.to_set all.select{|a| (a[:applicability] & applicability_types) == applicability_types} end |
#create_permissions_hash(view_only_categories = [], remove_categories = [], applicability_types = 'Role') ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/permissify/ability_class.rb', line 49 def (view_only_categories=[], remove_categories=[], applicability_types = 'Role') @@permissions = {} all_for(applicability_types).each{|| @@permissions[[:key]] = {'0' => '1'}} view_only_categories.each{|category| view_only(category)} remove_categories.each{|category| (category)} @@permissions end |
#current ⇒ Object
10 11 12 |
# File 'lib/permissify/ability_class.rb', line 10 def current @@abilities end |
#current_permissions_hash ⇒ Object
67 68 69 |
# File 'lib/permissify/ability_class.rb', line 67 def @@permissions end |
#get(action, category) ⇒ Object
25 26 27 28 |
# File 'lib/permissify/ability_class.rb', line 25 def get(action, category) key = key_for(action, category) all.select{ |ability| ability[:key] == key }.first end |
#key_for(action, category) ⇒ Object
71 72 73 |
# File 'lib/permissify/ability_class.rb', line 71 def key_for(action, category) "#{key_token(category)}_#{key_token(action)}" end |
#remove_permission(key_prefix) ⇒ Object
57 58 59 60 |
# File 'lib/permissify/ability_class.rb', line 57 def (key_prefix) @@permissions.keys.each{ |key| @@permissions.delete(key) if key.start_with?(key_prefix) } @@permissions end |
#remove_permissions(key_prefixes) ⇒ Object
62 63 64 65 |
# File 'lib/permissify/ability_class.rb', line 62 def (key_prefixes) key_prefixes.each{ |key_prefix| (key_prefix) } @@permissions end |
#reset ⇒ Object
6 7 8 |
# File 'lib/permissify/ability_class.rb', line 6 def reset @@abilities = [] end |