scout-essentials 1.3.0 → 1.4.0
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.
- checksums.yaml +4 -4
- data/.vimproject +33 -1
- data/VERSION +1 -1
- data/lib/scout/annotation/annotated_object.rb +69 -0
- data/lib/scout/annotation/annotation_module.rb +59 -0
- data/lib/scout/annotation/array.rb +74 -0
- data/lib/scout/annotation.rb +45 -0
- data/lib/scout/concurrent_stream.rb +4 -1
- data/lib/scout/config.rb +3 -3
- data/lib/scout/exceptions.rb +2 -1
- data/lib/scout/indiferent_hash/options.rb +2 -1
- data/lib/scout/log/color.rb +1 -1
- data/lib/scout/log.rb +11 -11
- data/lib/scout/misc/digest.rb +39 -8
- data/lib/scout/misc/filesystem.rb +23 -0
- data/lib/scout/misc/format.rb +32 -0
- data/lib/scout/misc/helper.rb +37 -0
- data/lib/scout/misc/math.rb +109 -0
- data/lib/scout/misc/system.rb +2 -2
- data/lib/scout/misc.rb +1 -0
- data/lib/scout/named_array.rb +8 -6
- data/lib/scout/open/remote.rb +8 -3
- data/lib/scout/open/stream.rb +5 -1
- data/lib/scout/open/util.rb +1 -1
- data/lib/scout/path/find.rb +18 -6
- data/lib/scout/path/util.rb +1 -1
- data/lib/scout/path.rb +10 -4
- data/lib/scout/persist/open.rb +1 -1
- data/lib/scout/persist/serialize.rb +6 -2
- data/lib/scout/persist.rb +49 -20
- data/lib/scout/resource/path.rb +1 -1
- data/lib/scout/resource/scout.rb +2 -0
- data/lib/scout/resource/util.rb +8 -3
- data/lib/scout/resource.rb +15 -3
- data/scout-essentials.gemspec +21 -13
- data/test/scout/annotation/test_annotated_object.rb +0 -0
- data/test/scout/annotation/test_array.rb +119 -0
- data/test/scout/misc/test_digest.rb +54 -0
- data/test/scout/misc/test_filesystem.rb +28 -0
- data/test/scout/misc/test_helper.rb +14 -0
- data/test/scout/misc/test_math.rb +9 -0
- data/test/scout/path/test_find.rb +32 -0
- data/test/scout/test_annotation.rb +169 -0
- data/test/scout/test_persist.rb +17 -1
- data/test/scout/test_resource.rb +8 -8
- metadata +13 -5
- data/lib/scout/meta_extension.rb +0 -101
- data/test/scout/test_meta_extension.rb +0 -80
@@ -0,0 +1,119 @@
|
|
1
|
+
require File.expand_path(__FILE__).sub(%r(/test/.*), '/test/test_helper.rb')
|
2
|
+
require File.expand_path(__FILE__).sub(%r(.*/test/), '').sub(/test_(.*)\.rb/,'\1')
|
3
|
+
|
4
|
+
class TestAnnotationArray < Test::Unit::TestCase
|
5
|
+
module AnnotationClass
|
6
|
+
extend Annotation
|
7
|
+
|
8
|
+
annotation :code, :code2
|
9
|
+
end
|
10
|
+
|
11
|
+
module AnnotationClass2
|
12
|
+
extend Annotation
|
13
|
+
|
14
|
+
annotation :code3, :code4
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_array
|
18
|
+
ary = ["string"]
|
19
|
+
code = "Annotation String"
|
20
|
+
AnnotationClass.setup(ary, code)
|
21
|
+
ary.extend AnnotatedArray
|
22
|
+
assert_equal [AnnotationClass], ary.annotation_types
|
23
|
+
assert_equal code, ary.code
|
24
|
+
assert_equal code, ary[0].code
|
25
|
+
|
26
|
+
assert_equal code, ary.first.code
|
27
|
+
assert_equal code, ary.last.code
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_array_first_last
|
31
|
+
%w(first last).each do |method|
|
32
|
+
ary = ["string"]
|
33
|
+
code = "Annotation String"
|
34
|
+
AnnotationClass.setup(ary, code)
|
35
|
+
ary.extend AnnotatedArray
|
36
|
+
assert_equal [AnnotationClass], ary.annotation_types
|
37
|
+
|
38
|
+
assert_equal code, ary.send(method).code
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_array_each
|
43
|
+
ary = ["string"]
|
44
|
+
code = "Annotation String"
|
45
|
+
AnnotationClass.setup(ary, code)
|
46
|
+
ary.extend AnnotatedArray
|
47
|
+
|
48
|
+
codes = []
|
49
|
+
ary.each{|v| codes << v.code }
|
50
|
+
assert_equal [code], codes
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_array_inject
|
54
|
+
ary = ["string"]
|
55
|
+
code = "Annotation String"
|
56
|
+
AnnotationClass.setup(ary, code)
|
57
|
+
ary.extend AnnotatedArray
|
58
|
+
|
59
|
+
codes = []
|
60
|
+
codes = ary.inject(codes){|acc,v| acc.push(v.code) }
|
61
|
+
assert_equal [code], codes
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_array_collect
|
65
|
+
ary = ["string"]
|
66
|
+
code = "Annotation String"
|
67
|
+
AnnotationClass.setup(ary, code)
|
68
|
+
ary.extend AnnotatedArray
|
69
|
+
|
70
|
+
codes = ary.collect{|v| v.code }
|
71
|
+
assert_equal [code], codes
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_array_collect_no_block
|
75
|
+
ary = ["string"]
|
76
|
+
code = "Annotation String"
|
77
|
+
AnnotationClass.setup(ary, code)
|
78
|
+
ary.extend AnnotatedArray
|
79
|
+
|
80
|
+
codes = ary.collect
|
81
|
+
assert_equal ["string"], codes
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_compact
|
85
|
+
ary = [nil,"string"]
|
86
|
+
code = "Annotation String"
|
87
|
+
AnnotationClass.setup(ary, code)
|
88
|
+
ary.extend AnnotatedArray
|
89
|
+
|
90
|
+
assert_equal code, ary.compact.first.code
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_reverse
|
94
|
+
ary = ["string2", "string1"]
|
95
|
+
code = "Annotation String"
|
96
|
+
AnnotationClass.setup(ary, code)
|
97
|
+
ary.extend AnnotatedArray
|
98
|
+
|
99
|
+
assert_equal code, ary.reverse.first.code
|
100
|
+
assert_equal "string1", ary.reverse.first
|
101
|
+
end
|
102
|
+
|
103
|
+
def test_purge
|
104
|
+
ary = ["string2", "string1"]
|
105
|
+
code = "Annotation String"
|
106
|
+
AnnotationClass.setup(ary, code)
|
107
|
+
ary.extend AnnotatedArray
|
108
|
+
|
109
|
+
assert Annotation.is_annotated?(ary)
|
110
|
+
assert Annotation.is_annotated?(ary.first)
|
111
|
+
|
112
|
+
ary = Annotation.purge(ary)
|
113
|
+
|
114
|
+
refute Annotation.is_annotated?(ary)
|
115
|
+
refute Annotation.is_annotated?(ary.first)
|
116
|
+
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
@@ -26,5 +26,59 @@ class TestMiscDigest < Test::Unit::TestCase
|
|
26
26
|
end
|
27
27
|
end
|
28
28
|
end
|
29
|
+
|
30
|
+
def test_file_digest
|
31
|
+
content1 =<<-EOF
|
32
|
+
This is one file
|
33
|
+
EOF
|
34
|
+
|
35
|
+
content2 =<<-EOF
|
36
|
+
This is another file
|
37
|
+
EOF
|
38
|
+
|
39
|
+
TmpFile.with_file(content1) do |file1|
|
40
|
+
TmpFile.with_file(content2) do |file2|
|
41
|
+
digest1 = Misc.digest_file(file1)
|
42
|
+
digest2 = Misc.digest_file(file2)
|
43
|
+
refute_equal digest1, digest2
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_file_digest_fast
|
49
|
+
content1 =<<-EOF
|
50
|
+
This is one file
|
51
|
+
EOF
|
52
|
+
|
53
|
+
content2 =<<-EOF
|
54
|
+
This is another file
|
55
|
+
EOF
|
56
|
+
|
57
|
+
TmpFile.with_file(content1) do |file1|
|
58
|
+
TmpFile.with_file(content2) do |file2|
|
59
|
+
digest1 = Misc.fast_file_md5(file1, 5)
|
60
|
+
digest2 = Misc.fast_file_md5(file2, 5)
|
61
|
+
refute_equal digest1, digest2
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_file_digest_fast_2
|
67
|
+
content1 =<<-EOF
|
68
|
+
This is file 2
|
69
|
+
EOF
|
70
|
+
|
71
|
+
content2 =<<-EOF
|
72
|
+
This is file 1
|
73
|
+
EOF
|
74
|
+
|
75
|
+
TmpFile.with_file(content1) do |file1|
|
76
|
+
TmpFile.with_file(content2) do |file2|
|
77
|
+
digest1 = Misc.fast_file_md5(file1, 5)
|
78
|
+
digest2 = Misc.fast_file_md5(file2, 5)
|
79
|
+
refute_equal digest1, digest2
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
29
83
|
end
|
30
84
|
|
@@ -26,5 +26,33 @@ class TestFilesystem < Test::Unit::TestCase
|
|
26
26
|
assert Misc.path_relative_to(File.dirname(tmpdir), File.join(tmpdir, "foo"))
|
27
27
|
end
|
28
28
|
end
|
29
|
+
|
30
|
+
def test_tarize
|
31
|
+
TmpFile.with_path do |source|
|
32
|
+
Open.write(source.data.file1, 'test1')
|
33
|
+
Open.write(source.data.file2, 'test2')
|
34
|
+
TmpFile.with_path extension: 'tar.gz' do |tarball|
|
35
|
+
Misc.tarize(source, tarball)
|
36
|
+
TmpFile.with_path do |dest|
|
37
|
+
Misc.untar(tarball, dest)
|
38
|
+
assert dest.data.file1.exists?
|
39
|
+
assert_equal 'test2', Open.read(dest.data.file2)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_tarize_stream
|
46
|
+
TmpFile.with_path do |source|
|
47
|
+
Open.write(source.data.file1, 'test1')
|
48
|
+
Open.write(source.data.file2, 'test2')
|
49
|
+
stream = Misc.tarize(source)
|
50
|
+
TmpFile.with_path do |dest|
|
51
|
+
Misc.untar(stream, dest)
|
52
|
+
assert dest.data.file1.exists?
|
53
|
+
assert_equal 'test2', Open.read(dest.data.file2)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
29
57
|
end
|
30
58
|
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require File.expand_path(__FILE__).sub(%r(/test/.*), '/test/test_helper.rb')
|
2
|
+
require File.expand_path(__FILE__).sub(%r(.*/test/), '').sub(/test_(.*)\.rb/,'\1')
|
3
|
+
|
4
|
+
class TestMiscHelper < Test::Unit::TestCase
|
5
|
+
def test_divide
|
6
|
+
assert_equal 2, Misc.divide(%w(1 2 3 4 5 6 7 8 9),2).length
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_ordered_divide
|
10
|
+
assert_equal 5, Misc.ordered_divide(%w(1 2 3 4 5 6 7 8 9),2).length
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require File.expand_path(__FILE__).sub(%r(/test/.*), '/test/test_helper.rb')
|
2
|
+
require File.expand_path(__FILE__).sub(%r(.*/test/), '').sub(/test_(.*)\.rb/,'\1')
|
3
|
+
|
4
|
+
class TestMiscMath < Test::Unit::TestCase
|
5
|
+
def test_mean
|
6
|
+
assert_equal 4, Misc.mean([6,2])
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
@@ -106,5 +106,37 @@ class TestPathFind < Test::Unit::TestCase
|
|
106
106
|
end
|
107
107
|
end
|
108
108
|
|
109
|
+
def test_plain_map
|
110
|
+
path = Path.setup("somefile")
|
111
|
+
TmpFile.with_path do |tmpdir|
|
112
|
+
Open.write(tmpdir.somefile, 'test')
|
113
|
+
path.path_maps["tmpdir"] = tmpdir
|
114
|
+
assert path.exists?
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
def test_add_path
|
119
|
+
TmpFile.with_path do |dir1|
|
120
|
+
TmpFile.with_path do |dir2|
|
121
|
+
TmpFile.with_path do |dir3|
|
122
|
+
TmpFile.with_path do |dir4|
|
123
|
+
Open.write(dir1.foo, "FOO1")
|
124
|
+
Open.write(dir2.foo, "FOO2")
|
125
|
+
Open.write(dir3.foo, "FOO3")
|
126
|
+
Open.write(dir4.foo, "FOO4")
|
127
|
+
file = Path.setup('foo')
|
128
|
+
file.append_path 'dir1', dir1
|
129
|
+
assert_equal "FOO1", Open.read(file)
|
130
|
+
file.prepend_path 'dir2', dir2
|
131
|
+
assert_equal "FOO2", Open.read(file)
|
132
|
+
file.prepend_path 'dir3', dir3
|
133
|
+
assert_equal "FOO3", Open.read(file)
|
134
|
+
file.append_path 'dir4', dir4
|
135
|
+
assert_equal "FOO3", Open.read(file)
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
109
141
|
end
|
110
142
|
|
@@ -0,0 +1,169 @@
|
|
1
|
+
require File.expand_path(__FILE__).sub(%r(/test/.*), '/test/test_helper.rb')
|
2
|
+
require File.expand_path(__FILE__).sub(%r(.*/test/), '').sub(/test_(.*)\.rb/,'\1')
|
3
|
+
|
4
|
+
class TestAnnotation < Test::Unit::TestCase
|
5
|
+
|
6
|
+
module EmptyAnnotationClass
|
7
|
+
extend Annotation
|
8
|
+
end
|
9
|
+
|
10
|
+
module AnnotationClass
|
11
|
+
extend Annotation
|
12
|
+
|
13
|
+
annotation :code, :code2
|
14
|
+
end
|
15
|
+
|
16
|
+
module AnnotationClass2
|
17
|
+
extend Annotation
|
18
|
+
|
19
|
+
annotation :code3, :code4
|
20
|
+
end
|
21
|
+
|
22
|
+
module AnnotationClassInherit
|
23
|
+
extend Annotation
|
24
|
+
|
25
|
+
annotation :code_pre
|
26
|
+
|
27
|
+
include AnnotationClass
|
28
|
+
include AnnotationClass2
|
29
|
+
|
30
|
+
annotation :code5
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_setup_annotate
|
34
|
+
str = "String"
|
35
|
+
refute Annotation.is_annotated?(str)
|
36
|
+
AnnotationClass.setup(str, :code)
|
37
|
+
assert AnnotationClass === str
|
38
|
+
assert Annotation.is_annotated?(str)
|
39
|
+
assert_equal :code, str.code
|
40
|
+
|
41
|
+
str2 = "String2"
|
42
|
+
str.annotate(str2)
|
43
|
+
assert_equal :code, str2.code
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_inheritance
|
47
|
+
str = "String"
|
48
|
+
AnnotationClass.setup(str, :c, :c2)
|
49
|
+
assert_equal :c, str.code
|
50
|
+
|
51
|
+
str = "String"
|
52
|
+
AnnotationClassInherit.setup(str, :c_pre, :c, :c2, :c3, :c4, :c5)
|
53
|
+
assert_equal :c_pre, str.code_pre
|
54
|
+
assert_equal :c, str.code
|
55
|
+
assert_equal :c4, str.code4
|
56
|
+
assert_equal :c5, str.code5
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_setup_annotate_double
|
60
|
+
str = "String"
|
61
|
+
AnnotationClass.setup(str, :c, :c2)
|
62
|
+
AnnotationClass2.setup(str, :c3, :c4)
|
63
|
+
assert Annotation.is_annotated?(str)
|
64
|
+
assert AnnotationClass === str
|
65
|
+
assert AnnotationClass2 === str
|
66
|
+
assert_equal :c, str.code
|
67
|
+
assert_equal :c2, str.code2
|
68
|
+
assert_equal :c3, str.code3
|
69
|
+
assert_equal :c4, str.code4
|
70
|
+
|
71
|
+
str2 = "String2"
|
72
|
+
str.annotate(str2)
|
73
|
+
assert Annotation.is_annotated?(str2)
|
74
|
+
assert AnnotationClass === str2
|
75
|
+
assert AnnotationClass2 === str2
|
76
|
+
assert_equal :c, str2.code
|
77
|
+
assert_equal :c2, str2.code2
|
78
|
+
assert_equal :c3, str2.code3
|
79
|
+
assert_equal :c4, str2.code4
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_marshal
|
83
|
+
str = "String"
|
84
|
+
AnnotationClass.setup(str, :code)
|
85
|
+
assert AnnotationClass === str
|
86
|
+
assert_equal :code, str.code
|
87
|
+
|
88
|
+
str2 = Marshal.load(Marshal.dump(str))
|
89
|
+
assert_equal :code, str2.code
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_setup_alternatives
|
93
|
+
str = "String"
|
94
|
+
|
95
|
+
AnnotationClass.setup(str, nil, :code)
|
96
|
+
assert_equal nil, str.code
|
97
|
+
assert_equal :code, str.code2
|
98
|
+
|
99
|
+
AnnotationClass.setup(str, :code2 => :code)
|
100
|
+
assert_equal :code, str.code2
|
101
|
+
|
102
|
+
AnnotationClass.setup(str, code2: :code)
|
103
|
+
assert_equal :code, str.code2
|
104
|
+
|
105
|
+
AnnotationClass.setup(str, "code2" => :code)
|
106
|
+
assert_equal :code, str.code2
|
107
|
+
end
|
108
|
+
|
109
|
+
def test_setup_block
|
110
|
+
o = AnnotationClass.setup nil, :code => :c, :code2 => :c2 do
|
111
|
+
puts 1
|
112
|
+
end
|
113
|
+
|
114
|
+
assert o.annotation_hash.include?(:code)
|
115
|
+
assert o.annotation_hash.include?(:code2)
|
116
|
+
end
|
117
|
+
|
118
|
+
def test_twice
|
119
|
+
str = "String"
|
120
|
+
|
121
|
+
AnnotationClass.setup(str, :code2 => :code)
|
122
|
+
assert_equal :code, str.code2
|
123
|
+
assert_include str.instance_variable_get(:@annotations), :code
|
124
|
+
|
125
|
+
str.extend AnnotationClass2
|
126
|
+
str.code3 = :code_alt
|
127
|
+
assert_equal :code, str.code2
|
128
|
+
assert_equal :code_alt, str.code3
|
129
|
+
assert_include str.instance_variable_get(:@annotations), :code
|
130
|
+
assert_include str.instance_variable_get(:@annotations), :code3
|
131
|
+
|
132
|
+
assert_include str.annotation_hash, :code
|
133
|
+
assert_include str.annotation_hash, :code3
|
134
|
+
end
|
135
|
+
|
136
|
+
def test_annotation_types
|
137
|
+
str = "String"
|
138
|
+
AnnotationClass.setup(str, :code)
|
139
|
+
assert AnnotationClass === str
|
140
|
+
assert_include str.annotation_types, AnnotationClass
|
141
|
+
end
|
142
|
+
|
143
|
+
def test_meta_setup
|
144
|
+
str = "String"
|
145
|
+
Annotation.setup(str, [AnnotationClass], code: 'Some code')
|
146
|
+
|
147
|
+
assert_equal 'Some code', str.code
|
148
|
+
end
|
149
|
+
|
150
|
+
def test_empty
|
151
|
+
refute EmptyAnnotationClass.setup("foo").nil?
|
152
|
+
end
|
153
|
+
|
154
|
+
def test_dump
|
155
|
+
a = AnnotationClass.setup("a", code: 'test1', code2: 'test2')
|
156
|
+
d = Marshal.dump(a)
|
157
|
+
a2 = Marshal.load(d)
|
158
|
+
assert_equal 'test1', a2.code
|
159
|
+
end
|
160
|
+
|
161
|
+
def test_dump_array
|
162
|
+
a = AnnotationClass.setup(["a"], code: 'test1', code2: 'test2')
|
163
|
+
a.extend AnnotatedArray
|
164
|
+
d = Marshal.dump(a)
|
165
|
+
a2 = Marshal.load(d)
|
166
|
+
assert_equal 'test1', a2.first.code
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
data/test/scout/test_persist.rb
CHANGED
@@ -158,11 +158,27 @@ class TestPersist < Test::Unit::TestCase
|
|
158
158
|
end
|
159
159
|
|
160
160
|
def test_path_prefix
|
161
|
-
Persist.persist('foo', :
|
161
|
+
Persist.persist('foo', :marshal, :prefix => "TSV") do |filename|
|
162
162
|
assert File.basename(filename).start_with? "TSV"
|
163
163
|
end
|
164
164
|
end
|
165
165
|
|
166
|
+
def test_persist_with_data
|
167
|
+
res = Persist.persist('foo', :marshal, :prefix => "TSV", :data => {3 => 4}) do |data|
|
168
|
+
data[1] = 2
|
169
|
+
end
|
170
|
+
assert_equal 2, res[1]
|
171
|
+
assert_equal 4, res[3]
|
172
|
+
res2 = nil
|
173
|
+
assert_nothing_raised do
|
174
|
+
res2 = Persist.persist('foo', :marshal, :prefix => "TSV", :data => {}) do |data|
|
175
|
+
raise
|
176
|
+
end
|
177
|
+
end
|
178
|
+
assert_equal 2, res2[1]
|
179
|
+
assert_equal 4, res2[3]
|
180
|
+
end
|
181
|
+
|
166
182
|
def __test_speed
|
167
183
|
times = 100_000
|
168
184
|
TmpFile.with_file do |tmpfile|
|
data/test/scout/test_resource.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require File.expand_path(__FILE__).sub(%r(/test/.*), '/test/test_helper.rb')
|
2
2
|
require File.expand_path(__FILE__).sub(%r(.*/test/), '').sub(/test_(.*)\.rb/,'\1')
|
3
3
|
|
4
|
+
require 'scout/resource/scout'
|
4
5
|
class TestResourceUnit < Test::Unit::TestCase
|
5
6
|
module TestResource
|
6
7
|
extend Resource
|
@@ -8,19 +9,18 @@ class TestResourceUnit < Test::Unit::TestCase
|
|
8
9
|
self.subdir = Path.setup('tmp/test-resource')
|
9
10
|
end
|
10
11
|
|
11
|
-
|
12
12
|
def test_root
|
13
13
|
|
14
14
|
p = TestResource.root.some_file
|
15
15
|
assert p.find(:user).include?(ENV["HOME"])
|
16
16
|
end
|
17
17
|
|
18
|
-
def
|
19
|
-
assert_equal 'etc
|
20
|
-
assert_equal 'share/databases
|
21
|
-
assert_equal 'share/databases/DATABASE',
|
22
|
-
assert_equal 'share/databases/DATABASE/FILE',
|
23
|
-
assert_equal 'share/databases/DATABASE/FILE',
|
24
|
-
assert_equal 'share/databases/DATABASE/FILE',
|
18
|
+
def test_identify
|
19
|
+
assert_equal 'etc', Scout.identify(File.join(ENV["HOME"], '.scout/etc'))
|
20
|
+
assert_equal 'share/databases', Resource.identify('/usr/local/share/scout/databases/')
|
21
|
+
assert_equal 'share/databases/DATABASE', Resource.identify('/usr/local/share/scout/databases/DATABASE')
|
22
|
+
assert_equal 'share/databases/DATABASE/FILE', Resource.identify('/usr/local/share/scout/databases/DATABASE/FILE')
|
23
|
+
assert_equal 'share/databases/DATABASE/FILE', Resource.identify(File.join(ENV["HOME"], '.scout/share/databases/DATABASE/FILE'))
|
24
|
+
assert_equal 'share/databases/DATABASE/FILE', Resource.identify('/usr/local/share/scout/databases/DATABASE/FILE')
|
25
25
|
end
|
26
26
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scout-essentials
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Miguel Vazquez
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-05-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: shoulda
|
@@ -124,6 +124,10 @@ files:
|
|
124
124
|
- Rakefile
|
125
125
|
- VERSION
|
126
126
|
- lib/scout-essentials.rb
|
127
|
+
- lib/scout/annotation.rb
|
128
|
+
- lib/scout/annotation/annotated_object.rb
|
129
|
+
- lib/scout/annotation/annotation_module.rb
|
130
|
+
- lib/scout/annotation/array.rb
|
127
131
|
- lib/scout/cmd.rb
|
128
132
|
- lib/scout/concurrent_stream.rb
|
129
133
|
- lib/scout/config.rb
|
@@ -139,13 +143,13 @@ files:
|
|
139
143
|
- lib/scout/log/progress/report.rb
|
140
144
|
- lib/scout/log/progress/util.rb
|
141
145
|
- lib/scout/log/trap.rb
|
142
|
-
- lib/scout/meta_extension.rb
|
143
146
|
- lib/scout/misc.rb
|
144
147
|
- lib/scout/misc/digest.rb
|
145
148
|
- lib/scout/misc/filesystem.rb
|
146
149
|
- lib/scout/misc/format.rb
|
147
150
|
- lib/scout/misc/helper.rb
|
148
151
|
- lib/scout/misc/insist.rb
|
152
|
+
- lib/scout/misc/math.rb
|
149
153
|
- lib/scout/misc/monitor.rb
|
150
154
|
- lib/scout/misc/system.rb
|
151
155
|
- lib/scout/named_array.rb
|
@@ -182,6 +186,8 @@ files:
|
|
182
186
|
- share/color/color_names
|
183
187
|
- share/color/diverging_colors.hex
|
184
188
|
- share/software/install_helpers
|
189
|
+
- test/scout/annotation/test_annotated_object.rb
|
190
|
+
- test/scout/annotation/test_array.rb
|
185
191
|
- test/scout/indiferent_hash/test_case_insensitive.rb
|
186
192
|
- test/scout/indiferent_hash/test_options.rb
|
187
193
|
- test/scout/log/test_color.rb
|
@@ -189,7 +195,9 @@ files:
|
|
189
195
|
- test/scout/log/test_progress.rb
|
190
196
|
- test/scout/misc/test_digest.rb
|
191
197
|
- test/scout/misc/test_filesystem.rb
|
198
|
+
- test/scout/misc/test_helper.rb
|
192
199
|
- test/scout/misc/test_insist.rb
|
200
|
+
- test/scout/misc/test_math.rb
|
193
201
|
- test/scout/misc/test_system.rb
|
194
202
|
- test/scout/open/test_lock.rb
|
195
203
|
- test/scout/open/test_remote.rb
|
@@ -208,12 +216,12 @@ files:
|
|
208
216
|
- test/scout/simple_opt/test_get.rb
|
209
217
|
- test/scout/simple_opt/test_parse.rb
|
210
218
|
- test/scout/simple_opt/test_setup.rb
|
219
|
+
- test/scout/test_annotation.rb
|
211
220
|
- test/scout/test_cmd.rb
|
212
221
|
- test/scout/test_concurrent_stream.rb
|
213
222
|
- test/scout/test_config.rb
|
214
223
|
- test/scout/test_indiferent_hash.rb
|
215
224
|
- test/scout/test_log.rb
|
216
|
-
- test/scout/test_meta_extension.rb
|
217
225
|
- test/scout/test_misc.rb
|
218
226
|
- test/scout/test_named_array.rb
|
219
227
|
- test/scout/test_open.rb
|
@@ -241,7 +249,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
241
249
|
- !ruby/object:Gem::Version
|
242
250
|
version: '0'
|
243
251
|
requirements: []
|
244
|
-
rubygems_version: 3.5.
|
252
|
+
rubygems_version: 3.5.10
|
245
253
|
signing_key:
|
246
254
|
specification_version: 4
|
247
255
|
summary: Scout essential tools
|
data/lib/scout/meta_extension.rb
DELETED
@@ -1,101 +0,0 @@
|
|
1
|
-
module MetaExtension
|
2
|
-
def self.extended(base)
|
3
|
-
meta = class << base; self; end
|
4
|
-
|
5
|
-
base.class_variable_set("@@extension_attrs", []) unless base.class_variables.include?("@@extension_attrs")
|
6
|
-
|
7
|
-
meta.define_method(:extension_attr) do |*attrs|
|
8
|
-
self.class_variable_get("@@extension_attrs").concat attrs
|
9
|
-
attrs.each do |a|
|
10
|
-
self.attr_accessor a
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
meta.define_method(:extended) do |obj|
|
15
|
-
attrs = self.class_variable_get("@@extension_attrs")
|
16
|
-
|
17
|
-
obj.instance_variable_set(:@extension_attrs, []) unless obj.instance_variables.include?(:@extension_attrs)
|
18
|
-
extension_attrs = obj.instance_variable_get(:@extension_attrs)
|
19
|
-
extension_attrs.concat attrs
|
20
|
-
end
|
21
|
-
|
22
|
-
meta.define_method(:setup) do |*args,&block|
|
23
|
-
if block_given?
|
24
|
-
obj, rest = block, args
|
25
|
-
else
|
26
|
-
obj, *rest = args
|
27
|
-
end
|
28
|
-
obj = block if obj.nil?
|
29
|
-
obj.extend base unless base === obj
|
30
|
-
|
31
|
-
attrs = self.class_variable_get("@@extension_attrs")
|
32
|
-
|
33
|
-
return if attrs.nil? || attrs.empty?
|
34
|
-
|
35
|
-
if rest.length == 1 && Hash === (rlast = rest.last) &&
|
36
|
-
((! (rlkey = rlast.keys.first).nil? && attrs.include?(rlkey.to_sym)) ||
|
37
|
-
(! attrs.length != 1 ))
|
38
|
-
|
39
|
-
pairs = rlast
|
40
|
-
else
|
41
|
-
pairs = attrs.zip(rest)
|
42
|
-
end
|
43
|
-
|
44
|
-
pairs.each do |name,value|
|
45
|
-
obj.instance_variable_set("@#{name}", value)
|
46
|
-
end
|
47
|
-
|
48
|
-
obj
|
49
|
-
end
|
50
|
-
|
51
|
-
base.define_method(:extension_attr_hash) do
|
52
|
-
attr_hash = {}
|
53
|
-
@extension_attrs.each do |name|
|
54
|
-
attr_hash[name] = self.instance_variable_get("@#{name}")
|
55
|
-
end
|
56
|
-
attr_hash
|
57
|
-
end
|
58
|
-
|
59
|
-
base.define_method(:annotate) do |other|
|
60
|
-
attr_values = @extension_attrs.collect do |a|
|
61
|
-
self.instance_variable_get("@#{a}")
|
62
|
-
end
|
63
|
-
base.setup(other, *attr_values)
|
64
|
-
end
|
65
|
-
|
66
|
-
base.define_method(:purge) do
|
67
|
-
new = self.dup
|
68
|
-
|
69
|
-
if new.instance_variables.include?(:@extension_attrs)
|
70
|
-
new.instance_variable_get(:@extension_attrs).each do |a|
|
71
|
-
var_name = "@#{a}".to_sym
|
72
|
-
new.remove_instance_variable(var_name) if new.instance_variables.include? var_name
|
73
|
-
end
|
74
|
-
new.remove_instance_variable("@extension_attrs")
|
75
|
-
end
|
76
|
-
|
77
|
-
new
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
def self.is_extended?(obj)
|
82
|
-
obj.respond_to?(:extension_attr_hash)
|
83
|
-
end
|
84
|
-
|
85
|
-
def self.purge(obj)
|
86
|
-
case obj
|
87
|
-
when nil
|
88
|
-
nil
|
89
|
-
when Array
|
90
|
-
obj.collect{|e| purge(e) }
|
91
|
-
when Hash
|
92
|
-
new = {}
|
93
|
-
obj.each do |k,v|
|
94
|
-
new[k] = purge(v)
|
95
|
-
end
|
96
|
-
new
|
97
|
-
else
|
98
|
-
is_extended?(obj) ? obj.purge : obj
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|