nrser 0.0.26 → 0.0.27

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/lib/nrser.rb +1 -0
  3. data/lib/nrser/array.rb +15 -0
  4. data/lib/nrser/binding.rb +7 -1
  5. data/lib/nrser/enumerable.rb +21 -1
  6. data/lib/nrser/errors.rb +56 -6
  7. data/lib/nrser/hash/deep_merge.rb +1 -1
  8. data/lib/nrser/message.rb +33 -0
  9. data/lib/nrser/meta/props.rb +77 -15
  10. data/lib/nrser/meta/props/prop.rb +276 -44
  11. data/lib/nrser/proc.rb +7 -3
  12. data/lib/nrser/refinements/array.rb +5 -0
  13. data/lib/nrser/refinements/enumerable.rb +5 -0
  14. data/lib/nrser/refinements/hash.rb +8 -0
  15. data/lib/nrser/refinements/object.rb +11 -1
  16. data/lib/nrser/refinements/string.rb +17 -3
  17. data/lib/nrser/refinements/symbol.rb +8 -0
  18. data/lib/nrser/refinements/tree.rb +22 -0
  19. data/lib/nrser/rspex.rb +312 -70
  20. data/lib/nrser/rspex/shared_examples.rb +116 -0
  21. data/lib/nrser/string.rb +159 -27
  22. data/lib/nrser/temp/unicode_math.rb +48 -0
  23. data/lib/nrser/text.rb +3 -0
  24. data/lib/nrser/text/indentation.rb +210 -0
  25. data/lib/nrser/text/lines.rb +52 -0
  26. data/lib/nrser/text/word_wrap.rb +29 -0
  27. data/lib/nrser/tree.rb +4 -78
  28. data/lib/nrser/tree/each_branch.rb +76 -0
  29. data/lib/nrser/tree/map_branches.rb +91 -0
  30. data/lib/nrser/tree/map_tree.rb +97 -0
  31. data/lib/nrser/tree/transform.rb +56 -13
  32. data/lib/nrser/types.rb +1 -0
  33. data/lib/nrser/types/array.rb +15 -3
  34. data/lib/nrser/types/is_a.rb +40 -1
  35. data/lib/nrser/types/nil.rb +17 -0
  36. data/lib/nrser/types/paths.rb +17 -2
  37. data/lib/nrser/types/strings.rb +57 -22
  38. data/lib/nrser/types/tuples.rb +5 -0
  39. data/lib/nrser/types/type.rb +47 -6
  40. data/lib/nrser/version.rb +1 -1
  41. data/spec/nrser/errors/abstract_method_error_spec.rb +46 -0
  42. data/spec/nrser/meta/props/to_and_from_data_spec.rb +74 -0
  43. data/spec/nrser/meta/props_spec.rb +6 -2
  44. data/spec/nrser/refinements/erb_spec.rb +100 -1
  45. data/spec/nrser/{common_prefix_spec.rb → string/common_prefix_spec.rb} +9 -0
  46. data/spec/nrser/text/dedent_spec.rb +80 -0
  47. data/spec/nrser/tree/map_branch_spec.rb +83 -0
  48. data/spec/nrser/tree/map_tree_spec.rb +123 -0
  49. data/spec/nrser/tree/transform_spec.rb +26 -29
  50. data/spec/nrser/tree/transformer_spec.rb +179 -0
  51. data/spec/nrser/types/paths_spec.rb +73 -45
  52. data/spec/spec_helper.rb +10 -0
  53. metadata +27 -7
  54. data/spec/nrser/dedent_spec.rb +0 -36
@@ -0,0 +1,179 @@
1
+ # Refinements
2
+ # =======================================================================
3
+
4
+ require 'nrser/refinements'
5
+ using NRSER
6
+
7
+
8
+ # Examples
9
+ # =====================================================================
10
+
11
+ describe_method "NRSER.transformer" do
12
+ # ========================================================================
13
+ #
14
+ # Basically the same {NRSER.transform} tests but using {NRSER.transformer}
15
+ # to build the trees instead of {#sender}, {#chainer}, etc.
16
+ #
17
+
18
+ describe_section "Simple Examples" do
19
+ # ========================================================================
20
+
21
+ subject { NRSER.transform tree, source }
22
+
23
+ describe "value swap in {x: 'ex', y: 'why?'}" do
24
+
25
+ let( :tree ) {
26
+ NRSER.transformer do |h|
27
+ {
28
+ x: h[:y],
29
+ y: h[:x],
30
+ }
31
+ end
32
+ } # let :tree
33
+
34
+ let( :source ) {
35
+ {
36
+ x: 'ex',
37
+ y: 'why?'
38
+ }
39
+ } # let :source
40
+
41
+ it { is_expected.to eq x: 'why?', y: 'ex' }
42
+
43
+ end # value swap in {x: 'ex', y: 'why?'}
44
+
45
+
46
+ describe "transform in key" do
47
+
48
+ let :tree do
49
+ NRSER.transformer do |contact|
50
+ {
51
+ users: {
52
+ { id: contact[:id] } => {
53
+ name: contact[:name],
54
+ }
55
+ }
56
+ }
57
+ end
58
+ end
59
+
60
+ let :source do
61
+ {
62
+ id: 123,
63
+ name: "Mr. Cat",
64
+ }
65
+ end
66
+
67
+ it do
68
+ is_expected.to eq \
69
+ users: {
70
+ { id: 123 } => {
71
+ name: "Mr. Cat",
72
+ }
73
+ }
74
+ end
75
+
76
+ end # transform in key
77
+
78
+
79
+ describe "arrays in tree" do
80
+ let :tree do
81
+ NRSER.transformer do |h|
82
+ {
83
+ list: [
84
+ { name: h[:name] },
85
+ { age: h[:age] },
86
+ ]
87
+ }
88
+ end
89
+ end
90
+
91
+ let :source do
92
+ {
93
+ name: 'Mr. Cat',
94
+ age: 2,
95
+ }
96
+ end
97
+
98
+ it do
99
+ is_expected.to eq \
100
+ list: [
101
+ { name: 'Mr. Cat' },
102
+ { age: 2 },
103
+ ]
104
+ end
105
+ end # arrays in tree
106
+
107
+
108
+ end # section simple examples
109
+ # ************************************************************************
110
+
111
+
112
+ describe_section "Real-World Examples" do
113
+ # ========================================================================
114
+
115
+ describe "Address" do
116
+
117
+ let :contact do
118
+ OpenStruct.new id: 123
119
+ end
120
+
121
+ let :address do
122
+ OpenStruct.new \
123
+ id: 987,
124
+ parent: contact,
125
+ address: "东城区",
126
+ street2: "民安小区",
127
+ city: "北京市",
128
+ state: "北京",
129
+ zip: "100010"
130
+ end
131
+
132
+ let :tree do
133
+ NRSER.transformer do |address|
134
+ {
135
+ users: {
136
+ { contact_id: address.parent.id } => {
137
+ addresses: {
138
+ {
139
+ address_id: address.id } => {
140
+ district: address[:address],
141
+ line_1: address[:street2],
142
+ city: address[:city],
143
+ province: address[:state],
144
+ post_code: address[:zip],
145
+ }
146
+ }
147
+ }
148
+ }
149
+ }
150
+ end
151
+ end
152
+
153
+ subject { NRSER.transform tree, address }
154
+
155
+ it do
156
+ is_expected.to eq \
157
+ users: {
158
+ { contact_id: 123 } => {
159
+ addresses: {
160
+ { address_id: 987 } => {
161
+ district: "东城区",
162
+ line_1: "民安小区",
163
+ city: "北京市",
164
+ province: "北京",
165
+ post_code: "100010",
166
+ }
167
+ }
168
+ }
169
+ }
170
+ end
171
+
172
+ end # Address
173
+
174
+ end # section Real-World Examples
175
+ # ************************************************************************
176
+
177
+
178
+ end # NRSER.transform
179
+
@@ -1,51 +1,31 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe "NRSER::Types.dir_path" do
4
- subject { NRSER::Types.method :dir_path }
5
-
6
- include_examples 'make type',
7
- accepts: [
8
- '.',
9
- '/',
10
- Pathname.getwd,
11
- ],
12
-
13
- rejects: [
14
- 'README.md',
15
- ],
16
-
17
- to_data: {
18
- Pathname.getwd => Pathname.getwd.to_s,
19
- }
20
-
21
- end # NRSER::Types.dir_path
3
+ describe_file 'types/paths.rb' do
22
4
 
23
- describe "NRSER::Types.file_path" do
24
- subject { NRSER::Types.method :file_path }
25
-
26
- include_examples 'make type',
27
- accepts: [
28
- ( NRSER::ROOT / 'README.md' ),
29
- ],
30
-
31
- rejects: [
32
- '.',
33
- '/',
34
- Pathname.getwd,
35
- ],
5
+ describe "NRSER::Types.dir_path" do
6
+ subject { NRSER::Types.method :dir_path }
36
7
 
37
- and_is_expected: {
38
- to: {
39
- have_attributes: {
40
- name: 'FilePath',
41
- }
42
- }
43
- }
44
-
45
- context "custom name" do
46
8
  include_examples 'make type',
47
- args: [ name: 'CustomType' ],
9
+ accepts: [
10
+ '.',
11
+ '/',
12
+ Pathname.getwd,
13
+ ],
14
+
15
+ rejects: [
16
+ 'README.md',
17
+ ],
18
+
19
+ to_data: {
20
+ Pathname.getwd => Pathname.getwd.to_s,
21
+ }
48
22
 
23
+ end # NRSER::Types.dir_path
24
+
25
+ describe "NRSER::Types.file_path" do
26
+ subject { NRSER::Types.method :file_path }
27
+
28
+ include_examples 'make type',
49
29
  accepts: [
50
30
  ( NRSER::ROOT / 'README.md' ),
51
31
  ],
@@ -59,11 +39,59 @@ describe "NRSER::Types.file_path" do
59
39
  and_is_expected: {
60
40
  to: {
61
41
  have_attributes: {
62
- name: 'CustomType',
42
+ name: 'FilePath',
63
43
  }
64
44
  }
65
45
  }
66
- end # custom name
46
+
47
+ context "custom name" do
48
+ include_examples 'make type',
49
+ args: [ name: 'CustomType' ],
50
+
51
+ accepts: [
52
+ ( NRSER::ROOT / 'README.md' ),
53
+ ],
54
+
55
+ rejects: [
56
+ '.',
57
+ '/',
58
+ Pathname.getwd,
59
+ ],
60
+
61
+ and_is_expected: {
62
+ to: {
63
+ have_attributes: {
64
+ name: 'CustomType',
65
+ }
66
+ }
67
+ }
68
+ end # custom name
69
+
70
+ end # NRSER::Types.dir_path
71
+
67
72
 
73
+ describe 'NRSER::Types.path_seg' do
74
+ subject { NRSER::Types.method :path_seg }
68
75
 
69
- end # NRSER::Types.dir_path
76
+ include_examples 'make type',
77
+ accepts: [
78
+ 'hey',
79
+ 'ho_let\'s goooo!'
80
+ ],
81
+
82
+ rejects: [
83
+ 'hey/ho',
84
+ ],
85
+
86
+ and_is_expected: {
87
+ to: {
88
+ have_attributes: {
89
+ name: 'POSIXPathSegment',
90
+ }
91
+ }
92
+ }
93
+
94
+ end # NRSER::Types.path_seg
95
+
96
+
97
+ end
@@ -6,6 +6,16 @@ require 'nrser'
6
6
  require 'nrser/logger'
7
7
  require 'nrser/rspex'
8
8
 
9
+
10
+ # Dumping ground for classes and modules that we need to create for tests.
11
+ #
12
+ module NRSER::TestFixtures
13
+
14
+ # module definition...
15
+
16
+ end # module NRSER::TestFixtures
17
+
18
+
9
19
  MAIN = self
10
20
 
11
21
  LOG_LEVELS = {
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nrser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.26
4
+ version: 0.0.27
5
5
  platform: ruby
6
6
  authors:
7
7
  - nrser
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-03 00:00:00.000000000 Z
11
+ date: 2017-12-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -178,12 +178,21 @@ files:
178
178
  - lib/nrser/refinements/tree.rb
179
179
  - lib/nrser/refinements/types.rb
180
180
  - lib/nrser/rspex.rb
181
+ - lib/nrser/rspex/shared_examples.rb
181
182
  - lib/nrser/string.rb
182
183
  - lib/nrser/string/looks_like.rb
184
+ - lib/nrser/temp/unicode_math.rb
183
185
  - lib/nrser/temp/where.rb
186
+ - lib/nrser/text.rb
187
+ - lib/nrser/text/indentation.rb
188
+ - lib/nrser/text/lines.rb
189
+ - lib/nrser/text/word_wrap.rb
184
190
  - lib/nrser/tree.rb
191
+ - lib/nrser/tree/each_branch.rb
185
192
  - lib/nrser/tree/leaves.rb
193
+ - lib/nrser/tree/map_branches.rb
186
194
  - lib/nrser/tree/map_leaves.rb
195
+ - lib/nrser/tree/map_tree.rb
187
196
  - lib/nrser/tree/transform.rb
188
197
  - lib/nrser/types.rb
189
198
  - lib/nrser/types/any.rb
@@ -198,6 +207,7 @@ files:
198
207
  - lib/nrser/types/is_a.rb
199
208
  - lib/nrser/types/labels.rb
200
209
  - lib/nrser/types/maybe.rb
210
+ - lib/nrser/types/nil.rb
201
211
  - lib/nrser/types/numbers.rb
202
212
  - lib/nrser/types/pairs.rb
203
213
  - lib/nrser/types/paths.rb
@@ -211,9 +221,8 @@ files:
211
221
  - lib/nrser/version.rb
212
222
  - spec/nrser/collection/each_spec.rb
213
223
  - spec/nrser/collection/map_spec.rb
214
- - spec/nrser/common_prefix_spec.rb
215
- - spec/nrser/dedent_spec.rb
216
224
  - spec/nrser/enumerable_spec.rb
225
+ - spec/nrser/errors/abstract_method_error_spec.rb
217
226
  - spec/nrser/format_exception_spec.rb
218
227
  - spec/nrser/hash/bury_spec.rb
219
228
  - spec/nrser/hash/guess_label_key_type_spec.rb
@@ -229,6 +238,7 @@ files:
229
238
  - spec/nrser/logger/use_spec.rb
230
239
  - spec/nrser/merge_by_spec.rb
231
240
  - spec/nrser/meta/class_attrs_spec.rb
241
+ - spec/nrser/meta/props/to_and_from_data_spec.rb
232
242
  - spec/nrser/meta/props_spec.rb
233
243
  - spec/nrser/op/message_spec.rb
234
244
  - spec/nrser/open_struct_spec.rb
@@ -241,11 +251,16 @@ files:
241
251
  - spec/nrser/refinements/pathname_spec.rb
242
252
  - spec/nrser/refinements/set_spec.rb
243
253
  - spec/nrser/refinements/truncate_spec.rb
254
+ - spec/nrser/string/common_prefix_spec.rb
244
255
  - spec/nrser/string/looks_like_spec.rb
245
256
  - spec/nrser/template_spec.rb
257
+ - spec/nrser/text/dedent_spec.rb
246
258
  - spec/nrser/tree/each_branch_spec.rb
247
259
  - spec/nrser/tree/leaves_spec.rb
260
+ - spec/nrser/tree/map_branch_spec.rb
261
+ - spec/nrser/tree/map_tree_spec.rb
248
262
  - spec/nrser/tree/transform_spec.rb
263
+ - spec/nrser/tree/transformer_spec.rb
249
264
  - spec/nrser/truncate_spec.rb
250
265
  - spec/nrser/truthy_spec.rb
251
266
  - spec/nrser/types/array_spec.rb
@@ -280,16 +295,15 @@ required_rubygems_version: !ruby/object:Gem::Requirement
280
295
  version: '0'
281
296
  requirements: []
282
297
  rubyforge_project:
283
- rubygems_version: 2.5.2
298
+ rubygems_version: 2.6.11
284
299
  signing_key:
285
300
  specification_version: 4
286
301
  summary: basic ruby utils i use in a lot of stuff.
287
302
  test_files:
288
303
  - spec/nrser/collection/each_spec.rb
289
304
  - spec/nrser/collection/map_spec.rb
290
- - spec/nrser/common_prefix_spec.rb
291
- - spec/nrser/dedent_spec.rb
292
305
  - spec/nrser/enumerable_spec.rb
306
+ - spec/nrser/errors/abstract_method_error_spec.rb
293
307
  - spec/nrser/format_exception_spec.rb
294
308
  - spec/nrser/hash/bury_spec.rb
295
309
  - spec/nrser/hash/guess_label_key_type_spec.rb
@@ -305,6 +319,7 @@ test_files:
305
319
  - spec/nrser/logger/use_spec.rb
306
320
  - spec/nrser/merge_by_spec.rb
307
321
  - spec/nrser/meta/class_attrs_spec.rb
322
+ - spec/nrser/meta/props/to_and_from_data_spec.rb
308
323
  - spec/nrser/meta/props_spec.rb
309
324
  - spec/nrser/op/message_spec.rb
310
325
  - spec/nrser/open_struct_spec.rb
@@ -317,11 +332,16 @@ test_files:
317
332
  - spec/nrser/refinements/pathname_spec.rb
318
333
  - spec/nrser/refinements/set_spec.rb
319
334
  - spec/nrser/refinements/truncate_spec.rb
335
+ - spec/nrser/string/common_prefix_spec.rb
320
336
  - spec/nrser/string/looks_like_spec.rb
321
337
  - spec/nrser/template_spec.rb
338
+ - spec/nrser/text/dedent_spec.rb
322
339
  - spec/nrser/tree/each_branch_spec.rb
323
340
  - spec/nrser/tree/leaves_spec.rb
341
+ - spec/nrser/tree/map_branch_spec.rb
342
+ - spec/nrser/tree/map_tree_spec.rb
324
343
  - spec/nrser/tree/transform_spec.rb
344
+ - spec/nrser/tree/transformer_spec.rb
325
345
  - spec/nrser/truncate_spec.rb
326
346
  - spec/nrser/truthy_spec.rb
327
347
  - spec/nrser/types/array_spec.rb