Class: GroupPermission::Permission
- Inherits:
-
Object
- Object
- GroupPermission::Permission
- Includes:
- EacRubyUtils::SimpleCache
- Defined in:
- app/models/group_permission.rb
Instance Attribute Summary collapse
-
#dependencies ⇒ Object
readonly
Returns the value of attribute dependencies.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #depends_recursive(visited = Set.new) ⇒ Object
- #description ⇒ Object
-
#initialize(key, options) ⇒ Permission
constructor
A new instance of Permission.
- #to_s ⇒ Object
- #user_has?(user) ⇒ Boolean
Constructor Details
#initialize(key, options) ⇒ Permission
Returns a new instance of Permission.
65 66 67 68 |
# File 'app/models/group_permission.rb', line 65 def initialize(key, ) @key = self.class.sanitize_key(key) @dependencies = ([:dependencies] || []).map { |k| ::GroupPermission.(k) } end |
Instance Attribute Details
#dependencies ⇒ Object (readonly)
Returns the value of attribute dependencies.
63 64 65 |
# File 'app/models/group_permission.rb', line 63 def dependencies @dependencies end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
63 64 65 |
# File 'app/models/group_permission.rb', line 63 def key @key end |
Class Method Details
.sanitize_key(key) ⇒ Object
58 59 60 |
# File 'app/models/group_permission.rb', line 58 def sanitize_key(key) key.to_s.downcase end |
Instance Method Details
#<=>(other) ⇒ Object
95 96 97 |
# File 'app/models/group_permission.rb', line 95 def <=>(other) to_s <=> other.to_s end |
#depends_recursive(visited = Set.new) ⇒ Object
84 85 86 87 88 89 90 91 92 93 |
# File 'app/models/group_permission.rb', line 84 def depends_recursive(visited = Set.new) return [] if visited.include?(key) r = Set.new([key]) visited << key depends.each do |d| r += d.depends_recursive(visited) end r end |
#description ⇒ Object
70 71 72 |
# File 'app/models/group_permission.rb', line 70 def description I18n.t("permission_#{key}_description") end |
#to_s ⇒ Object
74 75 76 |
# File 'app/models/group_permission.rb', line 74 def to_s key end |
#user_has?(user) ⇒ Boolean
78 79 80 81 82 |
# File 'app/models/group_permission.rb', line 78 def user_has?(user) return true if user.admin GroupPermission.where(group: user_groups(user), permission: depends_recursive.to_a).any? end |