Class: Findler
- Inherits:
-
Object
show all
- Defined in:
- lib/findler.rb,
lib/findler/path.rb,
lib/findler/error.rb,
lib/findler/filters.rb,
lib/findler/version.rb,
lib/findler/iterator.rb
Defined Under Namespace
Classes: Error, Filters, Iterator, Path
Constant Summary
collapse
- VERSION =
Gem::Version.new("0.0.7")
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(path) ⇒ Findler
Returns a new instance of Findler.
9
10
11
12
|
# File 'lib/findler.rb', line 9
def initialize(path)
@path = Path.clean(path)
@flags = 0
end
|
Instance Attribute Details
#path ⇒ Object
Returns the value of attribute path.
7
8
9
|
# File 'lib/findler.rb', line 7
def path
@path
end
|
Instance Method Details
#add_extension(extension) ⇒ Object
29
30
31
|
# File 'lib/findler.rb', line 29
def add_extension(extension)
add_pattern "*#{normalize_extension(extension)}"
end
|
#add_extensions(extensions) ⇒ Object
33
34
35
|
# File 'lib/findler.rb', line 33
def add_extensions(extensions)
extensions.each { |ea| add_extension(ea) }
end
|
#add_filter(filter_symbol) ⇒ Object
Accepts symbols whose names are class methods on Finder::Filters.
Filter methods receive an array of Pathname instances, and are in charge of ordering and filtering the array. The returned array of pathnames will be used by the iterator.
Those pathnames will: a) have the same parent b) will not have been enumerated by next() already c) will satisfy the hidden flag and patterns preferences
Note that the last filter added will be last to order the children, so it will be the “primary” sort criterion.
87
88
89
|
# File 'lib/findler.rb', line 87
def add_filter(filter_symbol)
filters << filter_symbol
end
|
#add_filters(filter_symbols) ⇒ Object
95
96
97
|
# File 'lib/findler.rb', line 95
def add_filters(filter_symbols)
filter_symbols.each { |ea| add_filter(ea) }
end
|
#add_pattern(pattern) ⇒ Object
25
26
27
|
# File 'lib/findler.rb', line 25
def add_pattern(pattern)
self.patterns << pattern
end
|
#add_patterns(patterns) ⇒ Object
21
22
23
|
# File 'lib/findler.rb', line 21
def add_patterns(patterns)
self.patterns += patterns
end
|
#case_insensitive! ⇒ Object
43
44
45
|
# File 'lib/findler.rb', line 43
def case_insensitive!
@flags |= File::FNM_CASEFOLD
end
|
#case_sensitive! ⇒ Object
Should patterns be interpreted in a case-sensitive manner? The default is case sensitive, but if your local filesystem is not case sensitive, this flag is a no-op.
39
40
41
|
# File 'lib/findler.rb', line 39
def case_sensitive!
@flags &= ~File::FNM_CASEFOLD
end
|
#exclude_hidden! ⇒ Object
57
58
59
|
# File 'lib/findler.rb', line 57
def exclude_hidden!
@flags &= ~File::FNM_DOTMATCH
end
|
#filters ⇒ Object
91
92
93
|
# File 'lib/findler.rb', line 91
def filters
@filters ||= []
end
|
#filters_class ⇒ Object
65
66
67
|
# File 'lib/findler.rb', line 65
def filters_class
@filters_class ||= Filters
end
|
#filters_class=(new_filters_class) ⇒ Object
69
70
71
72
73
|
# File 'lib/findler.rb', line 69
def filters_class=(new_filters_class)
raise Error unless new_filters_class.is_a? Class
filters.each { |ea| new_filters_class.method(ea) } @filters_class = new_filters_class
end
|
#ignore_case? ⇒ Boolean
47
48
49
|
# File 'lib/findler.rb', line 47
def ignore_case?
(@flags & File::FNM_CASEFOLD) > 0
end
|
#include_hidden! ⇒ Object
Should we traverse hidden directories and files? (default is to skip files that start with a ‘.’)
53
54
55
|
# File 'lib/findler.rb', line 53
def include_hidden!
@flags |= File::FNM_DOTMATCH
end
|
#include_hidden? ⇒ Boolean
61
62
63
|
# File 'lib/findler.rb', line 61
def include_hidden?
(@flags & File::FNM_DOTMATCH) > 0
end
|
#iterator ⇒ Object
99
100
101
|
# File 'lib/findler.rb', line 99
def iterator
Iterator.new(self, path)
end
|
#patterns ⇒ Object
These are File.fnmatch patterns, and are only applied to files, not directories. If any pattern matches, it will be returned by Iterator#next_file. (see File.fnmatch?)
17
18
19
|
# File 'lib/findler.rb', line 17
def patterns
@patterns ||= []
end
|