nrser 0.3.9 → 0.3.10

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.
Files changed (141) hide show
  1. checksums.yaml +4 -4
  2. data/lib/nrser/char/alpha_numeric_sub.rb +9 -19
  3. data/lib/nrser/char/special.rb +5 -5
  4. data/lib/nrser/core_ext/array.rb +36 -13
  5. data/lib/nrser/core_ext/enumerable.rb +1 -0
  6. data/lib/nrser/core_ext/enumerable/find_map.rb +1 -1
  7. data/lib/nrser/core_ext/hash/bury.rb +3 -0
  8. data/lib/nrser/core_ext/hash/extract_values_at.rb +2 -2
  9. data/lib/nrser/core_ext/method/full_name.rb +1 -1
  10. data/lib/nrser/core_ext/module/method_objects.rb +1 -1
  11. data/lib/nrser/core_ext/module/source_locations.rb +27 -15
  12. data/lib/nrser/core_ext/object/lazy_var.rb +1 -1
  13. data/lib/nrser/core_ext/pathname.rb +67 -12
  14. data/lib/nrser/core_ext/pathname/subpath.rb +86 -0
  15. data/lib/nrser/core_ext/string.rb +28 -1
  16. data/lib/nrser/core_ext/symbol.rb +11 -12
  17. data/lib/nrser/errors/README.md +154 -0
  18. data/lib/nrser/errors/attr_error.rb +146 -53
  19. data/lib/nrser/errors/count_error.rb +61 -12
  20. data/lib/nrser/errors/nicer_error.rb +42 -71
  21. data/lib/nrser/errors/value_error.rb +53 -58
  22. data/lib/nrser/functions.rb +0 -2
  23. data/lib/nrser/functions/enumerable.rb +5 -17
  24. data/lib/nrser/functions/enumerable/associate.rb +14 -5
  25. data/lib/nrser/functions/enumerable/find_all_map.rb +1 -1
  26. data/lib/nrser/functions/enumerable/include_slice/array_include_slice.rb +1 -1
  27. data/lib/nrser/functions/hash/bury.rb +2 -12
  28. data/lib/nrser/functions/merge_by.rb +2 -2
  29. data/lib/nrser/functions/module/method_objects.rb +2 -2
  30. data/lib/nrser/functions/path.rb +185 -165
  31. data/lib/nrser/functions/path/normalized.rb +84 -0
  32. data/lib/nrser/functions/string.rb +4 -4
  33. data/lib/nrser/functions/text/README.md +4 -0
  34. data/lib/nrser/functions/text/format.rb +53 -0
  35. data/lib/nrser/functions/text/indentation.rb +6 -6
  36. data/lib/nrser/functions/text/word_wrap.rb +2 -2
  37. data/lib/nrser/functions/tree/map_leaves.rb +3 -3
  38. data/lib/nrser/functions/tree/map_tree.rb +2 -2
  39. data/lib/nrser/functions/tree/transform.rb +1 -18
  40. data/lib/nrser/gem_ext/README.md +4 -0
  41. data/lib/nrser/labs/README.md +8 -0
  42. data/lib/nrser/labs/config.rb +163 -0
  43. data/lib/nrser/labs/i8.rb +49 -159
  44. data/lib/nrser/labs/i8/struct.rb +167 -0
  45. data/lib/nrser/labs/i8/struct/hash.rb +140 -0
  46. data/lib/nrser/labs/i8/struct/vector.rb +149 -0
  47. data/lib/nrser/labs/i8/surjection.rb +211 -0
  48. data/lib/nrser/labs/lots/consumer.rb +19 -0
  49. data/lib/nrser/labs/lots/parser.rb +21 -1
  50. data/lib/nrser/labs/stash.rb +4 -4
  51. data/lib/nrser/log.rb +25 -21
  52. data/lib/nrser/log/appender/sync.rb +15 -11
  53. data/lib/nrser/log/formatters/color.rb +0 -3
  54. data/lib/nrser/log/formatters/mixin.rb +4 -4
  55. data/lib/nrser/log/logger.rb +54 -6
  56. data/lib/nrser/log/mixin.rb +2 -1
  57. data/lib/nrser/log/plugin.rb +6 -6
  58. data/lib/nrser/log/types.rb +46 -29
  59. data/lib/nrser/mean_streak.rb +0 -8
  60. data/lib/nrser/mean_streak/document.rb +1 -4
  61. data/lib/nrser/message.rb +3 -3
  62. data/lib/nrser/meta/README.md +4 -0
  63. data/lib/nrser/meta/lazy_attr.rb +2 -2
  64. data/lib/nrser/meta/source/location.rb +1 -1
  65. data/lib/nrser/props.rb +34 -3
  66. data/lib/nrser/props/class_methods.rb +2 -1
  67. data/lib/nrser/props/instance_methods.rb +9 -9
  68. data/lib/nrser/props/metadata.rb +4 -12
  69. data/lib/nrser/props/mutable/stash.rb +5 -2
  70. data/lib/nrser/props/prop.rb +10 -19
  71. data/lib/nrser/rspex.rb +1 -20
  72. data/lib/nrser/rspex/example_group/describe_attribute.rb +3 -0
  73. data/lib/nrser/rspex/example_group/describe_called_with.rb +9 -4
  74. data/lib/nrser/rspex/example_group/describe_case.rb +1 -0
  75. data/lib/nrser/rspex/example_group/describe_class.rb +2 -0
  76. data/lib/nrser/rspex/example_group/describe_group.rb +1 -1
  77. data/lib/nrser/rspex/example_group/describe_instance.rb +3 -1
  78. data/lib/nrser/rspex/example_group/describe_message.rb +1 -1
  79. data/lib/nrser/rspex/example_group/describe_method.rb +64 -30
  80. data/lib/nrser/rspex/example_group/describe_response_to.rb +1 -1
  81. data/lib/nrser/rspex/example_group/describe_section.rb +4 -1
  82. data/lib/nrser/rspex/example_group/describe_sent_to.rb +1 -1
  83. data/lib/nrser/rspex/example_group/describe_setup.rb +1 -0
  84. data/lib/nrser/rspex/example_group/describe_source_file.rb +1 -1
  85. data/lib/nrser/rspex/example_group/describe_spec_file.rb +4 -2
  86. data/lib/nrser/rspex/example_group/describe_when.rb +2 -1
  87. data/lib/nrser/rspex/example_group/describe_x.rb +5 -5
  88. data/lib/nrser/rspex/format.rb +0 -15
  89. data/lib/nrser/sugar/method_missing_forwarder.rb +3 -3
  90. data/lib/nrser/sys/env/path.rb +2 -28
  91. data/lib/nrser/types.rb +63 -12
  92. data/lib/nrser/types/README.md +76 -0
  93. data/lib/nrser/types/arrays.rb +192 -137
  94. data/lib/nrser/types/attributes.rb +269 -0
  95. data/lib/nrser/types/booleans.rb +134 -83
  96. data/lib/nrser/types/bounded.rb +110 -47
  97. data/lib/nrser/types/collections.rb +119 -0
  98. data/lib/nrser/types/combinators.rb +283 -196
  99. data/lib/nrser/types/doc/display_table.md +66 -0
  100. data/lib/nrser/types/eqiuvalent.rb +91 -0
  101. data/lib/nrser/types/errors/check_error.rb +5 -11
  102. data/lib/nrser/types/errors/from_string_error.rb +3 -3
  103. data/lib/nrser/types/factory.rb +287 -20
  104. data/lib/nrser/types/hashes.rb +227 -179
  105. data/lib/nrser/types/in.rb +73 -36
  106. data/lib/nrser/types/is.rb +67 -60
  107. data/lib/nrser/types/is_a.rb +141 -84
  108. data/lib/nrser/types/labels.rb +45 -16
  109. data/lib/nrser/types/maybe.rb +6 -3
  110. data/lib/nrser/types/nil.rb +64 -27
  111. data/lib/nrser/types/not.rb +92 -34
  112. data/lib/nrser/types/numbers.rb +224 -169
  113. data/lib/nrser/types/pairs.rb +113 -89
  114. data/lib/nrser/types/paths.rb +250 -137
  115. data/lib/nrser/types/responds.rb +167 -89
  116. data/lib/nrser/types/selector.rb +234 -0
  117. data/lib/nrser/types/shape.rb +136 -65
  118. data/lib/nrser/types/strings.rb +189 -63
  119. data/lib/nrser/types/symbols.rb +83 -33
  120. data/lib/nrser/types/top.rb +89 -0
  121. data/lib/nrser/types/tuples.rb +134 -98
  122. data/lib/nrser/types/type.rb +617 -505
  123. data/lib/nrser/types/when.rb +123 -98
  124. data/lib/nrser/types/where.rb +182 -91
  125. data/lib/nrser/version.rb +1 -1
  126. data/spec/lib/nrser/core_ext/pathname/subpath_spec.rb +22 -0
  127. data/spec/lib/nrser/errors/attr_error_spec.rb +68 -0
  128. data/spec/lib/nrser/errors/count_error_spec.rb +69 -0
  129. data/spec/lib/nrser/functions/path/normalize_path_spec.rb +35 -0
  130. data/spec/lib/nrser/functions/tree/map_tree_spec.rb +74 -96
  131. data/spec/lib/nrser/functions/tree/transform_spec.rb +11 -11
  132. data/spec/lib/nrser/labs/config_spec.rb +22 -0
  133. data/spec/lib/nrser/labs/i8/struct_spec.rb +39 -0
  134. data/spec/lib/nrser/types/display_spec.rb +50 -0
  135. data/spec/lib/nrser/types/paths_spec.rb +16 -10
  136. data/spec/lib/nrser/types/selector_spec.rb +125 -0
  137. data/spec/spec_helper.rb +4 -5
  138. metadata +105 -22
  139. data/lib/nrser/types/any.rb +0 -41
  140. data/lib/nrser/types/attrs.rb +0 -213
  141. data/lib/nrser/types/trees.rb +0 -42
data/lib/nrser/version.rb CHANGED
@@ -18,7 +18,7 @@ module NRSER
18
18
  #
19
19
  # @return [String]
20
20
  #
21
- VERSION = '0.3.9'
21
+ VERSION = '0.3.10'
22
22
 
23
23
 
24
24
  module Version
@@ -0,0 +1,22 @@
1
+ require 'nrser/core_ext/string'
2
+ require 'nrser/core_ext/pathname/subpath'
3
+
4
+ SPEC_FILE(
5
+ spec_path: __FILE__,
6
+ class: Pathname,
7
+ instance_method: :subpath?,
8
+ ) do
9
+
10
+ SETUP "Pathname.new( args[0] ).subpath? args[1]" do
11
+ subject do
12
+ ->( path_1, path_2 ) do
13
+ Pathname.new( path_1 ).subpath? path_2; end; end
14
+
15
+ it_behaves_like "a function",
16
+ mapping: {
17
+ [ Pathname.getwd, './tmp' ] => true
18
+ }
19
+
20
+ end # SETUP
21
+
22
+ end # SPEC_FILE
@@ -0,0 +1,68 @@
1
+ SPEC_FILE(
2
+ spec_path: __FILE__,
3
+ class: NRSER::AttrError,
4
+ ) do
5
+
6
+ METHOD '#default_message' do
7
+ # ==========================================================================
8
+
9
+ SETUP "create an", NRSER::AttrError,
10
+ "from the `keys` slice of `all_values` and call #default_message" do
11
+
12
+ let :all_values do
13
+ {
14
+ value: 'hey',
15
+ name: :empty?,
16
+ expected: true,
17
+ actual: false,
18
+ }
19
+ end
20
+
21
+ subject do
22
+ described_class.new( all_values.slice( *keys ) ).default_message
23
+ end
24
+
25
+ WHEN keys: [ :value, :name, :expected, :actual ] do
26
+ it do
27
+ is_expected.to eq ~%{
28
+ String object "hey" has invalid #empty? attribute,
29
+ expected true, found false
30
+ }; end; end
31
+
32
+ WHEN keys: [] do
33
+ it ~%{ defers to the super method } do
34
+ is_expected.to eq "(no message)"; end; end
35
+
36
+ WHEN keys: [ :value ] do
37
+ it ~%{ defers to the super method } do
38
+ is_expected.to eq "(no message)"; end; end
39
+
40
+ WHEN keys: [ :name ] do
41
+ it ~%{ defers to the super method } do
42
+ is_expected.to eq "(no message)"; end; end
43
+
44
+ WHEN keys: [ :value, :name ] do
45
+ it ~%{ renders the "name and value" part, and also the "found" part
46
+ because it will send the name to the value to get it } do
47
+ is_expected.to eq ~%{
48
+ String object "hey" has invalid #empty? attribute, found false
49
+ }; end; end
50
+
51
+ WHEN keys: [ :expected ] do
52
+ it ~%{ renders just the "expected" part } do
53
+ is_expected.to eq ~%{ expected true }; end; end
54
+
55
+ WHEN keys: [ :actual ] do
56
+ it ~%{ render just the "found" part } do
57
+ is_expected.to eq ~%{ found false }; end; end
58
+
59
+ WHEN keys: [ :actual, :expected ] do
60
+ it ~%{ renders "expected" and "found" parts } do
61
+ is_expected.to eq ~%{ expected true, found false }; end; end
62
+
63
+ end # SETUP
64
+
65
+ end # METHOD '#default_message' ********************************************
66
+
67
+
68
+ end # SPEC_FILE
@@ -0,0 +1,69 @@
1
+ class String
2
+ def to_re
3
+ # Regexp.new Regexp.escape( self )
4
+ /#{ Regexp.escape( self ) }/
5
+ end
6
+ end
7
+
8
+ SPEC_FILE(
9
+ spec_path: __FILE__,
10
+ class: NRSER::CountError,
11
+ ) do
12
+
13
+ METHOD '#default_message' do
14
+ # ==========================================================================
15
+
16
+ SETUP "create an", NRSER::CountError,
17
+ "from the `keys` slice of `all_values` and call #default_message" do
18
+
19
+ let :all_values do
20
+ {
21
+ value: [],
22
+ expected: 1,
23
+ actual: 0,
24
+ count: 0,
25
+ }
26
+ end
27
+
28
+ subject do
29
+ described_class.new( all_values.slice( *keys ) ).default_message
30
+ end
31
+
32
+ WHEN keys: [ :value, :expected, :actual ] do
33
+ it do
34
+ is_expected.to eq ~%{
35
+ Array object [] has invalid #count attribute, expected 1, found 0
36
+ }; end; end
37
+
38
+ WHEN keys: [ :value, :expected, :count ] do
39
+ it do
40
+ is_expected.to eq ~%{
41
+ Array object [] has invalid #count attribute, expected 1, found 0
42
+ }; end; end
43
+
44
+ end # SETUP
45
+
46
+ end # METHOD '#default_message' ********************************************
47
+
48
+
49
+ SECTION ~%{ in action } do
50
+ # ==========================================================================
51
+
52
+ METHOD [].method( :to_proc ) do
53
+ CALLED do
54
+ it do
55
+ expect { subject }.to raise_error NRSER::CountError,
56
+ /Can not create getter proc from empty array/; end; end; end
57
+
58
+
59
+ METHOD [].method( :only! ) do
60
+ CALLED do
61
+ it do
62
+ expect { subject }.to raise_error NRSER::CountError, (~%{
63
+ Array object [] has invalid #count attribute, expected 1, found 0
64
+ }).to_re; end; end; end
65
+
66
+ end # SECTION in action ************************************************
67
+
68
+
69
+ end # SPEC_FILE
@@ -0,0 +1,35 @@
1
+ SPEC_FILE(
2
+ spec_path: __FILE__,
3
+ module: NRSER,
4
+ method: :normalized_path?,
5
+ ) do
6
+
7
+ it_behaves_like "a function",
8
+ mapping: {
9
+ # Absolute paths
10
+ '/' => true,
11
+ '/x/y/z' => true,
12
+ '/x/y/z/' => true,
13
+
14
+ # Relative paths
15
+ '.' => true,
16
+ './' => true,
17
+ './x/y/z' => true,
18
+ './x/' => true,
19
+
20
+ # Empty segments
21
+ './/' => false,
22
+ '//' => false,
23
+ '/x//y/' => false,
24
+ 'x/y/z//' => false,
25
+
26
+ # `..` segments
27
+ '../x/y' => false,
28
+ '/x/../y' => false,
29
+ 'x/y/..' => false,
30
+
31
+ # But `...` is fine
32
+ '/x/.../y' => true,
33
+ }
34
+
35
+ end # SPEC_FILE
@@ -1,45 +1,86 @@
1
- describe_method "NRSER.map_tree" do
2
- # ========================================================================
1
+ SPEC_FILE \
2
+ spec_path: __FILE__,
3
+ module: NRSER,
4
+ method: :map_tree \
5
+ do
3
6
 
4
- subject { NRSER.method :map_tree }
5
-
6
- describe_section "Simple Examples" do
7
+ SECTION "Simple Examples" do
7
8
  # ========================================================================
8
9
 
9
- context_where(
10
- tree: {
11
- 1 => {
12
- name: 'Mr. Neil',
13
- fav_color: 'blue',
14
- age: 33,
15
- likes: [:tacos, :cats],
16
- },
17
-
18
- 2 => {
19
- name: 'Ms. Mica',
20
- fav_color: 'red',
21
- age: 32,
22
- likes: [:cats, :cookies],
23
- },
10
+ CASE "Convert all Integers to Strings" do
11
+ subject {
12
+ super().call( tree ) { |element|
13
+ if element.is_a? Integer
14
+ element.to_s
15
+ else
16
+ element
17
+ end
18
+ }
24
19
  }
25
- ) do
26
- describe "Convert all Integers to Strings" do
27
-
28
- subject {
29
- super().call( tree ) { |element|
20
+
21
+ WHEN \
22
+ tree: {
23
+ 1 => {
24
+ name: 'Mr. Neil',
25
+ fav_color: 'blue',
26
+ age: 33,
27
+ likes: [:tacos, :cats],
28
+ },
29
+
30
+ 2 => {
31
+ name: 'Ms. Mica',
32
+ fav_color: 'red',
33
+ age: 32,
34
+ likes: [:cats, :cookies],
35
+ } } do
36
+ it do
37
+ is_expected.to eq \
38
+ '1' => {
39
+ name: 'Mr. Neil',
40
+ fav_color: 'blue',
41
+ age: '33',
42
+ likes: [:tacos, :cats],
43
+ },
44
+
45
+ '2' => {
46
+ name: 'Ms. Mica',
47
+ fav_color: 'red',
48
+ age: '32',
49
+ likes: [:cats, :cookies],
50
+ }; end; end; end; end
51
+
52
+
53
+ SECTION "pruning" do
54
+ CASE "Convert all Integers to Strings and prune" do
55
+ subject do
56
+ super().call tree, prune: true do |element|
30
57
  if element.is_a? Integer
31
58
  element.to_s
32
59
  else
33
60
  element
34
- end
35
- }
36
- }
37
-
38
- it {
61
+ end; end; end
62
+
63
+ WHEN \
64
+ tree: {
65
+ 1 => {
66
+ name: 'Mr. Neil',
67
+ fav_color?: nil,
68
+ age: 33,
69
+ likes: [:tacos, :cats],
70
+ },
71
+
72
+ 2 => {
73
+ name: 'Ms. Mica',
74
+ fav_color?: 'red',
75
+ age: 32,
76
+ likes: [:cats, :cookies],
77
+ },
78
+ } \
79
+ do
80
+ it do
39
81
  is_expected.to eq \
40
82
  '1' => {
41
83
  name: 'Mr. Neil',
42
- fav_color: 'blue',
43
84
  age: '33',
44
85
  likes: [:tacos, :cats],
45
86
  },
@@ -50,69 +91,6 @@ describe_method "NRSER.map_tree" do
50
91
  age: '32',
51
92
  likes: [:cats, :cookies],
52
93
  }
53
- }
54
-
55
-
56
- end # Convert all Integers to Strings
57
- end # context where
58
-
59
- end # section Simple Examples
60
- # ************************************************************************
61
-
62
-
63
- describe_section "pruning" do
64
- # ========================================================================
65
-
66
- context_where(
67
- tree: {
68
- 1 => {
69
- name: 'Mr. Neil',
70
- fav_color?: nil,
71
- age: 33,
72
- likes: [:tacos, :cats],
73
- },
74
-
75
- 2 => {
76
- name: 'Ms. Mica',
77
- fav_color?: 'red',
78
- age: 32,
79
- likes: [:cats, :cookies],
80
- },
81
- }
82
- ) do
83
- describe "Convert all Integers to Strings and prune" do
84
-
85
- subject {
86
- super().call( tree, prune: true ) { |element|
87
- if element.is_a? Integer
88
- element.to_s
89
- else
90
- element
91
- end
92
- }
93
- }
94
-
95
- it {
96
- is_expected.to eq \
97
- '1' => {
98
- name: 'Mr. Neil',
99
- age: '33',
100
- likes: [:tacos, :cats],
101
- },
102
-
103
- '2' => {
104
- name: 'Ms. Mica',
105
- fav_color: 'red',
106
- age: '32',
107
- likes: [:cats, :cookies],
108
- }
109
- }
110
-
111
- end # Convert all Integers to Strings
112
- end # context where
113
-
114
- end # section pruning
115
- # ************************************************************************
116
-
94
+ end; end; end; end
117
95
 
118
- end # NRSER.map_tree
96
+ end # SPEC_FILE
@@ -8,8 +8,8 @@ describe "NRSER.transform" do
8
8
 
9
9
  let( :tree ) {
10
10
  {
11
- x: :y.to_retriever,
12
- y: :x.to_retriever,
11
+ x: [ :y ].to_proc,
12
+ y: [ :x ].to_proc,
13
13
  }
14
14
  } # let :tree
15
15
 
@@ -30,8 +30,8 @@ describe "NRSER.transform" do
30
30
  let :tree do
31
31
  {
32
32
  users: {
33
- { id: :id.to_retriever } => {
34
- name: :name.to_retriever,
33
+ { id: [ :id ].to_proc } => {
34
+ name: [ :name ].to_proc,
35
35
  }
36
36
  }
37
37
  }
@@ -60,8 +60,8 @@ describe "NRSER.transform" do
60
60
  let :tree do
61
61
  {
62
62
  list: [
63
- { name: :name.to_retriever },
64
- { age: :age.to_retriever },
63
+ { name: [ :name ].to_proc },
64
+ { age: [ :age ].to_proc },
65
65
  ]
66
66
  }
67
67
  end
@@ -118,11 +118,11 @@ describe "NRSER.transform" do
118
118
  addresses: {
119
119
  {
120
120
  address_id: [ :id ].to_sender } => {
121
- district: :address.to_retriever,
122
- line_1: :street2.to_retriever,
123
- city: :city.to_retriever,
124
- province: :state.to_retriever,
125
- post_code: :zip.to_retriever,
121
+ district: [:address ].to_proc,
122
+ line_1: [:street2 ].to_proc,
123
+ city: [:city ].to_proc,
124
+ province: [:state ].to_proc,
125
+ post_code: [:zip ].to_proc,
126
126
  }
127
127
  }
128
128
  }