Class: FastIgnore
- Inherits:
-
Object
- Object
- FastIgnore
- Includes:
- Enumerable
- Defined in:
- lib/fast_ignore.rb,
lib/fast_ignore/rule.rb,
lib/fast_ignore/version.rb,
lib/fast_ignore/rule_set.rb,
lib/fast_ignore/backports.rb,
lib/fast_ignore/rule_builder.rb,
lib/fast_ignore/shebang_rule.rb,
lib/fast_ignore/fn_match_to_re.rb,
lib/fast_ignore/rule_set_builder.rb
Defined Under Namespace
Modules: Backports, FNMatchToRegex, RuleBuilder, RuleSetBuilder Classes: Error, Rule, RuleSet, ShebangRule
Constant Summary collapse
- VERSION =
'0.11.0'
Instance Method Summary collapse
- #allowed?(path, directory: nil, content: nil) ⇒ Boolean (also: #===)
- #each(&block) ⇒ Object
-
#initialize(relative: false, root: nil, follow_symlinks: false, **rule_set_builder_args) ⇒ FastIgnore
constructor
:nocov:.
Constructor Details
#initialize(relative: false, root: nil, follow_symlinks: false, **rule_set_builder_args) ⇒ FastIgnore
:nocov:
22 23 24 25 26 27 28 29 |
# File 'lib/fast_ignore.rb', line 22 def initialize(relative: false, root: nil, follow_symlinks: false, **rule_set_builder_args) @relative = relative @follow_symlinks = follow_symlinks @root = "#{::File.(root.to_s, Dir.pwd)}/" @rule_sets = ::FastIgnore::RuleSetBuilder.build(root: @root, **rule_set_builder_args) freeze end |
Instance Method Details
#allowed?(path, directory: nil, content: nil) ⇒ Boolean Also known as: ===
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/fast_ignore.rb', line 40 def allowed?(path, directory: nil, content: nil) full_path = ::File.(path, @root) return false unless full_path.start_with?(@root) return false if directory.nil? ? directory?(full_path) : directory relative_path = full_path.delete_prefix(@root) filename = ::File.basename(relative_path) @rule_sets.all? { |r| r.allowed_recursive?(relative_path, false, full_path, filename, content) } rescue ::Errno::ENOENT, ::Errno::EACCES, ::Errno::ENOTDIR, ::Errno::ELOOP, ::Errno::ENAMETOOLONG false end |
#each(&block) ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/fast_ignore.rb', line 31 def each(&block) return enum_for(:each) unless block_given? dir_pwd = Dir.pwd root_from_pwd = @root.start_with?(dir_pwd) ? ".#{@root.delete_prefix(dir_pwd)}" : @root each_recursive(root_from_pwd, '', &block) end |