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.
67 68 69 70 |
# File 'app/models/group_permission.rb', line 67 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.
65 66 67 |
# File 'app/models/group_permission.rb', line 65 def dependencies @dependencies end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
65 66 67 |
# File 'app/models/group_permission.rb', line 65 def key @key end |
Class Method Details
.sanitize_key(key) ⇒ Object
60 61 62 |
# File 'app/models/group_permission.rb', line 60 def sanitize_key(key) key.to_s.downcase end |
Instance Method Details
#<=>(other) ⇒ Object
97 98 99 |
# File 'app/models/group_permission.rb', line 97 def <=>(other) to_s <=> other.to_s end |
#depends_recursive(visited = Set.new) ⇒ Object
86 87 88 89 90 91 92 93 94 95 |
# File 'app/models/group_permission.rb', line 86 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
72 73 74 |
# File 'app/models/group_permission.rb', line 72 def description I18n.t("permission_#{key}_description") end |
#to_s ⇒ Object
76 77 78 |
# File 'app/models/group_permission.rb', line 76 def to_s key end |
#user_has?(user) ⇒ Boolean
80 81 82 83 84 |
# File 'app/models/group_permission.rb', line 80 def user_has?(user) return true if user.admin GroupPermission.where(group: user_groups(user), permission: depends_recursive.to_a).any? end |