Class: PermissionConfig
- Inherits:
-
Object
- Object
- PermissionConfig
- Defined in:
- lib/cancan-permits/loader/permission_config.rb
Instance Attribute Summary collapse
-
#can ⇒ Object
Returns the value of attribute can.
-
#cannot ⇒ Object
Returns the value of attribute cannot.
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
-
#can_eval {|statements| ... } ⇒ Object
Should take @can=href=""all"">manage”=>, @cannot=“Profile”] and create string ready to ruby evaluate like: can(:manage, :all) cannot(:update, [User, Profile]).
-
#initialize(name) ⇒ PermissionConfig
constructor
A new instance of PermissionConfig.
- #parse_targets(targets) ⇒ Object
Constructor Details
#initialize(name) ⇒ PermissionConfig
Returns a new instance of PermissionConfig.
4 5 6 |
# File 'lib/cancan-permits/loader/permission_config.rb', line 4 def initialize name @name = name end |
Instance Attribute Details
#can ⇒ Object
Returns the value of attribute can.
2 3 4 |
# File 'lib/cancan-permits/loader/permission_config.rb', line 2 def can @can end |
#cannot ⇒ Object
Returns the value of attribute cannot.
2 3 4 |
# File 'lib/cancan-permits/loader/permission_config.rb', line 2 def cannot @cannot end |
#name ⇒ Object
Returns the value of attribute name.
2 3 4 |
# File 'lib/cancan-permits/loader/permission_config.rb', line 2 def name @name end |
Instance Method Details
#can_eval {|statements| ... } ⇒ Object
Should take @can=href=""all"">manage”=>, @cannot=“Profile”] and create string ready to ruby evaluate like: can(:manage, :all) cannot(:update, [User, Profile])
12 13 14 15 16 17 18 |
# File 'lib/cancan-permits/loader/permission_config.rb', line 12 def can_eval &block statements = [:manage, :read, :update, :create, :write].map do |action| targets = can[action] targets ? "can(:#{action}, #{parse_targets(targets)})" : nil end.compact.join("\n") yield statements if !statements.empty? && block end |
#parse_targets(targets) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/cancan-permits/loader/permission_config.rb', line 28 def parse_targets targets targets.map do |target| if target == 'all' ':all' else begin "#{target.constantize}" rescue puts "[permission] target #{target} does not have a class so it was skipped" end end end end |