Class: Rushiro::Permission
- Inherits:
-
Object
- Object
- Rushiro::Permission
- Defined in:
- lib/rushiro/permission.rb
Constant Summary collapse
- WildCard =
:*
Instance Attribute Summary collapse
-
#original ⇒ Object
readonly
Returns the value of attribute original.
-
#parts ⇒ Object
readonly
Returns the value of attribute parts.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #implied?(perm) ⇒ Boolean
-
#initialize(permission) ⇒ Permission
constructor
A new instance of Permission.
- #serialize ⇒ Object
Constructor Details
#initialize(permission) ⇒ Permission
Returns a new instance of Permission.
7 8 9 10 11 12 |
# File 'lib/rushiro/permission.rb', line 7 def initialize() raise ArgumentError.new("Invalid permission, empty string") if .empty? @original = @parts = .split(GSEP).map {|part| part.split(FSEP).map(&:to_sym)} @size = @parts.size end |
Instance Attribute Details
#original ⇒ Object (readonly)
Returns the value of attribute original.
3 4 5 |
# File 'lib/rushiro/permission.rb', line 3 def original @original end |
#parts ⇒ Object (readonly)
Returns the value of attribute parts.
3 4 5 |
# File 'lib/rushiro/permission.rb', line 3 def parts @parts end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
3 4 5 |
# File 'lib/rushiro/permission.rb', line 3 def size @size end |
Instance Method Details
#==(other) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/rushiro/permission.rb', line 29 def ==(other) return false unless @size == other.size @parts.each_with_index do |part, idx| return false unless (part - other.parts[idx]).empty? end true end |
#implied?(perm) ⇒ Boolean
14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/rushiro/permission.rb', line 14 def implied?(perm) if perm.include?(FSEP) msg = "Field separator: #{FSEP} used in input. Be specific, one of domain, action or instance per section." raise ArgumentError.new(msg) end array = perm.split(GSEP).map(&:to_sym) array.each_with_index do |part_sym, idx| # If the permission has less parts than the permission being tested, everything after the number # of parts contained in this permission is automatically implied, so return true break if @size.pred < idx return false if (@parts[idx] & [WildCard, part_sym]).empty? end true end |