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
data/lib/nrser/types/any.rb
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
# frozen_string_literal: true
|
3
|
-
|
4
|
-
module NRSER::Types
|
5
|
-
|
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
|
39
|
-
end
|
40
|
-
|
41
|
-
end # NRSER::Types
|
data/lib/nrser/types/attrs.rb
DELETED
@@ -1,213 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
# frozen_string_literal: true
|
3
|
-
|
4
|
-
|
5
|
-
# Requirements
|
6
|
-
# ========================================================================
|
7
|
-
|
8
|
-
# Project / Package
|
9
|
-
# ------------------------------------------------------------------------
|
10
|
-
|
11
|
-
require 'nrser/core_ext/hash'
|
12
|
-
|
13
|
-
require_relative './type'
|
14
|
-
require_relative './combinators'
|
15
|
-
require_relative './is'
|
16
|
-
|
17
|
-
|
18
|
-
# Definitions
|
19
|
-
# ========================================================================
|
20
|
-
|
21
|
-
module NRSER::Types
|
22
|
-
|
23
|
-
# Specify types for value attributes.
|
24
|
-
#
|
25
|
-
class AttrsType < NRSER::Types::Type
|
26
|
-
|
27
|
-
# Construct an `AttrsType`.
|
28
|
-
#
|
29
|
-
# @param [Hash<Symbol, TYPE>] attrs
|
30
|
-
# Map of attribute names to their types (`TYPE` values will be passed
|
31
|
-
# through {NRSER::Types.make} to get a type instance).
|
32
|
-
#
|
33
|
-
# May not be empty.
|
34
|
-
#
|
35
|
-
def initialize attrs, **options
|
36
|
-
super **options
|
37
|
-
|
38
|
-
if attrs.empty?
|
39
|
-
raise ArgumentError,
|
40
|
-
"Must provide at least one attribute name/type pair"
|
41
|
-
end
|
42
|
-
|
43
|
-
@attrs = attrs.transform_values &NRSER::Types.maker
|
44
|
-
end
|
45
|
-
|
46
|
-
|
47
|
-
# @see NRSER::Types::Type#explain
|
48
|
-
#
|
49
|
-
# @return [String]
|
50
|
-
#
|
51
|
-
def explain
|
52
|
-
attrs_str = @attrs.map { |name, type|
|
53
|
-
"##{ name }#{ RESPONDS_WITH }#{ type.name }"
|
54
|
-
}.join(', ')
|
55
|
-
|
56
|
-
if @attrs.length < 2
|
57
|
-
attrs_str
|
58
|
-
else
|
59
|
-
L_PAREN + attrs_str + R_PAREN
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
|
64
|
-
# @see NRSER::Types::Type#test
|
65
|
-
#
|
66
|
-
# @return [Boolean]
|
67
|
-
#
|
68
|
-
def test? value
|
69
|
-
@attrs.all? { |name, type|
|
70
|
-
value.respond_to?( name ) &&
|
71
|
-
type.test?( value.method( name ).call )
|
72
|
-
}
|
73
|
-
end
|
74
|
-
|
75
|
-
end # AttrsType
|
76
|
-
|
77
|
-
|
78
|
-
# @!group Type Factory Functions
|
79
|
-
|
80
|
-
# Get a {Type} that checks the types of one or more attributes on values.
|
81
|
-
#
|
82
|
-
# @example Type where first element of an Enumerable is a String
|
83
|
-
# string_first = intersection Enumerable, attrs(first: String)
|
84
|
-
#
|
85
|
-
def_factory :attrs do |*args|
|
86
|
-
case args.length
|
87
|
-
when 0
|
88
|
-
raise NRSER::ArgumentError.new \
|
89
|
-
"requires at least one argument"
|
90
|
-
when 1
|
91
|
-
attrs = args[0]
|
92
|
-
options = {}
|
93
|
-
when 2
|
94
|
-
attrs = args[0]
|
95
|
-
options = args[1]
|
96
|
-
end
|
97
|
-
|
98
|
-
AttrsType.new attrs, **options
|
99
|
-
end
|
100
|
-
|
101
|
-
|
102
|
-
# @overload length exact, options = {}
|
103
|
-
# Get a length attribute type that specifies an `exact` value.
|
104
|
-
#
|
105
|
-
# @example
|
106
|
-
# only_type = NRSER::Types.length 1
|
107
|
-
#
|
108
|
-
# only_type.test []
|
109
|
-
# # => false
|
110
|
-
#
|
111
|
-
# only_type.test [:x]
|
112
|
-
# # => true
|
113
|
-
#
|
114
|
-
# only_type.test [:x, :y]
|
115
|
-
# # => false
|
116
|
-
#
|
117
|
-
# @param [Integer] exact
|
118
|
-
# Exact non-negative integer that the length must be to satisfy the
|
119
|
-
# type created.
|
120
|
-
#
|
121
|
-
# @param [Hash] options
|
122
|
-
# Options hash passed up to {NRSER::Types::Type} constructor.
|
123
|
-
#
|
124
|
-
# @return [NRSER::Types::Attrs]
|
125
|
-
# Type satisfied by a `#length` attribute that is exactly `exact`.
|
126
|
-
#
|
127
|
-
#
|
128
|
-
# @overload length bounds, options = {}
|
129
|
-
# Get a length attribute type satisfied by values within a `:min` and
|
130
|
-
# `:max` (inclusive).
|
131
|
-
#
|
132
|
-
# @example
|
133
|
-
# three_to_five = NRSER::Types.length( {min: 3, max: 5}, name: '3-5' )
|
134
|
-
# three_to_five.test [1, 2] # => false
|
135
|
-
# three_to_five.test [1, 2, 3] # => true
|
136
|
-
# three_to_five.test [1, 2, 3, 4] # => true
|
137
|
-
# three_to_five.test [1, 2, 3, 4, 5] # => true
|
138
|
-
# three_to_five.test [1, 2, 3, 4, 5, 6] # => false
|
139
|
-
#
|
140
|
-
# @param [Hash] bounds
|
141
|
-
#
|
142
|
-
# @option bounds [Integer] :min
|
143
|
-
# An optional minimum value that the `#length` should not be less than.
|
144
|
-
#
|
145
|
-
# @option bounds [Integer] :max
|
146
|
-
# An optional maximum value that the `#length` should not be more than.
|
147
|
-
#
|
148
|
-
# @option bounds [Integer] :length
|
149
|
-
# An optional value for both the minimum and maximum.
|
150
|
-
#
|
151
|
-
# @param [Hash] options
|
152
|
-
# Options hash passed up to {NRSER::Types::Type} constructor.
|
153
|
-
#
|
154
|
-
# @return [NRSER::Types::Attrs]
|
155
|
-
# Type satisfied by a `#length` attribute between the `:min` and `:max`
|
156
|
-
# (inclusive).
|
157
|
-
#
|
158
|
-
def self.length *args
|
159
|
-
bounds = {}
|
160
|
-
options = if args[1].is_a?( Hash ) then args[1] else {} end
|
161
|
-
|
162
|
-
case args[0]
|
163
|
-
when ::Integer
|
164
|
-
# It's just a length
|
165
|
-
return attrs(
|
166
|
-
{ length: is( non_neg_int.check!( args[0] ) ) },
|
167
|
-
**options
|
168
|
-
)
|
169
|
-
|
170
|
-
bounds[:min] = bounds[:max] = non_neg_int.check args[0]
|
171
|
-
|
172
|
-
when ::Hash
|
173
|
-
# It's keyword args
|
174
|
-
kwds = args[0].sym_keys
|
175
|
-
|
176
|
-
# Pull any :min and :max in the keywords
|
177
|
-
bounds[:min] = kwds.delete :min
|
178
|
-
bounds[:max] = kwds.delete :max
|
179
|
-
|
180
|
-
# But override with :length if we got it
|
181
|
-
if length = kwds.delete(:length)
|
182
|
-
bounds[:min] = length
|
183
|
-
bounds[:max] = length
|
184
|
-
end
|
185
|
-
|
186
|
-
# (Reverse) merge anything else into the options (options hash values
|
187
|
-
# take precedence)
|
188
|
-
options = kwds.merge options
|
189
|
-
|
190
|
-
else
|
191
|
-
raise ArgumentError, <<-END.squish
|
192
|
-
arg must be positive integer or option hash, found:
|
193
|
-
#{ args[0].inspect } of type #{ args[0].class }
|
194
|
-
END
|
195
|
-
|
196
|
-
end
|
197
|
-
|
198
|
-
bounded_type = bounded bounds
|
199
|
-
|
200
|
-
length_type = if !bounded_type.min.nil? && bounded_type.min >= 0
|
201
|
-
# We don't need the non-neg check
|
202
|
-
bounded_type
|
203
|
-
else
|
204
|
-
# We do need the non-neg check
|
205
|
-
intersection(non_neg_int, bounded_type)
|
206
|
-
end
|
207
|
-
|
208
|
-
options[:name] ||= "Length<#{ bounded_type.name }>"
|
209
|
-
|
210
|
-
attrs({ length: length_type }, options)
|
211
|
-
end # #length
|
212
|
-
|
213
|
-
end # NRSER::Types
|
data/lib/nrser/types/trees.rb
DELETED
@@ -1,42 +0,0 @@
|
|
1
|
-
# Requirements
|
2
|
-
# =======================================================================
|
3
|
-
|
4
|
-
# Project / Package
|
5
|
-
# -----------------------------------------------------------------------
|
6
|
-
require_relative './combinators'
|
7
|
-
require_relative './responds'
|
8
|
-
require_relative './is_a'
|
9
|
-
|
10
|
-
|
11
|
-
# Definitions
|
12
|
-
# =======================================================================
|
13
|
-
|
14
|
-
module NRSER::Types
|
15
|
-
|
16
|
-
def_factory :array_like do |name: 'ArrayLike', **options|
|
17
|
-
intersection \
|
18
|
-
is_a( Enumerable ),
|
19
|
-
respond_to( :each_index ),
|
20
|
-
name: name,
|
21
|
-
**options
|
22
|
-
end # .array_like
|
23
|
-
|
24
|
-
|
25
|
-
def_factory :hash_like do |name: 'HashLike', **options|
|
26
|
-
intersection \
|
27
|
-
is_a( Enumerable ),
|
28
|
-
respond_to( :each_pair ),
|
29
|
-
name: name,
|
30
|
-
**options
|
31
|
-
end # .hash_like
|
32
|
-
|
33
|
-
|
34
|
-
def_factory :tree do |name: 'Tree', **options|
|
35
|
-
union \
|
36
|
-
array_like,
|
37
|
-
hash_like,
|
38
|
-
name: name,
|
39
|
-
**options
|
40
|
-
end # .tree
|
41
|
-
|
42
|
-
end # module NRSER::Types
|