yarrow 0.7.2 → 0.7.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,78 +0,0 @@
1
- module Yarrow
2
- module Content
3
- # Collects a digraph of all directories and files underneath the given input
4
- # directory.
5
- class SourceCollector
6
- def self.collect(input_dir)
7
- Mementus::Graph.new(is_mutable: true) do
8
- root = create_node do |root|
9
- root.label = :root
10
- end
11
-
12
- root_dir_entry = Pathname.new(input_dir)
13
-
14
- root_dir = create_node do |dir|
15
- dir.label = :directory
16
- dir.props = {
17
- name: root_dir_entry.basename.to_s,
18
- path: root_dir_entry.to_s,
19
- entry: root_dir_entry
20
- }
21
- end
22
-
23
- create_edge do |child|
24
- child.label = :child
25
- child.from = root.id
26
- child.to = root_dir.id
27
- end
28
-
29
- directories = {
30
- root_dir_entry.to_s => root_dir.id
31
- }
32
-
33
- Pathname.glob("#{input_dir}/**/**").each do |entry|
34
- if entry.directory?
35
- content_node = create_node do |dir|
36
- dir.label = :directory
37
- # dir.props[:name] = entry.basename.to_s
38
- # dir.props[:slug] = entry.basename.to_s
39
- # dir.props[:path] = entry.to_s
40
- # dir.props[:entry] = entry
41
- dir.props = {
42
- name: entry.basename.to_s,
43
- path: entry.to_s,
44
- entry: entry
45
- }
46
- end
47
-
48
- directories[entry.to_s] = content_node.id
49
- else
50
- content_node = create_node do |file|
51
- file.label = :file
52
- # file.props[:name] = entry.basename.to_s
53
- # file.props[:slug] = entry.basename.sub_ext('').to_s
54
- # file.props[:path] = entry.to_s
55
- # file.props[:entry] = entry
56
-
57
- file.props = {
58
- name: entry.basename.to_s,
59
- ext: entry.extname.to_s,
60
- path: entry.to_s,
61
- entry: entry
62
- }
63
- end
64
- end
65
-
66
- if directories.key?(entry.dirname.to_s)
67
- create_edge do |edge|
68
- edge.label = :child
69
- edge.from = directories[entry.dirname.to_s]
70
- edge.to = content_node
71
- end
72
- end
73
- end
74
- end
75
- end
76
- end
77
- end
78
- end