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