Class: RubynCode::Permissions::DenyList
- Inherits:
-
Object
- Object
- RubynCode::Permissions::DenyList
- Defined in:
- lib/rubyn_code/permissions/deny_list.rb
Instance Attribute Summary collapse
-
#names ⇒ Object
readonly
Returns the value of attribute names.
-
#prefixes ⇒ Object
readonly
Returns the value of attribute prefixes.
Instance Method Summary collapse
- #add_name(name) ⇒ self
- #add_prefix(prefix) ⇒ self
-
#blocks?(tool_name) ⇒ Boolean
Returns true if the given tool name is blocked by an exact name match or by a prefix match.
-
#initialize(names: [], prefixes: []) ⇒ DenyList
constructor
A new instance of DenyList.
- #remove_name(name) ⇒ self
Constructor Details
#initialize(names: [], prefixes: []) ⇒ DenyList
Returns a new instance of DenyList.
10 11 12 13 |
# File 'lib/rubyn_code/permissions/deny_list.rb', line 10 def initialize(names: [], prefixes: []) @names = Set.new(names.map(&:to_s)) @prefixes = Set.new(prefixes.map(&:to_s)) end |
Instance Attribute Details
#names ⇒ Object (readonly)
Returns the value of attribute names.
6 7 8 |
# File 'lib/rubyn_code/permissions/deny_list.rb', line 6 def names @names end |
#prefixes ⇒ Object (readonly)
Returns the value of attribute prefixes.
6 7 8 |
# File 'lib/rubyn_code/permissions/deny_list.rb', line 6 def prefixes @prefixes end |
Instance Method Details
#add_name(name) ⇒ self
29 30 31 32 |
# File 'lib/rubyn_code/permissions/deny_list.rb', line 29 def add_name(name) @names.add(name.to_s) self end |
#add_prefix(prefix) ⇒ self
36 37 38 39 |
# File 'lib/rubyn_code/permissions/deny_list.rb', line 36 def add_prefix(prefix) @prefixes.add(prefix.to_s) self end |
#blocks?(tool_name) ⇒ Boolean
Returns true if the given tool name is blocked by an exact name match or by a prefix match.
20 21 22 23 24 25 |
# File 'lib/rubyn_code/permissions/deny_list.rb', line 20 def blocks?(tool_name) name = tool_name.to_s return true if @names.include?(name) @prefixes.any? { |prefix| name.start_with?(prefix) } end |
#remove_name(name) ⇒ self
43 44 45 46 |
# File 'lib/rubyn_code/permissions/deny_list.rb', line 43 def remove_name(name) @names.delete(name.to_s) self end |