nrser 0.3.9 → 0.3.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/nrser/char/alpha_numeric_sub.rb +9 -19
- data/lib/nrser/char/special.rb +5 -5
- data/lib/nrser/core_ext/array.rb +36 -13
- data/lib/nrser/core_ext/enumerable.rb +1 -0
- data/lib/nrser/core_ext/enumerable/find_map.rb +1 -1
- data/lib/nrser/core_ext/hash/bury.rb +3 -0
- data/lib/nrser/core_ext/hash/extract_values_at.rb +2 -2
- data/lib/nrser/core_ext/method/full_name.rb +1 -1
- data/lib/nrser/core_ext/module/method_objects.rb +1 -1
- data/lib/nrser/core_ext/module/source_locations.rb +27 -15
- data/lib/nrser/core_ext/object/lazy_var.rb +1 -1
- data/lib/nrser/core_ext/pathname.rb +67 -12
- data/lib/nrser/core_ext/pathname/subpath.rb +86 -0
- data/lib/nrser/core_ext/string.rb +28 -1
- data/lib/nrser/core_ext/symbol.rb +11 -12
- data/lib/nrser/errors/README.md +154 -0
- data/lib/nrser/errors/attr_error.rb +146 -53
- data/lib/nrser/errors/count_error.rb +61 -12
- data/lib/nrser/errors/nicer_error.rb +42 -71
- data/lib/nrser/errors/value_error.rb +53 -58
- data/lib/nrser/functions.rb +0 -2
- data/lib/nrser/functions/enumerable.rb +5 -17
- data/lib/nrser/functions/enumerable/associate.rb +14 -5
- data/lib/nrser/functions/enumerable/find_all_map.rb +1 -1
- data/lib/nrser/functions/enumerable/include_slice/array_include_slice.rb +1 -1
- data/lib/nrser/functions/hash/bury.rb +2 -12
- data/lib/nrser/functions/merge_by.rb +2 -2
- data/lib/nrser/functions/module/method_objects.rb +2 -2
- data/lib/nrser/functions/path.rb +185 -165
- data/lib/nrser/functions/path/normalized.rb +84 -0
- data/lib/nrser/functions/string.rb +4 -4
- data/lib/nrser/functions/text/README.md +4 -0
- data/lib/nrser/functions/text/format.rb +53 -0
- data/lib/nrser/functions/text/indentation.rb +6 -6
- data/lib/nrser/functions/text/word_wrap.rb +2 -2
- data/lib/nrser/functions/tree/map_leaves.rb +3 -3
- data/lib/nrser/functions/tree/map_tree.rb +2 -2
- data/lib/nrser/functions/tree/transform.rb +1 -18
- data/lib/nrser/gem_ext/README.md +4 -0
- data/lib/nrser/labs/README.md +8 -0
- data/lib/nrser/labs/config.rb +163 -0
- data/lib/nrser/labs/i8.rb +49 -159
- data/lib/nrser/labs/i8/struct.rb +167 -0
- data/lib/nrser/labs/i8/struct/hash.rb +140 -0
- data/lib/nrser/labs/i8/struct/vector.rb +149 -0
- data/lib/nrser/labs/i8/surjection.rb +211 -0
- data/lib/nrser/labs/lots/consumer.rb +19 -0
- data/lib/nrser/labs/lots/parser.rb +21 -1
- data/lib/nrser/labs/stash.rb +4 -4
- data/lib/nrser/log.rb +25 -21
- data/lib/nrser/log/appender/sync.rb +15 -11
- data/lib/nrser/log/formatters/color.rb +0 -3
- data/lib/nrser/log/formatters/mixin.rb +4 -4
- data/lib/nrser/log/logger.rb +54 -6
- data/lib/nrser/log/mixin.rb +2 -1
- data/lib/nrser/log/plugin.rb +6 -6
- data/lib/nrser/log/types.rb +46 -29
- data/lib/nrser/mean_streak.rb +0 -8
- data/lib/nrser/mean_streak/document.rb +1 -4
- data/lib/nrser/message.rb +3 -3
- data/lib/nrser/meta/README.md +4 -0
- data/lib/nrser/meta/lazy_attr.rb +2 -2
- data/lib/nrser/meta/source/location.rb +1 -1
- data/lib/nrser/props.rb +34 -3
- data/lib/nrser/props/class_methods.rb +2 -1
- data/lib/nrser/props/instance_methods.rb +9 -9
- data/lib/nrser/props/metadata.rb +4 -12
- data/lib/nrser/props/mutable/stash.rb +5 -2
- data/lib/nrser/props/prop.rb +10 -19
- data/lib/nrser/rspex.rb +1 -20
- data/lib/nrser/rspex/example_group/describe_attribute.rb +3 -0
- data/lib/nrser/rspex/example_group/describe_called_with.rb +9 -4
- data/lib/nrser/rspex/example_group/describe_case.rb +1 -0
- data/lib/nrser/rspex/example_group/describe_class.rb +2 -0
- data/lib/nrser/rspex/example_group/describe_group.rb +1 -1
- data/lib/nrser/rspex/example_group/describe_instance.rb +3 -1
- data/lib/nrser/rspex/example_group/describe_message.rb +1 -1
- data/lib/nrser/rspex/example_group/describe_method.rb +64 -30
- data/lib/nrser/rspex/example_group/describe_response_to.rb +1 -1
- data/lib/nrser/rspex/example_group/describe_section.rb +4 -1
- data/lib/nrser/rspex/example_group/describe_sent_to.rb +1 -1
- data/lib/nrser/rspex/example_group/describe_setup.rb +1 -0
- data/lib/nrser/rspex/example_group/describe_source_file.rb +1 -1
- data/lib/nrser/rspex/example_group/describe_spec_file.rb +4 -2
- data/lib/nrser/rspex/example_group/describe_when.rb +2 -1
- data/lib/nrser/rspex/example_group/describe_x.rb +5 -5
- data/lib/nrser/rspex/format.rb +0 -15
- data/lib/nrser/sugar/method_missing_forwarder.rb +3 -3
- data/lib/nrser/sys/env/path.rb +2 -28
- data/lib/nrser/types.rb +63 -12
- data/lib/nrser/types/README.md +76 -0
- data/lib/nrser/types/arrays.rb +192 -137
- data/lib/nrser/types/attributes.rb +269 -0
- data/lib/nrser/types/booleans.rb +134 -83
- data/lib/nrser/types/bounded.rb +110 -47
- data/lib/nrser/types/collections.rb +119 -0
- data/lib/nrser/types/combinators.rb +283 -196
- data/lib/nrser/types/doc/display_table.md +66 -0
- data/lib/nrser/types/eqiuvalent.rb +91 -0
- data/lib/nrser/types/errors/check_error.rb +5 -11
- data/lib/nrser/types/errors/from_string_error.rb +3 -3
- data/lib/nrser/types/factory.rb +287 -20
- data/lib/nrser/types/hashes.rb +227 -179
- data/lib/nrser/types/in.rb +73 -36
- data/lib/nrser/types/is.rb +67 -60
- data/lib/nrser/types/is_a.rb +141 -84
- data/lib/nrser/types/labels.rb +45 -16
- data/lib/nrser/types/maybe.rb +6 -3
- data/lib/nrser/types/nil.rb +64 -27
- data/lib/nrser/types/not.rb +92 -34
- data/lib/nrser/types/numbers.rb +224 -169
- data/lib/nrser/types/pairs.rb +113 -89
- data/lib/nrser/types/paths.rb +250 -137
- data/lib/nrser/types/responds.rb +167 -89
- data/lib/nrser/types/selector.rb +234 -0
- data/lib/nrser/types/shape.rb +136 -65
- data/lib/nrser/types/strings.rb +189 -63
- data/lib/nrser/types/symbols.rb +83 -33
- data/lib/nrser/types/top.rb +89 -0
- data/lib/nrser/types/tuples.rb +134 -98
- data/lib/nrser/types/type.rb +617 -505
- data/lib/nrser/types/when.rb +123 -98
- data/lib/nrser/types/where.rb +182 -91
- data/lib/nrser/version.rb +1 -1
- data/spec/lib/nrser/core_ext/pathname/subpath_spec.rb +22 -0
- data/spec/lib/nrser/errors/attr_error_spec.rb +68 -0
- data/spec/lib/nrser/errors/count_error_spec.rb +69 -0
- data/spec/lib/nrser/functions/path/normalize_path_spec.rb +35 -0
- data/spec/lib/nrser/functions/tree/map_tree_spec.rb +74 -96
- data/spec/lib/nrser/functions/tree/transform_spec.rb +11 -11
- data/spec/lib/nrser/labs/config_spec.rb +22 -0
- data/spec/lib/nrser/labs/i8/struct_spec.rb +39 -0
- data/spec/lib/nrser/types/display_spec.rb +50 -0
- data/spec/lib/nrser/types/paths_spec.rb +16 -10
- data/spec/lib/nrser/types/selector_spec.rb +125 -0
- data/spec/spec_helper.rb +4 -5
- metadata +105 -22
- data/lib/nrser/types/any.rb +0 -41
- data/lib/nrser/types/attrs.rb +0 -213
- data/lib/nrser/types/trees.rb +0 -42
@@ -19,67 +19,8 @@ require 'nrser/core_ext/object/lazy_var'
|
|
19
19
|
|
20
20
|
# A mixin for {Exception} and utilities to make life better... even when things
|
21
21
|
# go wrong.
|
22
|
-
#
|
23
|
-
#
|
24
|
-
#
|
25
|
-
# 1. **`message` is a splat/`Array`**
|
26
|
-
#
|
27
|
-
# Accept an {Array} `message` instead of just a string, dumping non-string
|
28
|
-
# values and joining everything together.
|
29
|
-
#
|
30
|
-
# This lets you deal with printing/dumping all in one place instead of
|
31
|
-
# ad-hoc'ing `#to_s`, `#inspect`, `#pretty_inspect`, etc. all over the
|
32
|
-
# place (though you can still dump values yourself of course since string
|
33
|
-
# pass right through).
|
34
|
-
#
|
35
|
-
# Write things like:
|
36
|
-
#
|
37
|
-
# MyError.new "The value", value, "sucks, it should be", expected
|
38
|
-
#
|
39
|
-
# This should cut down the amount of typing when raising as well, which
|
40
|
-
# is always welcome.
|
41
|
-
#
|
42
|
-
# It also allows for a future where we get smarter about dumping things,
|
43
|
-
# offer configuration options, switch on environments (slow, rich dev
|
44
|
-
# versus fast, concise prod), etc.
|
45
|
-
#
|
46
|
-
# 2. **"Extended" Messages**
|
47
|
-
#
|
48
|
-
# The normal message that we talked about in (1) - that we call the
|
49
|
-
# *summary message* or *super-message* (since it gets passed up to the
|
50
|
-
# built-in Exception's `#initialize`) - is intended to be:
|
51
|
-
#
|
52
|
-
# 1. Very concise
|
53
|
-
# - A single line well under 80 characters if possible.
|
54
|
-
#
|
55
|
-
# - This just seems like how Ruby exception messages were meant to
|
56
|
-
# be, I guess, and in many situations it's all you would want or
|
57
|
-
# need (production, when it just gets rescued anyways,
|
58
|
-
# there's no one there to read it, etc.).
|
59
|
-
#
|
60
|
-
# 2. Cheap to render.
|
61
|
-
# - We may be trying to do lot very quickly on a production system.
|
62
|
-
#
|
63
|
-
# However - especially when developing - it can be really nice to add
|
64
|
-
# considerably more detail and feedback to errors.
|
65
|
-
#
|
66
|
-
# To support this important use case as well, `NicerError` introduces the
|
67
|
-
# idea of an *extended message* that does not need to be rendered and
|
68
|
-
# output along with the *summary/super-message*.
|
69
|
-
#
|
70
|
-
# It's rendering is done on-demand, so systems that are not configured to
|
71
|
-
# use it will pay a minimal cost for it's existence.
|
72
|
-
#
|
73
|
-
# > See {#extended_message}.
|
74
|
-
#
|
75
|
-
# The extended message is composed of:
|
76
|
-
#
|
77
|
-
# 1. Text *details*, optionally rendered via {Binding.erb} when a
|
78
|
-
# binding is provided.
|
79
|
-
#
|
80
|
-
# 2. A *context* of name and value pairs to dump.
|
81
|
-
#
|
82
|
-
# Both are provided as optional keyword parameters to {#initialize}.
|
22
|
+
#
|
23
|
+
# Check the docs at the {file:lib/nrser/errors/README.md nrser/errors README}.
|
83
24
|
#
|
84
25
|
module NRSER::NicerError
|
85
26
|
|
@@ -104,18 +45,44 @@ module NRSER::NicerError
|
|
104
45
|
def self.column_width
|
105
46
|
DEFAULT_COLUMN_WIDTH
|
106
47
|
end
|
48
|
+
|
49
|
+
|
50
|
+
module ClassMethods
|
51
|
+
def def_context_delegator keys:, presence_predicate: true
|
52
|
+
keys = Array keys
|
53
|
+
|
54
|
+
keys.each do |key|
|
55
|
+
define_method key do
|
56
|
+
if (found_key = keys.find { |k| context.key? k })
|
57
|
+
context[found_key]
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
if presence_predicate
|
62
|
+
define_method "#{ key }?" do
|
63
|
+
!!keys.find { |k| context.key? k }
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def self.included base
|
71
|
+
base.extend ClassMethods
|
72
|
+
end
|
107
73
|
|
108
74
|
|
109
75
|
# Construct a nicer error.
|
110
76
|
#
|
111
|
-
# @param [Array]
|
112
|
-
# Main message segments.
|
77
|
+
# @param [Array] message
|
78
|
+
# Main message segments. See {#format_message} and {#format_message_segment}
|
79
|
+
# for an understanding of how they are, well, formatted.
|
113
80
|
#
|
114
|
-
# @param [Binding?] binding
|
81
|
+
# @param [Binding?] binding
|
115
82
|
# When provided any details string will be rendered using it's
|
116
83
|
# {Binding#erb} method.
|
117
84
|
#
|
118
|
-
# @param [nil | String | Proc<()=>String> | #to_s] details
|
85
|
+
# @param [nil | String | Proc<()=>String> | #to_s] details
|
119
86
|
# Additional text details to add to the extended message. When:
|
120
87
|
#
|
121
88
|
# 1. `nil` - no details will be added.
|
@@ -131,16 +98,16 @@ module NRSER::NicerError
|
|
131
98
|
# `#to_s` will be called on the value and the result will be used
|
132
99
|
# as in (2).
|
133
100
|
#
|
134
|
-
# @param [Hash<Symbol, VALUE>]
|
101
|
+
# @param [Hash<Symbol, VALUE>] context
|
135
102
|
# Any additional names and values to dump with an extended message.
|
136
103
|
#
|
137
104
|
def initialize *message,
|
138
105
|
binding: nil,
|
139
106
|
details: nil,
|
140
107
|
**context
|
141
|
-
@binding = binding
|
142
|
-
@context = context
|
143
|
-
@details = details
|
108
|
+
@binding = binding.freeze
|
109
|
+
@context = context.freeze
|
110
|
+
@details = details.freeze
|
144
111
|
|
145
112
|
message = default_message if message.empty?
|
146
113
|
super_message = format_message *message
|
@@ -159,6 +126,10 @@ module NRSER::NicerError
|
|
159
126
|
# @return [String]
|
160
127
|
# The formatted string for the segment.
|
161
128
|
#
|
129
|
+
# @todo
|
130
|
+
# This should talk to config when that comes about to find out how to
|
131
|
+
# dump things.
|
132
|
+
#
|
162
133
|
def format_message_segment segment
|
163
134
|
return segment.to_summary if segment.respond_to?( :to_summary )
|
164
135
|
|
@@ -171,7 +142,7 @@ module NRSER::NicerError
|
|
171
142
|
|
172
143
|
# Format the main message by converting args to strings and joining them.
|
173
144
|
#
|
174
|
-
# @param [Array]
|
145
|
+
# @param [Array] message
|
175
146
|
# Message segments.
|
176
147
|
#
|
177
148
|
# @return [String]
|
@@ -306,7 +277,7 @@ module NRSER::NicerError
|
|
306
277
|
# {Exception#message} just forwards here, so I overrode that with
|
307
278
|
# {#message} to just get the *summary/super-message* from this method.
|
308
279
|
#
|
309
|
-
# @param [Boolean?] extended
|
280
|
+
# @param [Boolean?] extended
|
310
281
|
# Flag to explicitly control summary/super or extended message:
|
311
282
|
#
|
312
283
|
# 1. `nil` - call {#add_extended_message?} to decide (default).
|
@@ -1,5 +1,21 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
# encoding: UTF-8
|
2
3
|
|
4
|
+
# Requirements
|
5
|
+
# ========================================================================
|
6
|
+
|
7
|
+
# Make nice(r)
|
8
|
+
require_relative './nicer_error'
|
9
|
+
|
10
|
+
|
11
|
+
# Namespace
|
12
|
+
# ========================================================================
|
13
|
+
|
14
|
+
module NRSER
|
15
|
+
|
16
|
+
|
17
|
+
# Definitions
|
18
|
+
# ========================================================================
|
3
19
|
|
4
20
|
# Raised when there is a problem with a *value* that does not fall into one
|
5
21
|
# of the other built-in exception categories (non-exhaustive list):
|
@@ -7,66 +23,45 @@
|
|
7
23
|
# 1. It's the wrong type (TypeError)
|
8
24
|
# 2. It's an argument (ArgumentError)
|
9
25
|
#
|
10
|
-
#
|
11
|
-
#
|
26
|
+
# It is encouraged to attach the invalid value as the `value:` keyword argument,
|
27
|
+
# which is then stored in {#context} hash and can be accessed via {#value}.
|
12
28
|
#
|
13
29
|
class NRSER::ValueError < StandardError
|
30
|
+
|
31
|
+
# Play nice :)
|
32
|
+
include NicerError
|
14
33
|
|
15
|
-
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
# If we received `nil` for the message, call {#build_message} to get it.
|
26
|
-
#
|
27
|
-
# This provides a "hook" to assemble the message at the last possible
|
28
|
-
# moment before it needs to go up to {StandardError#initialize}, allowing
|
29
|
-
# {#build_message} to work with an otherwise fully-initialized instance.
|
30
|
-
#
|
31
|
-
# Of course, {NRSER::ValueError#build_message}
|
32
|
-
# throws {NotImplementedError} since it doesn't really have enough
|
33
|
-
# knowledge to build anything useful (we're going for useful errors,
|
34
|
-
# "Value #{ value } is invalid" does not suffice).
|
35
|
-
#
|
36
|
-
message = build_message if message.nil?
|
37
|
-
|
38
|
-
super message
|
39
|
-
end
|
40
|
-
|
41
|
-
|
42
|
-
# Build the error message when none is provided to `#initialize`.
|
34
|
+
# @!method value?
|
35
|
+
# `true` if we have a `:value` key in the {#context}.
|
36
|
+
#
|
37
|
+
# @return [Boolean]
|
38
|
+
#
|
39
|
+
# @!method value
|
40
|
+
# Get the value at the `:value` key in {#context}.
|
41
|
+
#
|
42
|
+
# @return [Object]
|
43
43
|
#
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
#
|
48
|
-
#
|
49
|
-
#
|
50
|
-
#
|
51
|
-
#
|
52
|
-
#
|
53
|
-
#
|
54
|
-
#
|
55
|
-
#
|
56
|
-
#
|
57
|
-
#
|
58
|
-
#
|
59
|
-
# message.
|
60
|
-
#
|
61
|
-
# @return [String]
|
62
|
-
# Implementations must return the message string for
|
63
|
-
# {StadardError#initialize}.
|
64
|
-
#
|
65
|
-
# @raise [NRSER::AbstractMethodError]
|
66
|
-
# Must be implemented by subclasses if they wish to use message building.
|
44
|
+
def_context_delegator keys: :value
|
45
|
+
|
46
|
+
|
47
|
+
# @!method initialize *message, **kwds
|
48
|
+
# Create a new {ValueError}.
|
49
|
+
#
|
50
|
+
# @param [Array] message
|
51
|
+
# See {NicerError#initialize}.
|
52
|
+
#
|
53
|
+
# @param [Hash<Symbol, Object>] kwds
|
54
|
+
# Except as called out below, other keywords are passed up to
|
55
|
+
# {NicerError#initialize}.
|
56
|
+
#
|
57
|
+
# @option kwds [Object] :value
|
58
|
+
# The problematic value.
|
67
59
|
#
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
60
|
+
|
61
|
+
end # class ValueError
|
62
|
+
|
63
|
+
|
64
|
+
# /Namespace
|
65
|
+
# ========================================================================
|
66
|
+
|
67
|
+
end # module NRSER
|
data/lib/nrser/functions.rb
CHANGED
@@ -48,7 +48,7 @@ module NRSER
|
|
48
48
|
# Passed as only argument to {NRSER::Types.length} to create the length
|
49
49
|
# type the results are checked against.
|
50
50
|
#
|
51
|
-
# @param [Proc]
|
51
|
+
# @param [Proc] block
|
52
52
|
# `#find`/`#find_all`-style block that will be called with each entry
|
53
53
|
# from `enum`. Truthy responses mean the entry matched.
|
54
54
|
#
|
@@ -109,7 +109,7 @@ module NRSER
|
|
109
109
|
# Enumerable in question (really, anything that responds to `#first` and
|
110
110
|
# `#count`).
|
111
111
|
#
|
112
|
-
# @param [D] default
|
112
|
+
# @param [D] default
|
113
113
|
# Value to return if `enum` does not have only one entry.
|
114
114
|
#
|
115
115
|
# @return [E]
|
@@ -142,19 +142,7 @@ module NRSER
|
|
142
142
|
count = enum.count
|
143
143
|
|
144
144
|
unless count == 1
|
145
|
-
|
146
|
-
Expected enumerable to have #count == 1 but it has
|
147
|
-
|
148
|
-
#count = <%= enum.count %>
|
149
|
-
|
150
|
-
Enumerable (class: <%= enum.class %>):
|
151
|
-
|
152
|
-
<%= enum.pretty_inspect %>
|
153
|
-
|
154
|
-
END
|
155
|
-
|
156
|
-
raise NRSER::CountError.new message,
|
157
|
-
subject: enum,
|
145
|
+
raise NRSER::CountError.new value: enum,
|
158
146
|
count: count,
|
159
147
|
expected: 1
|
160
148
|
end
|
@@ -206,7 +194,7 @@ module NRSER
|
|
206
194
|
# {Enumerable} (or other object with compatible `#each_with_object` and
|
207
195
|
# `#to_enum` methods) you want to count.
|
208
196
|
#
|
209
|
-
# @param [Proc<(E)=>C>]
|
197
|
+
# @param [Proc<(E)=>C>] block
|
210
198
|
# Block mapping entries in `enum` to the group to count them in.
|
211
199
|
#
|
212
200
|
# @return [Hash{C=>Integer}]
|
@@ -229,7 +217,7 @@ module NRSER
|
|
229
217
|
# @param [Enumerable<E>] enum
|
230
218
|
# Values to call `&block` with.
|
231
219
|
#
|
232
|
-
# @param [Proc<E=>V>]
|
220
|
+
# @param [Proc<E=>V>] block
|
233
221
|
# Block to call, which is expected to raise an error if it fails.
|
234
222
|
#
|
235
223
|
# @return [V]
|
@@ -24,7 +24,7 @@ module NRSER
|
|
24
24
|
# @param [Enumerable<V>] enum
|
25
25
|
# Enumerable containing the values for the hash.
|
26
26
|
#
|
27
|
-
# @param [Proc<(V)=>K>]
|
27
|
+
# @param [Proc<(V)=>K>] block
|
28
28
|
# Block that maps `enum` values to their hash keys.
|
29
29
|
#
|
30
30
|
# @return [Hash<K, V>]
|
@@ -53,12 +53,21 @@ module NRSER
|
|
53
53
|
# Create a {Hash} mapping the entries in `enum` to the value returned by
|
54
54
|
# passing them through `&block`, raising on conflicts.
|
55
55
|
#
|
56
|
+
# @param [Enumerable<ENTRY>] enum
|
56
57
|
#
|
57
|
-
# @param [
|
58
|
-
#
|
58
|
+
# @param [ :raise | :first_wins | :last_wins | Proc ] on_conflict
|
59
|
+
# What to do when there's a conflict mapping the entries into the hash.
|
60
|
+
#
|
61
|
+
# The names are meant to make some sense.
|
59
62
|
#
|
60
|
-
# @
|
61
|
-
#
|
63
|
+
# @param [Proc<(ENTRY)=>VALUE>] block
|
64
|
+
# The star of the show! Maps `ENTRY` from `enum` to `VALUE` for the
|
65
|
+
# resulting hash.
|
66
|
+
#
|
67
|
+
# @return [Hash<ENTRY, VALUE>]
|
68
|
+
#
|
69
|
+
# @raise [NRSER::ConflictError]
|
70
|
+
# If a conflict occurs and `on_conflict` is set to `:raise`.
|
62
71
|
#
|
63
72
|
def self.assoc_to enum, on_conflict: :raise, &block
|
64
73
|
enum.each_with_object( {} ) { |entry, hash|
|
@@ -22,7 +22,7 @@ module NRSER
|
|
22
22
|
# The {Enumerable} slice that we want to see if `enum` includes. Must
|
23
23
|
# support `#length` and `#slice` like {Array} does.
|
24
24
|
#
|
25
|
-
# @param [Proc<(E, S)=>Boolean>]
|
25
|
+
# @param [Proc<(E, S)=>Boolean>] is_match
|
26
26
|
# Optional {Proc} that accepts an entry from `enum` and an entry from
|
27
27
|
# `slice` and returns if they match.
|
28
28
|
#
|
@@ -22,7 +22,7 @@ module NRSER
|
|
22
22
|
# @param [Object] value
|
23
23
|
# The value to set at the end of the path.
|
24
24
|
#
|
25
|
-
# @param [Class | :guess] parsed_key_type
|
25
|
+
# @param [Class | :guess] parsed_key_type
|
26
26
|
# How to handle parsed key path segments:
|
27
27
|
#
|
28
28
|
# - `String` - use the strings that naturally split from a parsed
|
@@ -68,17 +68,7 @@ module NRSER
|
|
68
68
|
create_arrays_for_unsigned_keys: create_arrays_for_unsigned_keys
|
69
69
|
end # .bury!
|
70
70
|
|
71
|
-
|
72
|
-
# @todo Document _internal_bury! method.
|
73
|
-
#
|
74
|
-
# @private
|
75
|
-
#
|
76
|
-
# @param [type] arg_name
|
77
|
-
# @todo Add name param description.
|
78
|
-
#
|
79
|
-
# @return [return_type]
|
80
|
-
# @todo Document return value.
|
81
|
-
#
|
71
|
+
|
82
72
|
def self._internal_bury! tree,
|
83
73
|
key_path,
|
84
74
|
value,
|
@@ -8,11 +8,11 @@ module NRSER
|
|
8
8
|
# @param [Array<Hash>] current
|
9
9
|
# Current (base) array of hashes to start with (lowest predominance).
|
10
10
|
#
|
11
|
-
# @param [Array<Hash>]
|
11
|
+
# @param [Array<Hash>] updates
|
12
12
|
# One or more arrays of update hashes to merge over `current` (last is
|
13
13
|
# highest predominance).
|
14
14
|
#
|
15
|
-
# @param [Proc<(Hash)=>Object>]
|
15
|
+
# @param [Proc<(Hash)=>Object>] merge_key
|
16
16
|
# Each hash is passed to `&merge_key` and the result is used to match
|
17
17
|
# hashes for merge. Must not return equal values for two different hashes
|
18
18
|
# in any of the arrays (`current` or any of `*updates`).
|