Class: Straycall::Policy::Exec
- Inherits:
-
Object
- Object
- Straycall::Policy::Exec
- Defined in:
- lib/straycall/policy/exec.rb
Instance Method Summary collapse
- #active? ⇒ Boolean
- #allow(path) ⇒ Object
- #allow_under(path) ⇒ Object
- #allowed?(path) ⇒ Boolean
- #deny(path) ⇒ Object
- #deny_elsewhere! ⇒ Object
-
#initialize ⇒ Exec
constructor
A new instance of Exec.
Constructor Details
#initialize ⇒ Exec
Returns a new instance of Exec.
6 7 8 9 10 11 |
# File 'lib/straycall/policy/exec.rb', line 6 def initialize @default = :allow @allowed = [] @allowed_roots = [] @denied = [] end |
Instance Method Details
#active? ⇒ Boolean
32 33 34 |
# File 'lib/straycall/policy/exec.rb', line 32 def active? @default == :deny || !@denied.empty? end |
#allow(path) ⇒ Object
13 14 15 16 |
# File 'lib/straycall/policy/exec.rb', line 13 def allow(path) validate_path!(path) @allowed << normalize(path) end |
#allow_under(path) ⇒ Object
22 23 24 25 |
# File 'lib/straycall/policy/exec.rb', line 22 def allow_under(path) validate_path!(path) @allowed_roots << normalize(path) end |
#allowed?(path) ⇒ Boolean
36 37 38 39 |
# File 'lib/straycall/policy/exec.rb', line 36 def allowed?(path) path = normalize(path) @default == :allow ? !@denied.include?(path) : @allowed.include?(path) || @allowed_roots.any? { |root| under?(path, root) } end |
#deny(path) ⇒ Object
27 28 29 30 |
# File 'lib/straycall/policy/exec.rb', line 27 def deny(path) validate_path!(path) @denied << normalize(path) end |
#deny_elsewhere! ⇒ Object
18 19 20 |
# File 'lib/straycall/policy/exec.rb', line 18 def deny_elsewhere! @default = :deny end |