Class: OodSupport::ACL
- Inherits:
-
Object
- Object
- OodSupport::ACL
- Defined in:
- lib/ood_support/acl.rb
Overview
A helper object that describes an access control list (ACL) with entries
Direct Known Subclasses
Instance Attribute Summary collapse
-
#default ⇒ Boolean
readonly
Whether this ACL defaults to allow, otherwise default deny.
-
#entries ⇒ Array<ACLEntry>
readonly
The entries of this ACL.
Class Method Summary collapse
-
.parse(acl, **kwargs) ⇒ ACL
Generate an ACL by parsing a string along with options.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
The comparison operator.
-
#allow?(principle:) ⇒ Boolean
Check if queried principle has access to resource.
-
#eql?(other) ⇒ Boolean
Checks whether two ACL objects are completely identical to each other.
-
#hash ⇒ Integer
Generates a hash value for this object.
-
#initialize(entries:, default: false) ⇒ ACL
constructor
A new instance of ACL.
-
#to_h ⇒ Hash
Convert object to hash.
-
#to_s ⇒ String
Convert object to string.
Constructor Details
#initialize(entries:, default: false) ⇒ ACL
Returns a new instance of ACL.
26 27 28 29 |
# File 'lib/ood_support/acl.rb', line 26 def initialize(entries:, default: false) @entries = entries @default = default end |
Instance Attribute Details
#default ⇒ Boolean (readonly)
Whether this ACL defaults to allow, otherwise default deny
10 11 12 |
# File 'lib/ood_support/acl.rb', line 10 def default @default end |
#entries ⇒ Array<ACLEntry> (readonly)
The entries of this ACL
6 7 8 |
# File 'lib/ood_support/acl.rb', line 6 def entries @entries end |
Class Method Details
.parse(acl, **kwargs) ⇒ ACL
Generate an ACL by parsing a string along with options
16 17 18 19 20 21 22 |
# File 'lib/ood_support/acl.rb', line 16 def self.parse(acl, **kwargs) entries = [] acl.to_s.strip.split(/\n|,/).grep(/^[^#]/).each do |entry| entries << entry_class.parse(entry) end new(entries: entries, **kwargs) end |
Instance Method Details
#==(other) ⇒ Boolean
The comparison operator
54 55 56 |
# File 'lib/ood_support/acl.rb', line 54 def ==(other) to_h == other.to_h end |
#allow?(principle:) ⇒ Boolean
Check if queried principle has access to resource
34 35 36 37 |
# File 'lib/ood_support/acl.rb', line 34 def allow?(principle:) # Check in array order ordered_check(principle: principle) end |
#eql?(other) ⇒ Boolean
Checks whether two ACL objects are completely identical to each other
61 62 63 |
# File 'lib/ood_support/acl.rb', line 61 def eql?(other) self.class == other.class && self == other end |
#hash ⇒ Integer
Generates a hash value for this object
67 68 69 |
# File 'lib/ood_support/acl.rb', line 67 def hash [self.class, to_h].hash end |
#to_h ⇒ Hash
Convert object to hash
47 48 49 |
# File 'lib/ood_support/acl.rb', line 47 def to_h { entries: entries, default: default } end |
#to_s ⇒ String
Convert object to string
41 42 43 |
# File 'lib/ood_support/acl.rb', line 41 def to_s entries.join("\n") end |