Class: KFileset::Whitelist
- Inherits:
-
Object
- Object
- KFileset::Whitelist
- Defined in:
- lib/k_fileset/whitelist.rb
Overview
Whitelist rules around including of files with optional exclusion rules
Instance Method Summary collapse
- #add(glob, exclude = nil, flags = nil) ⇒ Object
- #clear ⇒ Object
-
#glob_entries ⇒ Object
Return GlobInfo entries with the directory, glob and exclusions.
-
#initialize ⇒ Whitelist
constructor
A new instance of Whitelist.
-
#match?(file) ⇒ Boolean
Return true if file is matched against an entry in the whitelist.
- #path_entries ⇒ Object
Constructor Details
#initialize ⇒ Whitelist
Returns a new instance of Whitelist.
6 7 8 9 |
# File 'lib/k_fileset/whitelist.rb', line 6 def initialize @glob_entries = nil # glob_entries @globs = [] # glob_infos / end |
Instance Method Details
#add(glob, exclude = nil, flags = nil) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/k_fileset/whitelist.rb', line 15 def add(glob, exclude = nil, flags = nil) flags ||= FileSet::DEF_FLAGS @glob_entries = nil @globs << KFileset::GlobInfo.new(glob, exclude, flags) self end |
#clear ⇒ Object
23 24 25 26 27 28 |
# File 'lib/k_fileset/whitelist.rb', line 23 def clear @glob_entries = nil @globs = [] self end |
#glob_entries ⇒ Object
Return GlobInfo entries with the directory, glob and exclusions
Will denormalize the entries where matching (path and glob), whilst expanding with any new exclusions.
38 39 40 |
# File 'lib/k_fileset/whitelist.rb', line 38 def glob_entries @glob_entries ||= KFileset::GlobInfo.build_glob_entries(@globs) end |
#match?(file) ⇒ Boolean
Return true if file is matched against an entry in the whitelist
31 32 33 |
# File 'lib/k_fileset/whitelist.rb', line 31 def match?(file) glob_entries.any? { |entry| entry.match?(file) } end |
#path_entries ⇒ Object
11 12 13 |
# File 'lib/k_fileset/whitelist.rb', line 11 def path_entries glob_entries.flat_map(&:path_entries) end |