jsus 0.2.5 → 0.2.6
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +6 -2
- data/VERSION +1 -1
- data/bin/jsus +15 -6
- data/jsus.gemspec +16 -15
- data/lib/jsus.rb +13 -13
- data/lib/jsus/container.rb +31 -28
- data/lib/jsus/package.rb +5 -6
- data/lib/jsus/packager.rb +6 -6
- data/lib/jsus/pool.rb +9 -12
- data/lib/jsus/source_file.rb +15 -15
- data/lib/jsus/tag.rb +5 -5
- data/lib/jsus/util.rb +7 -0
- data/lib/jsus/util/documenter.rb +118 -0
- data/lib/jsus/util/tree.rb +201 -0
- data/lib/jsus/util/validator.rb +8 -0
- data/lib/jsus/util/validator/base.rb +48 -0
- data/lib/jsus/util/validator/mooforge.rb +25 -0
- data/spec/jsus/pool_spec.rb +3 -3
- data/spec/jsus/{documenter_spec.rb → util/documenter_spec.rb} +3 -3
- data/spec/jsus/{tree_spec.rb → util/tree_spec.rb} +111 -27
- data/spec/jsus/{validator → util/validator}/base_spec.rb +5 -5
- data/spec/jsus/{validator → util/validator}/mooforge_spec.rb +7 -7
- metadata +18 -17
- data/lib/jsus/documenter.rb +0 -99
- data/lib/jsus/tree.rb +0 -124
- data/lib/jsus/validator.rb +0 -2
- data/lib/jsus/validator/base.rb +0 -38
- data/lib/jsus/validator/mooforge.rb +0 -19
data/lib/jsus/tree.rb
DELETED
@@ -1,124 +0,0 @@
|
|
1
|
-
module Jsus
|
2
|
-
class Tree
|
3
|
-
PATH_SEPARATOR = "/"
|
4
|
-
|
5
|
-
# Utility functions
|
6
|
-
def self.get_path_components(path)
|
7
|
-
raise "Path should start with root (got: #{path})" unless path && path[0,1] == PATH_SEPARATOR
|
8
|
-
path = path.dup
|
9
|
-
path[0,1] = ""
|
10
|
-
path.split(PATH_SEPARATOR)
|
11
|
-
end
|
12
|
-
|
13
|
-
def self.path_from_components(components)
|
14
|
-
"#{PATH_SEPARATOR}#{components.join(PATH_SEPARATOR)}"
|
15
|
-
end
|
16
|
-
|
17
|
-
|
18
|
-
class Node
|
19
|
-
attr_accessor :value
|
20
|
-
attr_accessor :parent
|
21
|
-
attr_accessor :path_components
|
22
|
-
|
23
|
-
def initialize(full_path, value = nil)
|
24
|
-
self.full_path = full_path
|
25
|
-
self.value = value
|
26
|
-
end
|
27
|
-
|
28
|
-
attr_reader :full_path
|
29
|
-
attr_reader :name
|
30
|
-
def full_path=(full_path)
|
31
|
-
@full_path = full_path
|
32
|
-
@path_components = Tree.get_path_components(full_path)
|
33
|
-
@name = @path_components[-1]
|
34
|
-
end
|
35
|
-
|
36
|
-
def children
|
37
|
-
@children ||= []
|
38
|
-
end
|
39
|
-
|
40
|
-
def find_child(name)
|
41
|
-
children.detect {|child| child.name == name }
|
42
|
-
end
|
43
|
-
|
44
|
-
def create_child(name, value = nil)
|
45
|
-
full_path = Tree.path_from_components(path_components + [name])
|
46
|
-
node = Node.new(full_path, value)
|
47
|
-
children << node
|
48
|
-
node.parent = self
|
49
|
-
node
|
50
|
-
end
|
51
|
-
|
52
|
-
def find_or_create_child(name, value = nil)
|
53
|
-
find_child(name) || create_child(name, value)
|
54
|
-
end
|
55
|
-
|
56
|
-
def find_children_matching(pathspec)
|
57
|
-
case pathspec
|
58
|
-
when "**"
|
59
|
-
[self] + children.select {|child| child.has_children? }
|
60
|
-
when /\*/
|
61
|
-
regexp = Regexp.new("^" + Regexp.escape(pathspec).gsub("\\*", ".*") + "$")
|
62
|
-
children.select {|child| !child.has_children? && child.name =~ regexp }
|
63
|
-
else
|
64
|
-
[find_child(pathspec)].compact
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
def has_children?
|
69
|
-
!children.empty?
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
|
74
|
-
def root
|
75
|
-
@root ||= Node.new("/", nil)
|
76
|
-
end
|
77
|
-
|
78
|
-
def [](path)
|
79
|
-
path_components = self.class.get_path_components(path)
|
80
|
-
path_components.inject(root) do |result, component|
|
81
|
-
if result
|
82
|
-
result.find_child(component)
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
def glob(pathspec)
|
88
|
-
self.class.get_path_components(pathspec).inject([root]) do |nodes, component|
|
89
|
-
nodes.map {|node| node.find_children_matching(component) }.flatten
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
def insert(full_path, value = nil)
|
94
|
-
node = create_all_nodes_if_needed(full_path)
|
95
|
-
node.value = value
|
96
|
-
node
|
97
|
-
end
|
98
|
-
alias_method :[]=, :insert
|
99
|
-
|
100
|
-
def traverse(all_nodes = false)
|
101
|
-
node_list = [root]
|
102
|
-
while !node_list.empty?
|
103
|
-
node = node_list.shift
|
104
|
-
yield node if all_nodes || !node.has_children?
|
105
|
-
node.children.each {|child| node_list << child }
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
def leaves(only_with_value = true)
|
110
|
-
result = []
|
111
|
-
traverse {|node| result << node if !only_with_value || node.value }
|
112
|
-
result
|
113
|
-
end
|
114
|
-
|
115
|
-
|
116
|
-
def create_all_nodes_if_needed(full_path)
|
117
|
-
self.class.get_path_components(full_path).inject(root) do |result, component|
|
118
|
-
result.find_or_create_child(component)
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
|
-
end
|
123
|
-
|
124
|
-
end
|
data/lib/jsus/validator.rb
DELETED
data/lib/jsus/validator/base.rb
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
module Jsus
|
2
|
-
module Validator
|
3
|
-
class Base
|
4
|
-
def initialize(pool_or_array_or_container)
|
5
|
-
self.source_files = pool_or_array_or_container
|
6
|
-
end
|
7
|
-
|
8
|
-
def source_files
|
9
|
-
@source_files ||= []
|
10
|
-
end
|
11
|
-
alias_method :sources, :source_files
|
12
|
-
|
13
|
-
def source_files=(pool_or_array_or_container)
|
14
|
-
case pool_or_array_or_container
|
15
|
-
when Pool
|
16
|
-
@source_files = pool_or_array_or_container.sources.to_a
|
17
|
-
when Array
|
18
|
-
@source_files = pool_or_array_or_container
|
19
|
-
when Container
|
20
|
-
@source_files = pool_or_array_or_container.to_a
|
21
|
-
end
|
22
|
-
end
|
23
|
-
alias_method :sources=, :source_files=
|
24
|
-
|
25
|
-
def validate
|
26
|
-
validation_errors.empty?
|
27
|
-
end
|
28
|
-
|
29
|
-
def validation_errors
|
30
|
-
[]
|
31
|
-
end
|
32
|
-
|
33
|
-
def self.validate(*args)
|
34
|
-
new(*args).validate
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
module Jsus
|
2
|
-
module Validator
|
3
|
-
class Mooforge < Base
|
4
|
-
def validation_errors
|
5
|
-
@validation_errors ||= sources.inject([]) do |result, sf|
|
6
|
-
if !sf.header
|
7
|
-
result << "#{sf.filename} is missing header"
|
8
|
-
elsif !sf.header["authors"]
|
9
|
-
result << "#{sf.filename} is missing authors"
|
10
|
-
elsif !sf.header["license"]
|
11
|
-
result << "#{sf.filename} is missing license"
|
12
|
-
else
|
13
|
-
result
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|