nrser 0.0.30 → 0.1.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.
Files changed (107) hide show
  1. checksums.yaml +4 -4
  2. data/lib/nrser.rb +56 -12
  3. data/lib/nrser/collection.rb +4 -7
  4. data/lib/nrser/ext.rb +5 -0
  5. data/lib/nrser/{refinements → ext}/enumerable.rb +11 -9
  6. data/lib/nrser/ext/pathname.rb +74 -0
  7. data/lib/nrser/{refinements → ext}/tree.rb +2 -26
  8. data/lib/nrser/functions.rb +18 -0
  9. data/lib/nrser/{array.rb → functions/array.rb} +2 -3
  10. data/lib/nrser/{binding.rb → functions/binding.rb} +0 -2
  11. data/lib/nrser/functions/enumerable.rb +355 -0
  12. data/lib/nrser/functions/enumerable/find_all_map.rb +33 -0
  13. data/lib/nrser/functions/enumerable/find_map.rb +53 -0
  14. data/lib/nrser/functions/exception.rb +17 -0
  15. data/lib/nrser/{hash.rb → functions/hash.rb} +0 -0
  16. data/lib/nrser/functions/hash/bury.rb +147 -0
  17. data/lib/nrser/{hash → functions/hash}/deep_merge.rb +5 -5
  18. data/lib/nrser/{hash → functions/hash}/except_keys.rb +2 -0
  19. data/lib/nrser/{hash → functions/hash}/guess_label_key_type.rb +3 -1
  20. data/lib/nrser/{hash → functions/hash}/slice_keys.rb +3 -1
  21. data/lib/nrser/{hash → functions/hash}/stringify_keys.rb +2 -0
  22. data/lib/nrser/{hash → functions/hash}/symbolize_keys.rb +3 -1
  23. data/lib/nrser/{hash → functions/hash}/transform_keys.rb +3 -1
  24. data/lib/nrser/functions/merge_by.rb +29 -0
  25. data/lib/nrser/{object.rb → functions/object.rb} +0 -0
  26. data/lib/nrser/{object → functions/object}/as_array.rb +2 -0
  27. data/lib/nrser/{object → functions/object}/as_hash.rb +7 -5
  28. data/lib/nrser/{object → functions/object}/truthy.rb +46 -7
  29. data/lib/nrser/{open_struct.rb → functions/open_struct.rb} +0 -0
  30. data/lib/nrser/functions/path.rb +150 -0
  31. data/lib/nrser/{proc.rb → functions/proc.rb} +1 -22
  32. data/lib/nrser/functions/string.rb +297 -0
  33. data/lib/nrser/functions/string/looks_like.rb +44 -0
  34. data/lib/nrser/{text.rb → functions/text.rb} +0 -0
  35. data/lib/nrser/{text → functions/text}/indentation.rb +2 -16
  36. data/lib/nrser/{text → functions/text}/lines.rb +1 -2
  37. data/lib/nrser/{text → functions/text}/word_wrap.rb +2 -4
  38. data/lib/nrser/{tree.rb → functions/tree.rb} +0 -0
  39. data/lib/nrser/{tree → functions/tree}/each_branch.rb +6 -7
  40. data/lib/nrser/functions/tree/leaves.rb +92 -0
  41. data/lib/nrser/{tree → functions/tree}/map_branches.rb +31 -32
  42. data/lib/nrser/functions/tree/map_leaves.rb +56 -0
  43. data/lib/nrser/{tree → functions/tree}/map_tree.rb +9 -20
  44. data/lib/nrser/{tree → functions/tree}/transform.rb +0 -10
  45. data/lib/nrser/logger.rb +9 -10
  46. data/lib/nrser/message.rb +3 -7
  47. data/lib/nrser/meta.rb +2 -0
  48. data/lib/nrser/meta/class_attrs.rb +3 -9
  49. data/lib/nrser/meta/props.rb +19 -19
  50. data/lib/nrser/meta/props/base.rb +4 -10
  51. data/lib/nrser/meta/props/prop.rb +12 -28
  52. data/lib/nrser/no_arg.rb +1 -3
  53. data/lib/nrser/refinements.rb +5 -0
  54. data/lib/nrser/refinements/array.rb +5 -17
  55. data/lib/nrser/refinements/enumerator.rb +1 -3
  56. data/lib/nrser/refinements/hash.rb +3 -15
  57. data/lib/nrser/refinements/object.rb +2 -2
  58. data/lib/nrser/refinements/open_struct.rb +0 -2
  59. data/lib/nrser/refinements/pathname.rb +3 -46
  60. data/lib/nrser/refinements/set.rb +2 -6
  61. data/lib/nrser/refinements/string.rb +2 -2
  62. data/lib/nrser/rspex.rb +16 -13
  63. data/lib/nrser/types.rb +6 -20
  64. data/lib/nrser/types/any.rb +0 -1
  65. data/lib/nrser/types/booleans.rb +1 -1
  66. data/lib/nrser/types/combinators.rb +5 -5
  67. data/lib/nrser/types/in.rb +0 -21
  68. data/lib/nrser/types/responds.rb +1 -0
  69. data/lib/nrser/types/trees.rb +1 -0
  70. data/lib/nrser/version.rb +2 -3
  71. data/spec/nrser/{template_spec.rb → functions/binding/template_spec.rb} +0 -0
  72. data/spec/nrser/functions/enumerable/find_all_map_spec.rb +28 -0
  73. data/spec/nrser/functions/enumerable/find_bounded_spec.rb +70 -0
  74. data/spec/nrser/functions/enumerable/find_map_spec.rb +38 -0
  75. data/spec/nrser/functions/enumerable/find_only_spec.rb +25 -0
  76. data/spec/nrser/functions/enumerable/to_h_by_spec.rb +28 -0
  77. data/spec/nrser/{format_exception_spec.rb → functions/exception/format_exception_spec.rb} +0 -0
  78. data/spec/nrser/{hash → functions/hash}/bury_spec.rb +0 -0
  79. data/spec/nrser/{hash → functions/hash}/guess_label_key_type_spec.rb +0 -0
  80. data/spec/nrser/{hash_spec.rb → functions/hash_spec.rb} +0 -7
  81. data/spec/nrser/{merge_by_spec.rb → functions/merge_by_spec.rb} +0 -0
  82. data/spec/nrser/{truthy_spec.rb → functions/object/truthy_spec.rb} +0 -0
  83. data/spec/nrser/{open_struct_spec.rb → functions/open_struct_spec.rb} +0 -0
  84. data/spec/nrser/{string → functions/string}/common_prefix_spec.rb +0 -0
  85. data/spec/nrser/{string → functions/string}/looks_like_spec.rb +0 -0
  86. data/spec/nrser/{truncate_spec.rb → functions/string/truncate_spec.rb} +0 -0
  87. data/spec/nrser/{text → functions/text}/dedent/gotchas_spec.rb +0 -0
  88. data/spec/nrser/{text → functions/text}/dedent_spec.rb +0 -0
  89. data/spec/nrser/{indent_spec.rb → functions/text/indent_spec.rb} +0 -0
  90. data/spec/nrser/{tree → functions/tree}/each_branch_spec.rb +0 -0
  91. data/spec/nrser/{tree → functions/tree}/leaves_spec.rb +0 -0
  92. data/spec/nrser/{tree → functions/tree}/map_branch_spec.rb +0 -0
  93. data/spec/nrser/{tree → functions/tree}/map_tree_spec.rb +0 -0
  94. data/spec/nrser/{tree → functions/tree}/transform_spec.rb +0 -0
  95. data/spec/nrser/{tree → functions/tree}/transformer_spec.rb +0 -0
  96. data/spec/nrser/meta/class_attrs_spec.rb +12 -14
  97. data/spec/spec_helper.rb +2 -3
  98. metadata +136 -110
  99. data/lib/nrser/enumerable.rb +0 -288
  100. data/lib/nrser/exception.rb +0 -7
  101. data/lib/nrser/hash/bury.rb +0 -154
  102. data/lib/nrser/merge_by.rb +0 -26
  103. data/lib/nrser/string.rb +0 -294
  104. data/lib/nrser/string/looks_like.rb +0 -51
  105. data/lib/nrser/tree/leaves.rb +0 -92
  106. data/lib/nrser/tree/map_leaves.rb +0 -63
  107. data/spec/nrser/enumerable_spec.rb +0 -111
@@ -1,7 +1,5 @@
1
- require_relative './enumerable'
2
-
3
1
  module NRSER
4
2
  refine ::Enumerator do
5
- include NRSER::Refinements::Enumerable
3
+ include NRSER::Ext::Enumerable
6
4
  end # refine ::Enumerator
7
5
  end # NRSER
@@ -1,20 +1,8 @@
1
- # Requirements
2
- # =======================================================================
3
-
4
- # Project / Package
5
- # -----------------------------------------------------------------------
6
- require_relative './enumerable'
7
- require_relative './tree'
8
-
9
-
10
- # Definitions
11
- # =======================================================================
12
-
13
1
  module NRSER
14
2
 
15
3
  refine ::Hash do
16
- include NRSER::Refinements::Enumerable
17
- include NRSER::Refinements::Tree
4
+ include NRSER::Ext::Enumerable
5
+ include NRSER::Ext::Tree
18
6
 
19
7
 
20
8
  # See {NRSER.except_keys!}.
@@ -159,4 +147,4 @@ module NRSER
159
147
  end
160
148
 
161
149
  end # refine ::Hash
162
- end # NRSER
150
+ end # NRSER
@@ -9,7 +9,7 @@
9
9
 
10
10
  # Project / Package
11
11
  # -----------------------------------------------------------------------
12
- require 'nrser/object'
12
+ require 'nrser/functions/object'
13
13
 
14
14
 
15
15
  # Definitions
@@ -53,4 +53,4 @@ module NRSER
53
53
  NRSER.as_array self
54
54
  end
55
55
  end
56
- end # NRSER
56
+ end # NRSER
@@ -1,5 +1,3 @@
1
- require 'ostruct'
2
-
3
1
  module NRSER
4
2
  refine OpenStruct do
5
3
 
@@ -1,48 +1,5 @@
1
- require 'pathname'
2
-
3
- module NRSER
4
- refine Pathname do
5
- # override to accept Pathname instances.
6
- #
7
- # @param [String] *prefixes
8
- # the prefixes to see if the Pathname starts with.
9
- #
10
- # @return [Boolean]
11
- # true if the Pathname starts with any of the prefixes.
12
- #
13
- def start_with? *prefixes
14
- to_s.start_with? *prefixes.map(&:to_s)
15
- end
16
-
17
- # override sub to support Pathname instances as patterns.
18
- #
19
- # @param [String | Regexp | Pathname] pattern
20
- # thing to replace.
21
- #
22
- # @param [String | Hash] replacement
23
- # thing to replace it with.
24
- #
25
- # @return [Pathname]
26
- # new Pathname.
27
- #
28
- def sub pattern, replacement
29
- case pattern
30
- when Pathname
31
- super pattern.to_s, replacement
32
- else
33
- super pattern, replacement
34
- end
35
- end
36
-
37
-
38
- # Just returns `self`. Implemented to match the {String#to_pn} API so it
39
- # can be called on an argument that may be either one.
40
- #
41
- # @return [Pathname]
42
- #
43
- def to_pn
44
- Pathname.new self
45
- end
46
-
1
+ module NRSER
2
+ refine ::Pathname do
3
+ include NRSER::Ext::Pathname
47
4
  end # Pathname
48
5
  end # NRSER
@@ -1,9 +1,5 @@
1
- require 'set'
2
-
3
- require_relative './enumerable'
4
-
5
1
  module NRSER
6
2
  refine ::Set do
7
- include NRSER::Refinements::Enumerable
3
+ include NRSER::Ext::Enumerable
8
4
  end # refine ::Set
9
- end # NRSER
5
+ end # NRSER
@@ -1,7 +1,7 @@
1
1
  require 'pathname'
2
2
 
3
- require 'nrser/string'
4
- require 'nrser/text'
3
+ require_relative '../functions/string'
4
+ require_relative '../functions/text'
5
5
 
6
6
  module NRSER
7
7
  refine String do
data/lib/nrser/rspex.rb CHANGED
@@ -22,8 +22,7 @@
22
22
 
23
23
  # Project / Package
24
24
  # -----------------------------------------------------------------------
25
- require 'nrser/message'
26
- require 'nrser/rspex/shared_examples'
25
+ require_relative './rspex/shared_examples'
27
26
 
28
27
 
29
28
  # Helpers
@@ -40,7 +39,7 @@ require 'nrser/rspex/shared_examples'
40
39
  def merge_expectations *expectations
41
40
  Hash.new { |result, state|
42
41
  result[state] = []
43
- }.tap { |result|
42
+ }.tap { |result|
44
43
  expectations.each { |ex|
45
44
  ex.each { |state, clauses|
46
45
  result[state] += clauses.to_a
@@ -98,7 +97,7 @@ end
98
97
 
99
98
  module NRSER; end
100
99
 
101
- module NRSER::RSpex
100
+ module NRSER::RSpex
102
101
 
103
102
  # Constants
104
103
  # =====================================================================
@@ -270,7 +269,7 @@ module NRSER::RSpex
270
269
  describe description, **metadata, type: type do
271
270
  subject( &subject_block ) if subject_block
272
271
  module_exec &body
273
- end # description,
272
+ end # description,
274
273
 
275
274
  end # #describe_x_type
276
275
 
@@ -281,7 +280,7 @@ module NRSER::RSpex
281
280
  # set a bunch of stuff up and build a helpful description.
282
281
  #
283
282
  # @todo
284
- # This is totally just a one-off right now... would need to be
283
+ # This is totally just a one-off right now... would need to be
285
284
  # generalized quite a bit...
286
285
  #
287
286
  # 1. Extraction of module, class, etc from metadata should be flexible
@@ -299,7 +298,7 @@ module NRSER::RSpex
299
298
  #
300
299
  # @return [nil]
301
300
  #
302
- def describe_spec_file description:,
301
+ def describe_spec_file description: nil,
303
302
  spec_path:,
304
303
  bind_subject: true,
305
304
  **metadata,
@@ -312,7 +311,12 @@ module NRSER::RSpex
312
311
 
313
312
  spec_rel_path = "./#{ Pathname.new( spec_path ).relative_path_from Pathname.getwd }"
314
313
 
315
- desc = "#{ metadata[:module].name }.#{ metadata[:method] } (#{ loc }) #{ description } Spec (#{ spec_rel_path})"
314
+ desc = [
315
+ "#{ metadata[:module].name }.#{ metadata[:method] }",
316
+ "(#{ loc })",
317
+ description,
318
+ "Spec (#{ spec_rel_path})"
319
+ ].compact.join " "
316
320
 
317
321
  describe desc, **metadata do
318
322
  if bind_subject
@@ -375,7 +379,7 @@ module NRSER::RSpex
375
379
  # Aliases to other names I was using at first... not preferring their use
376
380
  # at the moment.
377
381
  #
378
- # The `when_` one sucks because Atom de-dents the line, and `describe_`
382
+ # The `when_` one sucks because Atom de-dents the line, and `describe_`
379
383
  # is just clearer what the block is doing for people reading it.
380
384
  alias_method :called_with, :describe_called_with
381
385
  alias_method :when_called_with, :describe_called_with
@@ -400,7 +404,7 @@ module NRSER::RSpex
400
404
  # Object that will receive the message to create the new subject.
401
405
  #
402
406
  # @param [Boolean] publicly:
403
- # Send message publicly via {Object#public_send} (default) or privately
407
+ # Send message publicly via {Object#public_send} (default) or privately
404
408
  # via {Object.send}.
405
409
  #
406
410
  # @return
@@ -422,7 +426,7 @@ module NRSER::RSpex
422
426
  # Aliases to other names I was using at first... not preferring their use
423
427
  # at the moment.
424
428
  #
425
- # The `when_` one sucks because Atom de-dents the line, and `describe_`
429
+ # The `when_` one sucks because Atom de-dents the line, and `describe_`
426
430
  # is just clearer what the block is doing for people reading it.
427
431
  alias_method :sent_to, :describe_sent_to
428
432
  alias_method :when_sent_to, :describe_sent_to
@@ -442,7 +446,7 @@ module NRSER::RSpex
442
446
  #
443
447
  # 1. Expects a string title.
444
448
  #
445
- # 2. Prepends a little section squiggle `§` to the title so sections are
449
+ # 2. Prepends a little section squiggle `§` to the title so sections are
446
450
  # easier to pick out visually.
447
451
  #
448
452
  # 3. Adds `type: :section` metadata.
@@ -629,4 +633,3 @@ end
629
633
 
630
634
  # Make available at the top-level
631
635
  include NRSER::RSpex::ExampleGroup
632
-
data/lib/nrser/types.rb CHANGED
@@ -1,23 +1,7 @@
1
- # Requirements
2
- # =======================================================================
3
-
4
- # Stdlib
5
- # ---------------------------------------------------------------------
6
-
7
- # TODO Not sure if this needs to be here... can't find any usage of it in
8
- # quick searches, but I don't want to remove it now.
9
- require 'pp'
10
-
11
- # Deps
12
- # ---------------------------------------------------------------------
13
-
14
- # Package
15
- # ---------------------------------------------------------------------
16
-
17
1
  # Abstract infrastructure for type creation - stuff that doesn't define any
18
2
  # concrete type instances.
19
3
  #
20
- # Files that define concrete type instances on load (usually as module
4
+ # Files that define concrete type instances on load (usually as module
21
5
  # constants, which I'm still questioning a bit as a design because of the
22
6
  # uncontrollable mutability of Ruby and the importance of type checks)
23
7
  # need to be required in the "Post-Processing" section at the bottom.
@@ -30,14 +14,12 @@ require_relative './types/where'
30
14
  require_relative './types/combinators'
31
15
  require_relative './types/maybe'
32
16
  require_relative './types/attrs'
33
- require_relative './types/responds'
34
17
  require_relative './types/in'
35
18
 
36
19
 
37
20
  # Refinements
38
21
  # =======================================================================
39
22
 
40
- require 'nrser/refinements'
41
23
  using NRSER
42
24
 
43
25
 
@@ -143,7 +125,7 @@ module NRSER::Types
143
125
  end # .match
144
126
 
145
127
 
146
- # make a type instance from a object representation that can come from
128
+ # make a type instance from a object representation that can come from
147
129
  # a YAML or JSON declaration.
148
130
  def self.from_repr repr
149
131
  match repr, {
@@ -168,6 +150,10 @@ end # NRSER::Types
168
150
 
169
151
  require_relative './types/any'
170
152
  require_relative './types/booleans'
153
+
154
+ # Requires `booleans`
155
+ require_relative './types/responds'
156
+
171
157
  require_relative './types/numbers'
172
158
  require_relative './types/strings'
173
159
  require_relative './types/symbols'
@@ -1,7 +1,6 @@
1
1
  require 'nrser/refinements'
2
2
  require 'nrser/types/where'
3
3
 
4
- using NRSER
5
4
 
6
5
  module NRSER::Types
7
6
  ANY = where(name: 'AnyType', from_s: ->(s) { s }) { true }.freeze
@@ -44,4 +44,4 @@ module NRSER::Types
44
44
  bool
45
45
  end
46
46
 
47
- end # NRSER::Types
47
+ end # NRSER::Types
@@ -16,8 +16,8 @@ module NRSER::Types
16
16
 
17
17
 
18
18
  def default_name
19
- "#{ self.class.short_name }<" +
20
- @types.map {|type| type.name }.join(',') +
19
+ "#{ self.class.short_name }<" +
20
+ @types.map {|type| type.name }.join(',') +
21
21
  ">"
22
22
  end
23
23
 
@@ -100,7 +100,7 @@ module NRSER::Types
100
100
  end
101
101
  end
102
102
 
103
- class Union < Combinator
103
+ class Union < Combinator
104
104
  def test value
105
105
  @types.any? {|type| type.test value}
106
106
  end
@@ -113,7 +113,7 @@ module NRSER::Types
113
113
 
114
114
  singleton_class.send :alias_method, :one_of, :union
115
115
 
116
- class Intersection < Combinator
116
+ class Intersection < Combinator
117
117
  def test value
118
118
  @types.all? {|type| type.test value}
119
119
  end
@@ -130,4 +130,4 @@ module NRSER::Types
130
130
 
131
131
  singleton_class.send :alias_method, :all_of, :intersection
132
132
 
133
- end # NRSER::Types
133
+ end # NRSER::Types
@@ -1,30 +1,9 @@
1
- # Requirements
2
- # =======================================================================
3
-
4
- # Stdlib
5
- # -----------------------------------------------------------------------
6
-
7
- # Deps
8
- # -----------------------------------------------------------------------
9
-
10
- # Project / Package
11
- # -----------------------------------------------------------------------
12
- require_relative './where'
13
-
14
-
15
1
  # Refinements
16
2
  # =======================================================================
17
3
 
18
- require 'nrser/refinements'
19
4
  using NRSER
20
5
 
21
6
 
22
- # Declarations
23
- # =======================================================================
24
-
25
- module NRSER; end
26
-
27
-
28
7
  # Definitions
29
8
  # =======================================================================
30
9
 
@@ -1,3 +1,4 @@
1
+ require_relative './booleans'
1
2
 
2
3
  module NRSER::Types
3
4
 
@@ -11,6 +11,7 @@
11
11
  # -----------------------------------------------------------------------
12
12
  require_relative './combinators'
13
13
  require_relative './responds'
14
+ require_relative './is_a'
14
15
 
15
16
 
16
17
  # Refinements
data/lib/nrser/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module NRSER
2
- VERSION = "0.0.30"
2
+ VERSION = "0.1.0"
3
3
 
4
4
  module Version
5
5
 
@@ -11,7 +11,7 @@ module NRSER
11
11
  end # .gem_version
12
12
 
13
13
 
14
- # The `Gem::Version` "release" for {NRSER::VERSION} - everything before
14
+ # The `Gem::Version` "release" for {NRSER::VERSION} - everything before
15
15
  # any `-<alpha-numeric>` prerelease part (like `-dev`).
16
16
  #
17
17
  # @see https://ruby-doc.org/stdlib-2.4.1/libdoc/rubygems/rdoc/Gem/Version.html#method-i-release
@@ -47,6 +47,5 @@ module NRSER
47
47
  )
48
48
  end # .doc_url
49
49
 
50
-
51
50
  end
52
51
  end
@@ -0,0 +1,28 @@
1
+ describe_spec_file(
2
+ spec_path: __FILE__,
3
+ module: NRSER,
4
+ method: :find_all_map,
5
+ ) do
6
+
7
+ describe "when results are found" do
8
+ it "should return the block results" do
9
+ expect(
10
+ subject.call( [1, 2, 3, 4] ) do |i|
11
+ if i.even?
12
+ "#{ i } is even!"
13
+ end
14
+ end
15
+ ).to eq ["2 is even!", "4 is even!"]
16
+ end
17
+ end
18
+
19
+
20
+ describe "when block returns `false`" do
21
+ it "response should be empty" do
22
+ expect(
23
+ subject.call( [1, 2, 3] ) { |i| false }
24
+ ).to eq []
25
+ end
26
+ end
27
+
28
+ end