dir_validator 0.12.0 → 0.12.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.rdoc +4 -0
- data/lib/dir_validator/catalog.rb +25 -11
- metadata +3 -3
data/CHANGELOG.rdoc
CHANGED
@@ -35,30 +35,44 @@ class DirValidator::Catalog
|
|
35
35
|
return @items ||= load_items()
|
36
36
|
end
|
37
37
|
|
38
|
+
# Takes a path as a string. Returns true if it's . or .. directory.
|
39
|
+
def path_is_dot_dir(path)
|
40
|
+
return path =~ DOTDIR_RE ? true : false
|
41
|
+
end
|
42
|
+
|
38
43
|
# Scans the Validator.root_dir, creating a new Item for each file/dir
|
39
44
|
# found, and adding the Item to the indexes used by the Catalog.
|
45
|
+
# NOTES:
|
46
|
+
# - We must instantiate the new Items from within the Dir.chdir block
|
47
|
+
# in order to set their is_file and is_dir attributes correctly.
|
48
|
+
# - We must put the glob() call in a separate function so that
|
49
|
+
# we can sort it because we start assigning catalog_id values.
|
40
50
|
def load_items
|
41
51
|
catalog_id = -1
|
42
52
|
@items = []
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
#
|
48
|
-
#
|
53
|
+
rp = @validator.root_path
|
54
|
+
Dir.chdir(rp) do
|
55
|
+
dir_contents_deep(rp).each do |path|
|
56
|
+
# Create the new Item, and give it a unique ID (which is
|
57
|
+
# also an index into the @items array), add it to the catalog
|
58
|
+
# and the indexes.
|
49
59
|
catalog_id += 1
|
50
60
|
item = DirValidator::Item.new(@validator, path, catalog_id)
|
51
61
|
@items << item
|
52
|
-
# Add Item to the indexes.
|
53
62
|
add_to_index(item)
|
54
63
|
end
|
55
64
|
end
|
56
65
|
return @items
|
57
66
|
end
|
58
67
|
|
59
|
-
# Takes a path as a string.
|
60
|
-
|
61
|
-
|
68
|
+
# Takes a root path as a string.
|
69
|
+
# - gets a fully recursive list of the files and dirs
|
70
|
+
# - excludes the . and .. dirs (but not the dotfiles)
|
71
|
+
# Return the paths in sorted orded.
|
72
|
+
def dir_contents_deep(root_path)
|
73
|
+
paths = Dir.glob('**/*', File::FNM_DOTMATCH)
|
74
|
+
paths = paths.reject { |p| path_is_dot_dir(p) }
|
75
|
+
return paths.sort
|
62
76
|
end
|
63
77
|
|
64
78
|
# Takes an Item object and adds it to the Catalog indexes.
|
@@ -88,7 +102,7 @@ class DirValidator::Catalog
|
|
88
102
|
return unmatched_items(base_dir).select { |i| i.is_file }
|
89
103
|
end
|
90
104
|
|
91
|
-
# Returns
|
105
|
+
# Returns unmatched files and directories from the Catalog.
|
92
106
|
def unmatched_items(base_dir = nil)
|
93
107
|
# If a base_dir is given, we'll use the @bdi index. Otherwise,
|
94
108
|
# we'll use the @unmatched index. When using @bdi, we also
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dir_validator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 41
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 12
|
9
|
-
-
|
10
|
-
version: 0.12.
|
9
|
+
- 3
|
10
|
+
version: 0.12.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Monty Hindman
|