Module: Faalis::Permissions::ClassMethods
- Defined in:
- lib/faalis/permissions.rb
Constant Summary collapse
- @@permissions =
Default permission hash
{ :read => nil, :update => nil, :create => nil, :destroy => nil, }
- @@only_owner =
false
Instance Method Summary collapse
-
#only_his_objects ⇒ Object
This force user to have access to resources which is his.
- #only_his_objects? ⇒ Boolean
-
#permission_strings(model) ⇒ Object
An array of strings representation of permissions.
-
#permissions(*args) ⇒ Object
Define permissions using this method.
- #possible_permissions ⇒ Object
Instance Method Details
#only_his_objects ⇒ Object
This force user to have access to resources which is his.
62 63 64 |
# File 'lib/faalis/permissions.rb', line 62 def only_his_objects @@only_owner = true end |
#only_his_objects? ⇒ Boolean
66 67 68 |
# File 'lib/faalis/permissions.rb', line 66 def only_his_objects? @@only_owner end |
#permission_strings(model) ⇒ Object
Returns an array of strings representation of permissions.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/faalis/permissions.rb', line 19 def (model) strings = [] model_name = model.to_s humanize_name = ActiveModel::Name.new(model).human if model.respond_to? :model_name model_name = model.model_name humanize_name = model_name.human end @@permissions.each do |key, value| strings << { :name => "#{key}|#{model_name}", :string => _("can %s %s") % [_(key.to_s), humanize_name] } end strings end |
#permissions(*args) ⇒ Object
Define permissions using this method
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/faalis/permissions.rb', line 41 def (*args) args.each do || if .class == Symbol if not @@permissions.include? @@permission[] = nil elsif .class == Hash .each do |key, value| @@permissions[key.to_sym] = value end end end end end |
#possible_permissions ⇒ Object
36 37 38 |
# File 'lib/faalis/permissions.rb', line 36 def @@permissions.keys end |