scout-essentials 1.3.1 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/.vimproject +33 -1
  3. data/VERSION +1 -1
  4. data/lib/scout/annotation/annotated_object.rb +69 -0
  5. data/lib/scout/annotation/annotation_module.rb +59 -0
  6. data/lib/scout/annotation/array.rb +74 -0
  7. data/lib/scout/annotation.rb +45 -0
  8. data/lib/scout/concurrent_stream.rb +4 -1
  9. data/lib/scout/config.rb +3 -3
  10. data/lib/scout/exceptions.rb +2 -1
  11. data/lib/scout/indiferent_hash/options.rb +2 -1
  12. data/lib/scout/log/color.rb +1 -1
  13. data/lib/scout/log.rb +11 -11
  14. data/lib/scout/misc/digest.rb +39 -8
  15. data/lib/scout/misc/filesystem.rb +23 -0
  16. data/lib/scout/misc/format.rb +32 -0
  17. data/lib/scout/misc/helper.rb +37 -0
  18. data/lib/scout/misc/math.rb +109 -0
  19. data/lib/scout/misc/system.rb +18 -2
  20. data/lib/scout/misc.rb +1 -0
  21. data/lib/scout/named_array.rb +8 -6
  22. data/lib/scout/open/remote.rb +8 -3
  23. data/lib/scout/open/stream.rb +5 -1
  24. data/lib/scout/open/util.rb +1 -1
  25. data/lib/scout/path/find.rb +30 -8
  26. data/lib/scout/path/util.rb +1 -1
  27. data/lib/scout/path.rb +10 -4
  28. data/lib/scout/persist/open.rb +1 -1
  29. data/lib/scout/persist/serialize.rb +5 -1
  30. data/lib/scout/persist.rb +49 -20
  31. data/lib/scout/resource/path.rb +1 -1
  32. data/lib/scout/resource/scout.rb +2 -0
  33. data/lib/scout/resource/util.rb +8 -3
  34. data/lib/scout/resource.rb +15 -3
  35. data/scout-essentials.gemspec +21 -13
  36. data/test/scout/annotation/test_annotated_object.rb +0 -0
  37. data/test/scout/annotation/test_array.rb +119 -0
  38. data/test/scout/misc/test_digest.rb +54 -0
  39. data/test/scout/misc/test_filesystem.rb +28 -0
  40. data/test/scout/misc/test_helper.rb +14 -0
  41. data/test/scout/misc/test_math.rb +9 -0
  42. data/test/scout/path/test_find.rb +32 -0
  43. data/test/scout/test_annotation.rb +169 -0
  44. data/test/scout/test_persist.rb +17 -1
  45. data/test/scout/test_resource.rb +8 -8
  46. metadata +13 -5
  47. data/lib/scout/meta_extension.rb +0 -101
  48. data/test/scout/test_meta_extension.rb +0 -80
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.3.1
4
+ version: 1.5.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: 2023-11-07 00:00:00.000000000 Z
11
+ date: 2024-05-28 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.0.dev
252
+ rubygems_version: 3.5.10
245
253
  signing_key:
246
254
  specification_version: 4
247
255
  summary: Scout essential tools
@@ -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
@@ -1,80 +0,0 @@
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 TestMetaExtension < Test::Unit::TestCase
5
- module ExtensionClass
6
- extend MetaExtension
7
-
8
- extension_attr :code, :code2
9
- end
10
-
11
- module ExtensionClass2
12
- extend MetaExtension
13
-
14
- extension_attr :code3, :code4
15
- end
16
-
17
-
18
- def test_setup_annotate
19
- str = "String"
20
- ExtensionClass.setup(str, :code)
21
- assert ExtensionClass === str
22
- assert_equal :code, str.code
23
-
24
- str2 = "String2"
25
- str.annotate(str2)
26
- assert_equal :code, str2.code
27
- end
28
-
29
- def test_marshal
30
- str = "String"
31
- ExtensionClass.setup(str, :code)
32
- assert ExtensionClass === str
33
- assert_equal :code, str.code
34
-
35
- str2 = Marshal.load(Marshal.dump(str))
36
- assert_equal :code, str2.code
37
- end
38
-
39
- def test_setup_alternatives
40
- str = "String"
41
-
42
- ExtensionClass.setup(str, :code2 => :code)
43
- assert_equal :code, str.code2
44
-
45
- ExtensionClass.setup(str, code2: :code)
46
- assert_equal :code, str.code2
47
-
48
- ExtensionClass.setup(str, "code2" => :code)
49
- assert_equal :code, str.code2
50
-
51
- end
52
-
53
- def test_setup_block
54
- o = ExtensionClass.setup nil, :code => :c, :code2 => :c2 do
55
- puts 1
56
- end
57
-
58
- assert o.extension_attr_hash.include?(:code)
59
- assert o.extension_attr_hash.include?(:code2)
60
- end
61
-
62
- def test_twice
63
- str = "String"
64
-
65
- ExtensionClass.setup(str, :code2 => :code)
66
- assert_equal :code, str.code2
67
- assert_include str.instance_variable_get(:@extension_attrs), :code
68
-
69
- str.extend ExtensionClass2
70
- str.code3 = :code_alt
71
- assert_equal :code, str.code2
72
- assert_equal :code_alt, str.code3
73
- assert_include str.instance_variable_get(:@extension_attrs), :code
74
- assert_include str.instance_variable_get(:@extension_attrs), :code3
75
-
76
- assert_include str.extension_attr_hash, :code
77
- assert_include str.extension_attr_hash, :code3
78
- end
79
- end
80
-