nrser 0.2.2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (188) hide show
  1. checksums.yaml +4 -4
  2. data/lib/nrser/char/alpha_numeric_sub.rb +1 -2
  3. data/lib/nrser/char.rb +0 -6
  4. data/lib/nrser/core_ext/array.rb +120 -0
  5. data/lib/nrser/core_ext/binding.rb +44 -0
  6. data/lib/nrser/{functions → core_ext}/enumerable/find_map.rb +18 -15
  7. data/lib/nrser/{ext → core_ext}/enumerable.rb +10 -24
  8. data/lib/nrser/core_ext/exception.rb +30 -0
  9. data/lib/nrser/core_ext/hash/extract_values_at.rb +49 -0
  10. data/lib/nrser/core_ext/hash/transform_values_with_keys.rb +24 -0
  11. data/lib/nrser/core_ext/hash.rb +50 -0
  12. data/lib/nrser/core_ext/module/method_objects.rb +96 -0
  13. data/lib/nrser/core_ext/module/names.rb +69 -0
  14. data/lib/nrser/core_ext/module/source_locations.rb +214 -0
  15. data/lib/nrser/core_ext/module.rb +2 -0
  16. data/lib/nrser/core_ext/object/lazy_var.rb +31 -0
  17. data/lib/nrser/core_ext/object.rb +46 -0
  18. data/lib/nrser/core_ext/open_struct.rb +6 -0
  19. data/lib/nrser/{ext → core_ext}/pathname.rb +8 -5
  20. data/lib/nrser/{ext → core_ext}/string.rb +6 -12
  21. data/lib/nrser/core_ext/symbol.rb +13 -0
  22. data/lib/nrser/core_ext/time.rb +46 -0
  23. data/lib/nrser/core_ext.rb +13 -0
  24. data/lib/nrser/errors/abstract_method_error.rb +150 -0
  25. data/lib/nrser/errors/argument_error.rb +42 -0
  26. data/lib/nrser/errors/nicer_error.rb +298 -72
  27. data/lib/nrser/errors/type_error.rb +46 -0
  28. data/lib/nrser/errors.rb +4 -53
  29. data/lib/nrser/ext/tree.rb +3 -0
  30. data/lib/nrser/functions/enumerable/associate.rb +6 -9
  31. data/lib/nrser/functions/enumerable/include_slice.rb +2 -3
  32. data/lib/nrser/functions/enumerable.rb +1 -3
  33. data/lib/nrser/functions/exception.rb +1 -1
  34. data/lib/nrser/functions/hash.rb +0 -6
  35. data/lib/nrser/functions/merge_by.rb +2 -2
  36. data/lib/nrser/functions/module/method_objects.rb +77 -0
  37. data/lib/nrser/functions/module.rb +1 -2
  38. data/lib/nrser/functions/open_struct.rb +25 -35
  39. data/lib/nrser/functions/proc.rb +1 -6
  40. data/lib/nrser/functions/string/looks_like.rb +32 -1
  41. data/lib/nrser/functions/string.rb +1 -40
  42. data/lib/nrser/functions/text/lines.rb +2 -1
  43. data/lib/nrser/functions.rb +0 -1
  44. data/lib/nrser/graph/tsorter.rb +41 -0
  45. data/lib/nrser/labs/core_ext/binding.rb +37 -0
  46. data/lib/nrser/labs/stash.rb +372 -0
  47. data/lib/nrser/{logging → log}/appender/sync.rb +3 -3
  48. data/lib/nrser/log/appender.rb +3 -0
  49. data/lib/nrser/{logging → log}/formatters/color.rb +47 -20
  50. data/lib/nrser/log/formatters/mixin.rb +270 -0
  51. data/lib/nrser/{logging → log}/formatters.rb +0 -0
  52. data/lib/nrser/log/logger.rb +229 -0
  53. data/lib/nrser/log/mixin.rb +56 -0
  54. data/lib/nrser/log.rb +723 -0
  55. data/lib/nrser/message.rb +24 -3
  56. data/lib/nrser/meta/source/location.rb +158 -0
  57. data/lib/nrser/meta.rb +1 -1
  58. data/lib/nrser/props/class_methods.rb +118 -0
  59. data/lib/nrser/props/immutable/hash.rb +111 -0
  60. data/lib/nrser/props/immutable/hash_variable.rb +82 -0
  61. data/lib/nrser/props/immutable/instance_variables.rb +48 -0
  62. data/lib/nrser/props/immutable/vector.rb +107 -0
  63. data/lib/nrser/props/instance_methods.rb +184 -0
  64. data/lib/nrser/props/metadata.rb +359 -0
  65. data/lib/nrser/props/mutable/instance_variables.rb +60 -0
  66. data/lib/nrser/props/mutable/stash.rb +199 -0
  67. data/lib/nrser/{meta/props → props}/prop.rb +217 -112
  68. data/lib/nrser/props/storage/instance_variable.rb +85 -0
  69. data/lib/nrser/props/storage/instance_variables.rb +67 -0
  70. data/lib/nrser/props/storage/key.rb +88 -0
  71. data/lib/nrser/props.rb +9 -0
  72. data/lib/nrser/refinements/sugar.rb +41 -0
  73. data/lib/nrser/refinements/types.rb +2 -2
  74. data/lib/nrser/refinements.rb +14 -16
  75. data/lib/nrser/rspex/example_group/describe_attribute.rb +24 -0
  76. data/lib/nrser/rspex/example_group/describe_called_with.rb +1 -6
  77. data/lib/nrser/rspex/example_group/{describe_use_case.rb → describe_case.rb} +6 -3
  78. data/lib/nrser/rspex/example_group/describe_class.rb +1 -0
  79. data/lib/nrser/rspex/example_group/describe_group.rb +29 -0
  80. data/lib/nrser/rspex/example_group/describe_instance_method.rb +2 -2
  81. data/lib/nrser/rspex/example_group/describe_message.rb +35 -0
  82. data/lib/nrser/rspex/example_group/describe_method.rb +23 -2
  83. data/lib/nrser/rspex/example_group/describe_module.rb +19 -0
  84. data/lib/nrser/rspex/example_group/describe_response_to.rb +32 -0
  85. data/lib/nrser/rspex/example_group/describe_section.rb +38 -0
  86. data/lib/nrser/rspex/example_group/describe_sent_to.rb +52 -0
  87. data/lib/nrser/rspex/example_group/describe_source_file.rb +49 -0
  88. data/lib/nrser/rspex/example_group/describe_spec_file.rb +41 -108
  89. data/lib/nrser/rspex/example_group/describe_when.rb +14 -7
  90. data/lib/nrser/rspex/example_group/describe_x.rb +39 -12
  91. data/lib/nrser/rspex/example_group/overrides.rb +66 -0
  92. data/lib/nrser/rspex/example_group.rb +20 -252
  93. data/lib/nrser/rspex/format.rb +83 -17
  94. data/lib/nrser/rspex.rb +4 -34
  95. data/lib/nrser/sugar/method_missing_forwarder.rb +50 -0
  96. data/lib/nrser/{env → sys/env}/path.rb +1 -2
  97. data/lib/nrser/{env.rb → sys/env.rb} +2 -1
  98. data/lib/nrser/sys.rb +5 -0
  99. data/lib/nrser/types/any.rb +36 -7
  100. data/lib/nrser/types/{array.rb → arrays.rb} +32 -81
  101. data/lib/nrser/types/attrs.rb +68 -15
  102. data/lib/nrser/types/booleans.rb +95 -34
  103. data/lib/nrser/types/bounded.rb +12 -10
  104. data/lib/nrser/types/combinators.rb +74 -37
  105. data/lib/nrser/types/errors/check_error.rb +86 -0
  106. data/lib/nrser/types/errors/from_string_error.rb +82 -0
  107. data/lib/nrser/types/factory.rb +91 -0
  108. data/lib/nrser/types/hashes.rb +171 -26
  109. data/lib/nrser/types/in.rb +25 -12
  110. data/lib/nrser/types/is.rb +50 -18
  111. data/lib/nrser/types/is_a.rb +52 -33
  112. data/lib/nrser/types/labels.rb +6 -33
  113. data/lib/nrser/types/maybe.rb +12 -4
  114. data/lib/nrser/types/nil.rb +24 -4
  115. data/lib/nrser/types/not.rb +6 -16
  116. data/lib/nrser/types/numbers.rb +94 -57
  117. data/lib/nrser/types/pairs.rb +57 -57
  118. data/lib/nrser/types/paths.rb +112 -133
  119. data/lib/nrser/types/responds.rb +64 -74
  120. data/lib/nrser/types/shape.rb +29 -24
  121. data/lib/nrser/types/strings.rb +25 -17
  122. data/lib/nrser/types/symbols.rb +19 -17
  123. data/lib/nrser/types/trees.rb +18 -70
  124. data/lib/nrser/types/tuples.rb +36 -40
  125. data/lib/nrser/types/type.rb +342 -91
  126. data/lib/nrser/types/when.rb +40 -18
  127. data/lib/nrser/types/where.rb +94 -9
  128. data/lib/nrser/types.rb +72 -63
  129. data/lib/nrser/version.rb +1 -1
  130. data/lib/nrser.rb +18 -18
  131. data/spec/lib/nrser/{functions/binding/template_spec.rb → core_ext/binding/erb_spec.rb} +5 -5
  132. data/spec/lib/nrser/{functions → core_ext}/enumerable/find_map_spec.rb +8 -6
  133. data/spec/lib/nrser/{refinements → core_ext}/hash_spec.rb +9 -22
  134. data/spec/lib/nrser/errors/abstract_method_error_spec.rb +12 -5
  135. data/spec/lib/nrser/functions/enumerable/{to_h_by_spec.rb → associate_spec.rb} +1 -1
  136. data/spec/lib/nrser/functions/merge_by_spec.rb +1 -1
  137. data/spec/lib/nrser/functions/tree/each_branch_spec.rb +3 -3
  138. data/spec/lib/nrser/functions/tree/transform_spec.rb +14 -15
  139. data/spec/lib/nrser/gem_ext/hamster/json_spec.rb +4 -0
  140. data/spec/lib/nrser/meta/source/location_spec.rb +86 -0
  141. data/spec/lib/nrser/props/immutable/hash_spec.rb +297 -0
  142. data/spec/lib/nrser/props/immutable/vector_spec.rb +296 -0
  143. data/spec/lib/nrser/{meta/props_spec.rb → props/original_props_spec.rb} +11 -16
  144. data/spec/lib/nrser/{meta/props → props}/to_and_from_data_spec.rb +10 -8
  145. data/spec/lib/nrser/refinements/array_spec.rb +2 -15
  146. data/spec/lib/nrser/refinements/erb_spec.rb +5 -7
  147. data/spec/lib/nrser/refinements/set_spec.rb +2 -15
  148. data/spec/lib/nrser/{env → sys/env}/path/insert_spec.rb +4 -2
  149. data/spec/lib/nrser/{env → sys/env}/path_spec.rb +4 -2
  150. data/spec/lib/nrser/types/array_spec.rb +8 -8
  151. data/spec/lib/nrser/types/paths_spec.rb +15 -18
  152. data/spec/spec_helper.rb +4 -0
  153. metadata +109 -69
  154. data/lib/nrser/ext/binding.rb +0 -36
  155. data/lib/nrser/ext/module.rb +0 -62
  156. data/lib/nrser/ext.rb +0 -8
  157. data/lib/nrser/functions/binding.rb +0 -76
  158. data/lib/nrser/functions/enumerable/map_keys.rb +0 -0
  159. data/lib/nrser/functions/enumerable/map_values.rb +0 -94
  160. data/lib/nrser/functions/hash/deep_merge.rb +0 -57
  161. data/lib/nrser/functions/hash/except_keys.rb +0 -44
  162. data/lib/nrser/functions/hash/slice_keys.rb +0 -43
  163. data/lib/nrser/functions/hash/stringify_keys.rb +0 -55
  164. data/lib/nrser/functions/hash/symbolize_keys.rb +0 -57
  165. data/lib/nrser/functions/hash/transform_keys.rb +0 -140
  166. data/lib/nrser/functions/module/methods.rb +0 -206
  167. data/lib/nrser/functions/module/source_locations.rb +0 -213
  168. data/lib/nrser/logging/appender.rb +0 -3
  169. data/lib/nrser/logging.rb +0 -353
  170. data/lib/nrser/meta/props/base.rb +0 -31
  171. data/lib/nrser/meta/props.rb +0 -357
  172. data/lib/nrser/refinements/array.rb +0 -133
  173. data/lib/nrser/refinements/binding.rb +0 -6
  174. data/lib/nrser/refinements/enumerator.rb +0 -5
  175. data/lib/nrser/refinements/exception.rb +0 -35
  176. data/lib/nrser/refinements/hash.rb +0 -150
  177. data/lib/nrser/refinements/module.rb +0 -5
  178. data/lib/nrser/refinements/object.rb +0 -42
  179. data/lib/nrser/refinements/open_struct.rb +0 -28
  180. data/lib/nrser/refinements/pathname.rb +0 -5
  181. data/lib/nrser/refinements/set.rb +0 -5
  182. data/lib/nrser/refinements/string.rb +0 -5
  183. data/lib/nrser/refinements/symbol.rb +0 -20
  184. data/lib/nrser/rspex/described.rb +0 -99
  185. data/spec/design/mapping_spec.rb +0 -42
  186. data/spec/lib/nrser/functions/hash_spec.rb +0 -41
  187. data/spec/lib/nrser/functions/string/truncate_spec.rb +0 -11
  188. data/spec/lib/nrser/refinements/truncate_spec.rb +0 -10
@@ -6,261 +6,29 @@
6
6
  # =======================================================================
7
7
 
8
8
  module NRSER::RSpex; end
9
+ module NRSER::RSpex::ExampleGroup; end
9
10
 
10
11
 
11
- # Definitions
12
- # =======================================================================
13
-
14
- # Instance methods to extend examples groups with. Also included globally so
15
- # they're available at the top-level in files.
16
- #
17
- module NRSER::RSpex::ExampleGroup
18
-
19
- # HACK HACK HACK-ITY HACK - Allow for overriding RSpec methods
20
- #
21
- # Yeah, it has to do with mixin mixing-in ordering - seems to be that when
22
- #
23
- # config.extend NRSER::RSpex::ExampleGroup
24
- #
25
- # {NRSER::RSpex::ExampleGroup} gets mixed in *very early* in the chain,
26
- # before {RSpec::Core::ExampleGroup}... why you would provide an explicit
27
- # extension mechanism and not give those extensions priority I'm not sure,
28
- # but I'm sure I shouldn't be looking into it right now, so here we are:
29
- #
30
- # It turns out that {NRSER::RSpex::Example}, which gets mixed with
31
- #
32
- # config.include NRSER::RSpex::Example
33
- #
34
- # gets mixed *last*, so by using it's {NRSER::RSpex::Example.included}
35
- # hook we can use
36
- #
37
- # base#extend NRSER::RSpex::ExampleGroup::Overrides
38
- #
39
- # to mix these guys over the top of RSpec's methods.
40
- #
41
- # Seems like we could just mix all of {NRSER::RSpex::ExampleGroup} there
42
- # to get the behavior I would have expected all along, but maybe it's better
43
- # to have these explicit notes for the moment and not change much else until
44
- # I get the chance to really check out what's going on.
45
- #
46
- # And really it's all to override `.described_class` to pick up our
47
- # metadata if it's there, but that approach is in quite a bit of use at
48
- # this point, and, no, I have no idea how it seemed to work up until this
49
- # point :/
50
- #
51
- module Overrides
52
-
53
- # Override {RSpec::Core::ExampleGroup.described_class} to use RSpex's
54
- # `:class` metadata if it's present.
55
- #
56
- # Because I can't figure out how to feed RSpec the described class
57
- # without it being the description, and we want better descriptions.
58
- #
59
- # Some hackery could def do it, this is RUBY after all, but whatever this
60
- # works for now and may even be less fragile.
61
- #
62
- # @return [Class]
63
- # If there's a `:class` in the metadata, or if RSpec has on through the
64
- # standard means (`describe MyClass do ...`).
65
- #
66
- # @return [nil]
67
- # If we don't have a class context around.
68
- #
69
- def described_class
70
- metadata[:class] || super()
71
- end
72
-
73
- end
74
-
75
-
76
- def describe_message symbol, *args, &body
77
- description = \
78
- "message #{ [symbol, *args].map( &NRSER::RSpex.method( :short_s ) ).join( ', ' ) }"
79
-
80
- describe description, type: :message do
81
- subject { NRSER::Message.new symbol, *args }
82
- module_exec &body
83
- end
84
- end
85
-
86
-
87
- # For use when `subject` is a {NRSER::Message}. Create a new context for
88
- # the `receiver` where the subject is the result of sending that message
89
- # to the receiver.
90
- #
91
- # @param [Object] receiver
92
- # Object that will receive the message to create the new subject.
93
- #
94
- # @param [Boolean] publicly:
95
- # Send message publicly via {Object#public_send} (default) or privately
96
- # via {Object.send}.
97
- #
98
- # @return
99
- # Whatever the `context` call returns.
100
- #
101
- def describe_sent_to receiver, publicly: true, &block
102
- mode = if publicly
103
- "publicly"
104
- else
105
- "privately"
106
- end
107
-
108
- describe "sent to #{ receiver } (#{ mode })" do
109
- subject { super().send_to unwrap( receiver, context: self ) }
110
- module_exec &block
111
- end
112
- end # #describe_sent_to
113
-
114
- # Aliases to other names I was using at first... not preferring their use
115
- # at the moment.
116
- #
117
- # The `when_` one sucks because Atom de-dents the line, and `describe_`
118
- # is just clearer what the block is doing for people reading it.
119
- alias_method :sent_to, :describe_sent_to
120
- alias_method :when_sent_to, :describe_sent_to
121
-
122
-
123
- def describe_return_value *args, &body
124
- msg = NRSER::Message.from *args
125
-
126
- describe "return value from #{ msg }" do
127
- subject { msg.send_to super() }
128
- module_exec &body
129
- end # "return value from #{ msg }"
130
- end
131
-
132
-
133
- # Describe a "section". Just like {RSpec.describe} except it:
134
- #
135
- # 1. Expects a string title.
136
- #
137
- # 2. Prepends a little section squiggle `§` to the title so sections are
138
- # easier to pick out visually.
139
- #
140
- # 3. Adds `type: :section` metadata.
141
- #
142
- # @param [String] title
143
- # String title for the section.
144
- #
145
- # @param [Hash<Symbol, Object>] **metadata
146
- # Additional [RSpec metadata][] for the example group.
147
- #
148
- # [RSpec metadata]: https://relishapp.com/rspec/rspec-core/docs/metadata/user-defined-metadata
149
- #
150
- # @return
151
- # Whatever {RSpec.describe} returns.
152
- #
153
- def describe_section title, **metadata, &block
154
- describe(
155
- "#{ NRSER::RSpex::PREFIXES[:section] } #{ title }",
156
- type: :section,
157
- **metadata
158
- ) do
159
- module_exec &block
160
- end
161
- end # #describe_section
162
-
163
- # Old name
164
- alias_method :describe_topic, :describe_section
165
-
166
-
167
- def describe_file path, **metadata, &body
168
- title = path
169
-
170
- describe(
171
- "#{ NRSER::RSpex::PREFIXES[:file] } #{ title }",
172
- type: :file,
173
- file: path,
174
- **metadata
175
- ) do
176
- module_exec &body
177
- end
178
- end
179
-
180
-
181
- def describe_module mod, bind_subject: true, **metadata, &block
182
- describe(
183
- "#{ NRSER::RSpex::PREFIXES[:module] } #{ mod.name }",
184
- type: :module,
185
- module: mod,
186
- **metadata
187
- ) do
188
- if bind_subject
189
- subject { mod }
190
- end
191
-
192
- module_exec &block
193
- end
194
- end # #describe_module
195
-
196
-
197
- def describe_group title, **metadata, &block
198
- describe(
199
- "#{ NRSER::RSpex::PREFIXES[:group] } #{ title }",
200
- type: :group,
201
- **metadata
202
- ) do
203
- module_exec &block
204
- end
205
- end # #describe_class
206
-
207
-
208
- def describe_attribute symbol, **metadata, &block
209
- describe(
210
- "#{ NRSER::RSpex::PREFIXES[:attribute] } ##{ symbol }",
211
- type: :attribute,
212
- **metadata
213
- ) do
214
- subject { super().public_send symbol }
215
- module_exec &block
216
- end
217
- end # #describe_attribute
218
-
219
- # Shorter name
220
- alias_method :describe_attr, :describe_attribute
221
-
222
-
223
- # Define a `context` block with `let` bindings and evaluate the `body`
224
- # block in it.
225
- #
226
- # @param [Hash<Symbol, Object>] **bindings
227
- # Map of symbol names to value to bind using `let`.
228
- #
229
- # @param [#call] &body
230
- # Body block to evaluate in the context.
231
- #
232
- # @return
233
- # Whatever `context` returns.
234
- #
235
- def context_where description = nil, **bindings, &body
236
-
237
- if description.nil?
238
- description = bindings.map { |name, value|
239
- "#{ name }: #{ NRSER::RSpex.short_s value }"
240
- }.join( ", " )
241
- end
242
-
243
- context "△ #{ description }", type: :where do
244
- bindings.each { |name, value|
245
- let( name ) { unwrap value, context: self }
246
- }
247
-
248
- module_exec &body
249
- end
250
- end
251
-
252
- end # module NRSER:RSpex::ExampleGroup
12
+ # Sub-Tree
13
+ # ============================================================================
253
14
 
15
+ require_relative './example_group/overrides'
254
16
 
255
- # Post-Processing
256
- # =======================================================================
257
-
258
- require_relative './example_group/describe_x'
259
- require_relative './example_group/describe_spec_file'
260
- require_relative './example_group/describe_when'
261
- require_relative './example_group/describe_setup'
262
- require_relative './example_group/describe_use_case'
263
- require_relative './example_group/describe_instance'
17
+ require_relative './example_group/describe_attribute'
264
18
  require_relative './example_group/describe_called_with'
265
- require_relative './example_group/describe_method'
19
+ require_relative './example_group/describe_case'
266
20
  require_relative './example_group/describe_class'
21
+ require_relative './example_group/describe_group'
22
+ require_relative './example_group/describe_instance_method'
23
+ require_relative './example_group/describe_instance'
24
+ require_relative './example_group/describe_message'
25
+ require_relative './example_group/describe_method'
26
+ require_relative './example_group/describe_module'
27
+ require_relative './example_group/describe_response_to'
28
+ require_relative './example_group/describe_section'
29
+ require_relative './example_group/describe_sent_to'
30
+ require_relative './example_group/describe_setup'
31
+ require_relative './example_group/describe_source_file'
32
+ require_relative './example_group/describe_spec_file'
33
+ require_relative './example_group/describe_when'
34
+ require_relative './example_group/describe_x'
@@ -1,6 +1,5 @@
1
1
  require 'pastel'
2
2
 
3
- using NRSER
4
3
 
5
4
  # Definitions
6
5
  # =======================================================================
@@ -82,8 +81,26 @@ module NRSER::RSpex::Format
82
81
  end
83
82
 
84
83
 
84
+ def self.method_name? string
85
+ # Must start with `#` or `.`
86
+ return false unless ['#', '.'].any? { |c| string[0] == c }
87
+
88
+ name = string[1..-1]
89
+
90
+ case name
91
+ when '!', '~', '+', '**', '-', '*', '/', '%', '+', '-', '<<', '>>', '&',
92
+ '|', '^', '<', '<=', '>=', '>', '==', '===', '!=', '=~', '!~', '<=>',
93
+ '[]',
94
+ /\A[a-zA-Z_][a-zA-Z0-9_]*(?:\?|\!|=)?/
95
+ true
96
+ else
97
+ false
98
+ end
99
+ end
100
+
101
+
85
102
  def self.code string
86
- if string =~ /\A\#[a-zA-Z][a-zA-Z0-9_]*(?:\?|\!)?/
103
+ if method_name? string
87
104
  pastel.bold.blue string
88
105
  else
89
106
  rspec_syntax_highlighter.highlight string.lines
@@ -108,18 +125,41 @@ module NRSER::RSpex::Format
108
125
  def self.prepend_type type, description
109
126
  return description if type.nil?
110
127
 
111
- # prefixes = RSpec.configuration.x_type_prefixes
112
- #
113
- # prefix = prefixes[type] ||
114
- # pastel.magenta( i( type.to_s.upcase.gsub('_', ' ') ) )
128
+ prefixes = RSpec.configuration.x_type_prefixes
115
129
 
116
- # prefix = "*" + type.to_s.upcase.gsub('_', ' ') + "*"
117
- prefix = pastel.magenta( i( type.to_s.upcase.gsub('_', ' ') ) )
130
+ prefix = pastel.magenta(
131
+ prefixes[type] || i( type.to_s.upcase.gsub('_', ' ') )
132
+ )
118
133
 
119
134
  "#{ prefix } #{ description }"
120
135
  end # .format_type
121
136
 
122
137
 
138
+ def self.pathname pn
139
+ if pn.absolute?
140
+ rel = pn.relative_path_from Pathname.getwd
141
+
142
+ if rel.split( File::SEPARATOR ).first == '..'
143
+ File.join '.', rel
144
+ else
145
+ pn.to_s
146
+ end
147
+ else
148
+ if pn.exist?
149
+ File.join '.', pn
150
+ else
151
+ lib_pn = Pathname.getwd / 'lib' / pn
152
+
153
+ if lib_pn.exist?
154
+ File.join '.', lib_pn.relative_path_from( Pathname.getwd )
155
+ else
156
+ pn.to_s
157
+ end
158
+ end
159
+ end
160
+ end
161
+
162
+
123
163
  # @todo Document format method.
124
164
  #
125
165
  # @param [type] arg_name
@@ -129,18 +169,48 @@ module NRSER::RSpex::Format
129
169
  #
130
170
  def self.description *parts, type: nil
131
171
  parts.
132
- map { |part|
172
+ flat_map { |part|
133
173
  if part.respond_to? :to_desc
134
174
  desc = part.to_desc
135
175
  if desc.empty?
136
176
  ''
137
177
  else
138
- md_code_quote part.to_desc
178
+ md_code_quote desc
139
179
  end
140
- elsif part.is_a? String
141
- part
142
180
  else
143
- NRSER::RSpex.short_s part
181
+ case part
182
+ when Module
183
+ mod = part
184
+
185
+ name_desc = if mod.anonymous?
186
+ "(anonymous #{ part.class })"
187
+ else
188
+ md_code_quote mod.name
189
+ end
190
+
191
+ [name_desc, description( mod.source_location )]
192
+
193
+ when NRSER::Meta::Source::Location
194
+ if part.valid?
195
+ "(#{ NRSER::RSpex.dot_rel_path( part.file ) }:#{ part.line })"
196
+ else
197
+ ''
198
+ end
199
+
200
+ when String
201
+ part
202
+
203
+ when Pathname
204
+ pathname part
205
+
206
+ when NRSER::Message
207
+ [part.symbol, part.args].
208
+ map( &NRSER::RSpex.method( :short_s ) ).join( ', ' )
209
+
210
+ else
211
+ NRSER::RSpex.short_s part
212
+
213
+ end
144
214
  end
145
215
  }.
146
216
  join( ' ' ).
@@ -151,7 +221,3 @@ module NRSER::RSpex::Format
151
221
  end # .description
152
222
 
153
223
  end # module NRSER::RSpex::Format
154
-
155
-
156
- # Post-Processing
157
- # =======================================================================
data/lib/nrser/rspex.rb CHANGED
@@ -25,6 +25,8 @@ require 'commonmarker'
25
25
  # Project / Package
26
26
  # -----------------------------------------------------------------------
27
27
  require 'nrser'
28
+ require 'nrser/core_ext'
29
+
28
30
  require_relative './rspex/example'
29
31
  require_relative './rspex/example_group'
30
32
  require_relative './rspex/shared_examples'
@@ -133,50 +135,18 @@ module NRSER::RSpex
133
135
  # Constants
134
136
  # =====================================================================
135
137
 
136
- # Symbols
137
- # ---------------------------------------------------------------------
138
+ # Symbol characters for specific example group types.
138
139
  #
139
140
  # Sources:
140
141
  #
141
142
  # - https://en.wikipedia.org/wiki/Mathematical_operators_and_symbols_in_Unicode
142
143
  #
143
-
144
- PREFIXES_BASE = {
144
+ PREFIXES = {
145
145
  section: '§',
146
146
  group: '•',
147
147
  invocation: '𝑓⟮𝑥⟯',
148
148
  }
149
149
 
150
- PREFIXES_MATH_ITALIC = PREFIXES_BASE.merge(
151
- module: '𝑀',
152
- method: '𝑚',
153
- class: '𝐶',
154
- attribute: '𝑎',
155
- file: '𝐹',
156
- )
157
-
158
- PREFIXES_MATH_CURSIVE_WORDS = PREFIXES_BASE.merge(
159
- module: '𝓜 𝓸𝓭𝓾𝓵𝓮',
160
- method: '𝓶𝓮𝓽',
161
- class: '𝐶',
162
- attribute: '𝑎',
163
- file: '𝐹',
164
- )
165
-
166
- # PREFIXES_MATH_GREEK = PREFIXES_BASE.merge(
167
- # # module: "𝓜 𝓸𝓭𝓾𝓵𝓮",
168
- # module: '𝛭',
169
- # method: '𝜆',
170
- # class: '𝛤',
171
- # attribute: '𝛼',
172
- # )
173
-
174
- PREFIXES = PREFIXES_MATH_ITALIC
175
-
176
- # PREFIXES = PREFIXES_MATH_ITALIC.map_values { |k, v|
177
- # RSpec::Core::Formatters::ConsoleCodes.wrap( v, :cyan )
178
- # }
179
-
180
150
 
181
151
  # Module (Class) Functions
182
152
  # =====================================================================
@@ -0,0 +1,50 @@
1
+ # encoding: UTF-8
2
+ # frozen_string_literal: true
3
+
4
+ # Declarations
5
+ # =======================================================================
6
+
7
+ module NRSER; end
8
+
9
+
10
+ # Definitions
11
+ # ========================================================================
12
+
13
+ # A very simple class that forwards all method calls to the block it was
14
+ # initialized with (via {#method_missing}).
15
+ #
16
+ class NRSER::MethodMissingForwarder < BasicObject
17
+
18
+ # Constructor
19
+ # ========================================================================
20
+
21
+ # Instantiate a new `NRSER::MethodMissingForwarder` holding the forwarding
22
+ # block.
23
+ #
24
+ # @param [Proc<(symbol:Symbol, *args, &block)>] &forwarder
25
+ # Block that will receive all calls to {#method_missing}.
26
+ #
27
+ def initialize &forwarder
28
+ @forwarder = forwarder
29
+ end # #initialize
30
+
31
+
32
+ # Instance Methods
33
+ # ========================================================================
34
+
35
+ # Forwards all params to the `@forwarder` proc.
36
+ #
37
+ # @param [Symbol] symbol
38
+ # The name of the method that was called.
39
+ #
40
+ # @param [Array] *args
41
+ # Any parameters the missing method was called with.
42
+ #
43
+ # @param [Proc?] &block
44
+ # The block the method was called with, if any.
45
+ #
46
+ def method_missing symbol, *args, &block
47
+ @forwarder.call symbol, *args, &block
48
+ end
49
+
50
+ end # class NRSER::MethodMisser
@@ -27,9 +27,8 @@ using NRSER
27
27
  # =======================================================================
28
28
 
29
29
  # @todo document NRSER::Env::Path class.
30
- class NRSER::Env::Path
30
+ class NRSER::Sys::Env::Path
31
31
  include Enumerable
32
- include NRSER::Ext::Enumerable
33
32
 
34
33
  # Constants
35
34
  # ======================================================================
@@ -3,7 +3,8 @@
3
3
  # Declarations
4
4
  # =======================================================================
5
5
 
6
- module NRSER::Env; end
6
+ module NRSER::Sys; end
7
+ module NRSER::Sys::Env; end
7
8
 
8
9
 
9
10
  # Post-Processing
data/lib/nrser/sys.rb ADDED
@@ -0,0 +1,5 @@
1
+ # Object wrappers and utilities for system interfaces and information.
2
+ #
3
+ module NRSER::Sys; end
4
+
5
+ require_relative './sys/env'
@@ -1,12 +1,41 @@
1
- require 'nrser/refinements'
2
- require 'nrser/types/where'
3
-
1
+ # encoding: UTF-8
2
+ # frozen_string_literal: true
4
3
 
5
4
  module NRSER::Types
6
- ANY = where(name: 'AnyType', from_s: ->(s) { s }) { true }.freeze
7
5
 
8
- # anything
9
- def self.any
10
- ANY
6
+ # A type for anything - {#test?} always returns `true`.
7
+ #
8
+ class AnyType < NRSER::Types::Type
9
+
10
+ def test? value; true; end
11
+ def explain; '*'; end
12
+ def custom_from_s string; string; end
13
+
14
+ # {AnyType} instances are all equal.
15
+ #
16
+ # @note
17
+ # `other`'s class must be {AnyType} exactly - we make no assumptions
18
+ # about anything that has subclasses {AnyType}.
19
+ #
20
+ # @param [*] other
21
+ # Object to compare to.
22
+ #
23
+ # @return [Boolean]
24
+ # `true` if `other#class` equals {AnyType}.
25
+ #
26
+ def == other
27
+ other.class == AnyType
28
+ end
29
+
30
+ end # class Any
31
+
32
+ # Anything at all...
33
+ #
34
+ def_factory(
35
+ :any,
36
+ aliases: [ :all ],
37
+ ) do
38
+ @_any_type_instance ||= AnyType.new
11
39
  end
40
+
12
41
  end # NRSER::Types