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.
- checksums.yaml +4 -4
- data/lib/nrser.rb +56 -12
- data/lib/nrser/collection.rb +4 -7
- data/lib/nrser/ext.rb +5 -0
- data/lib/nrser/{refinements → ext}/enumerable.rb +11 -9
- data/lib/nrser/ext/pathname.rb +74 -0
- data/lib/nrser/{refinements → ext}/tree.rb +2 -26
- data/lib/nrser/functions.rb +18 -0
- data/lib/nrser/{array.rb → functions/array.rb} +2 -3
- data/lib/nrser/{binding.rb → functions/binding.rb} +0 -2
- data/lib/nrser/functions/enumerable.rb +355 -0
- data/lib/nrser/functions/enumerable/find_all_map.rb +33 -0
- data/lib/nrser/functions/enumerable/find_map.rb +53 -0
- data/lib/nrser/functions/exception.rb +17 -0
- data/lib/nrser/{hash.rb → functions/hash.rb} +0 -0
- data/lib/nrser/functions/hash/bury.rb +147 -0
- data/lib/nrser/{hash → functions/hash}/deep_merge.rb +5 -5
- data/lib/nrser/{hash → functions/hash}/except_keys.rb +2 -0
- data/lib/nrser/{hash → functions/hash}/guess_label_key_type.rb +3 -1
- data/lib/nrser/{hash → functions/hash}/slice_keys.rb +3 -1
- data/lib/nrser/{hash → functions/hash}/stringify_keys.rb +2 -0
- data/lib/nrser/{hash → functions/hash}/symbolize_keys.rb +3 -1
- data/lib/nrser/{hash → functions/hash}/transform_keys.rb +3 -1
- data/lib/nrser/functions/merge_by.rb +29 -0
- data/lib/nrser/{object.rb → functions/object.rb} +0 -0
- data/lib/nrser/{object → functions/object}/as_array.rb +2 -0
- data/lib/nrser/{object → functions/object}/as_hash.rb +7 -5
- data/lib/nrser/{object → functions/object}/truthy.rb +46 -7
- data/lib/nrser/{open_struct.rb → functions/open_struct.rb} +0 -0
- data/lib/nrser/functions/path.rb +150 -0
- data/lib/nrser/{proc.rb → functions/proc.rb} +1 -22
- data/lib/nrser/functions/string.rb +297 -0
- data/lib/nrser/functions/string/looks_like.rb +44 -0
- data/lib/nrser/{text.rb → functions/text.rb} +0 -0
- data/lib/nrser/{text → functions/text}/indentation.rb +2 -16
- data/lib/nrser/{text → functions/text}/lines.rb +1 -2
- data/lib/nrser/{text → functions/text}/word_wrap.rb +2 -4
- data/lib/nrser/{tree.rb → functions/tree.rb} +0 -0
- data/lib/nrser/{tree → functions/tree}/each_branch.rb +6 -7
- data/lib/nrser/functions/tree/leaves.rb +92 -0
- data/lib/nrser/{tree → functions/tree}/map_branches.rb +31 -32
- data/lib/nrser/functions/tree/map_leaves.rb +56 -0
- data/lib/nrser/{tree → functions/tree}/map_tree.rb +9 -20
- data/lib/nrser/{tree → functions/tree}/transform.rb +0 -10
- data/lib/nrser/logger.rb +9 -10
- data/lib/nrser/message.rb +3 -7
- data/lib/nrser/meta.rb +2 -0
- data/lib/nrser/meta/class_attrs.rb +3 -9
- data/lib/nrser/meta/props.rb +19 -19
- data/lib/nrser/meta/props/base.rb +4 -10
- data/lib/nrser/meta/props/prop.rb +12 -28
- data/lib/nrser/no_arg.rb +1 -3
- data/lib/nrser/refinements.rb +5 -0
- data/lib/nrser/refinements/array.rb +5 -17
- data/lib/nrser/refinements/enumerator.rb +1 -3
- data/lib/nrser/refinements/hash.rb +3 -15
- data/lib/nrser/refinements/object.rb +2 -2
- data/lib/nrser/refinements/open_struct.rb +0 -2
- data/lib/nrser/refinements/pathname.rb +3 -46
- data/lib/nrser/refinements/set.rb +2 -6
- data/lib/nrser/refinements/string.rb +2 -2
- data/lib/nrser/rspex.rb +16 -13
- data/lib/nrser/types.rb +6 -20
- data/lib/nrser/types/any.rb +0 -1
- data/lib/nrser/types/booleans.rb +1 -1
- data/lib/nrser/types/combinators.rb +5 -5
- data/lib/nrser/types/in.rb +0 -21
- data/lib/nrser/types/responds.rb +1 -0
- data/lib/nrser/types/trees.rb +1 -0
- data/lib/nrser/version.rb +2 -3
- data/spec/nrser/{template_spec.rb → functions/binding/template_spec.rb} +0 -0
- data/spec/nrser/functions/enumerable/find_all_map_spec.rb +28 -0
- data/spec/nrser/functions/enumerable/find_bounded_spec.rb +70 -0
- data/spec/nrser/functions/enumerable/find_map_spec.rb +38 -0
- data/spec/nrser/functions/enumerable/find_only_spec.rb +25 -0
- data/spec/nrser/functions/enumerable/to_h_by_spec.rb +28 -0
- data/spec/nrser/{format_exception_spec.rb → functions/exception/format_exception_spec.rb} +0 -0
- data/spec/nrser/{hash → functions/hash}/bury_spec.rb +0 -0
- data/spec/nrser/{hash → functions/hash}/guess_label_key_type_spec.rb +0 -0
- data/spec/nrser/{hash_spec.rb → functions/hash_spec.rb} +0 -7
- data/spec/nrser/{merge_by_spec.rb → functions/merge_by_spec.rb} +0 -0
- data/spec/nrser/{truthy_spec.rb → functions/object/truthy_spec.rb} +0 -0
- data/spec/nrser/{open_struct_spec.rb → functions/open_struct_spec.rb} +0 -0
- data/spec/nrser/{string → functions/string}/common_prefix_spec.rb +0 -0
- data/spec/nrser/{string → functions/string}/looks_like_spec.rb +0 -0
- data/spec/nrser/{truncate_spec.rb → functions/string/truncate_spec.rb} +0 -0
- data/spec/nrser/{text → functions/text}/dedent/gotchas_spec.rb +0 -0
- data/spec/nrser/{text → functions/text}/dedent_spec.rb +0 -0
- data/spec/nrser/{indent_spec.rb → functions/text/indent_spec.rb} +0 -0
- data/spec/nrser/{tree → functions/tree}/each_branch_spec.rb +0 -0
- data/spec/nrser/{tree → functions/tree}/leaves_spec.rb +0 -0
- data/spec/nrser/{tree → functions/tree}/map_branch_spec.rb +0 -0
- data/spec/nrser/{tree → functions/tree}/map_tree_spec.rb +0 -0
- data/spec/nrser/{tree → functions/tree}/transform_spec.rb +0 -0
- data/spec/nrser/{tree → functions/tree}/transformer_spec.rb +0 -0
- data/spec/nrser/meta/class_attrs_spec.rb +12 -14
- data/spec/spec_helper.rb +2 -3
- metadata +136 -110
- data/lib/nrser/enumerable.rb +0 -288
- data/lib/nrser/exception.rb +0 -7
- data/lib/nrser/hash/bury.rb +0 -154
- data/lib/nrser/merge_by.rb +0 -26
- data/lib/nrser/string.rb +0 -294
- data/lib/nrser/string/looks_like.rb +0 -51
- data/lib/nrser/tree/leaves.rb +0 -92
- data/lib/nrser/tree/map_leaves.rb +0 -63
- data/spec/nrser/enumerable_spec.rb +0 -111
|
@@ -1,13 +1,3 @@
|
|
|
1
|
-
# Requirements
|
|
2
|
-
# =======================================================================
|
|
3
|
-
|
|
4
|
-
# Project / Package
|
|
5
|
-
# -----------------------------------------------------------------------
|
|
6
|
-
require_relative './map_tree'
|
|
7
|
-
|
|
8
|
-
# Definitions
|
|
9
|
-
# =======================================================================
|
|
10
|
-
|
|
11
1
|
module NRSER
|
|
12
2
|
|
|
13
3
|
# @todo Document transform method.
|
data/lib/nrser/logger.rb
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
require 'pp'
|
|
4
|
-
require 'json'
|
|
5
|
-
|
|
6
|
-
require 'nrser'
|
|
7
|
-
require 'nrser/refinements'
|
|
1
|
+
# Refinements
|
|
2
|
+
# =======================================================================
|
|
8
3
|
|
|
9
4
|
using NRSER
|
|
10
5
|
|
|
6
|
+
|
|
7
|
+
# Definitions
|
|
8
|
+
# =======================================================================
|
|
9
|
+
|
|
11
10
|
module NRSER
|
|
12
11
|
|
|
13
12
|
# @todo doc class
|
|
@@ -61,10 +60,10 @@ module NRSER
|
|
|
61
60
|
# format a debug message with optional key / values to print
|
|
62
61
|
#
|
|
63
62
|
# @param name [String] logger name.
|
|
64
|
-
# @param level [String, Symbol, Fixnum] the level in string, symbol or
|
|
63
|
+
# @param level [String, Symbol, Fixnum] the level in string, symbol or
|
|
65
64
|
# integer form.
|
|
66
65
|
# @param msg [String] message to print.
|
|
67
|
-
# @param dump [Hash] optional hash of keys and vaues to dump.
|
|
66
|
+
# @param dump [Hash] optional hash of keys and vaues to dump.
|
|
68
67
|
def self.format name, level, msg, dump = {}
|
|
69
68
|
data = {
|
|
70
69
|
'logger' => name,
|
|
@@ -84,7 +83,7 @@ module NRSER
|
|
|
84
83
|
# msg
|
|
85
84
|
# end
|
|
86
85
|
|
|
87
|
-
def self.dump_value value
|
|
86
|
+
def self.dump_value value
|
|
88
87
|
case value
|
|
89
88
|
when String, Fixnum, Float, TrueClass, FalseClass
|
|
90
89
|
value
|
data/lib/nrser/message.rb
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
# Definitions
|
|
2
|
-
# =======================================================================
|
|
3
|
-
|
|
4
1
|
module NRSER
|
|
5
2
|
|
|
6
|
-
# Container for a message (method call) to be sent to a receiver via
|
|
3
|
+
# Container for a message (method call) to be sent to a receiver via
|
|
7
4
|
# {Object#send} (or {Object#public_send}).
|
|
8
5
|
#
|
|
9
6
|
# Encapsulates the method symbol as well as any arguments and block to send.
|
|
@@ -16,7 +13,7 @@ module NRSER
|
|
|
16
13
|
#
|
|
17
14
|
# msg.send_to obj
|
|
18
15
|
#
|
|
19
|
-
# Useful for clearly describing and recognizing data that is meant to be
|
|
16
|
+
# Useful for clearly describing and recognizing data that is meant to be
|
|
20
17
|
# sent to an object as a method call, especially in testing.
|
|
21
18
|
#
|
|
22
19
|
class Message
|
|
@@ -26,7 +23,7 @@ module NRSER
|
|
|
26
23
|
# Instantiate a message from the arguments, unless they already are one.
|
|
27
24
|
#
|
|
28
25
|
# @overload from symbol, *args, &block
|
|
29
|
-
# Create a new instance from the arguments by passing them to
|
|
26
|
+
# Create a new instance from the arguments by passing them to
|
|
30
27
|
# {NRSER::Message.new}.
|
|
31
28
|
#
|
|
32
29
|
# @param [NRSER::Message] message
|
|
@@ -155,4 +152,3 @@ module NRSER
|
|
|
155
152
|
end # class Message
|
|
156
153
|
|
|
157
154
|
end # module NRSER
|
|
158
|
-
|
data/lib/nrser/meta.rb
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
module NRSER
|
|
2
|
-
module Meta
|
|
3
|
-
|
|
4
1
|
# Mixin to provide methods to define and access class attributes - variables
|
|
5
2
|
# that act like instance variables with regards to inheritance but for the
|
|
6
3
|
# class itself.
|
|
7
4
|
#
|
|
8
|
-
# The motivation is to create a easy-to-use class instance variables that
|
|
5
|
+
# The motivation is to create a easy-to-use class instance variables that
|
|
9
6
|
# resolve like regular instance variables by looking up the inheritance
|
|
10
7
|
# hierarchy - meaning that:
|
|
11
8
|
#
|
|
@@ -23,7 +20,7 @@ module Meta
|
|
|
23
20
|
# The tests in `spec/nrser/class_attrs_spec.rb` provide detailed walk-through
|
|
24
21
|
# of usage and differences from other approaches.
|
|
25
22
|
#
|
|
26
|
-
module ClassAttrs
|
|
23
|
+
module NRSER::Meta::ClassAttrs
|
|
27
24
|
|
|
28
25
|
# Class methods to extend the receiver with when {NRSER::Meta::ClassAttrs}
|
|
29
26
|
# is included.
|
|
@@ -120,7 +117,4 @@ module ClassAttrs
|
|
|
120
117
|
base.extend ClassMethods
|
|
121
118
|
end
|
|
122
119
|
|
|
123
|
-
end # module ClassAttrs
|
|
124
|
-
|
|
125
|
-
end # module Meta
|
|
126
|
-
end # module NRSER
|
|
120
|
+
end # module NRSER::Meta::ClassAttrs
|
data/lib/nrser/meta/props.rb
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
require 'nrser/refinements'
|
|
4
|
-
require 'nrser/refinements/types'
|
|
1
|
+
# Refinements
|
|
2
|
+
# =======================================================================
|
|
5
3
|
|
|
6
4
|
using NRSER
|
|
7
5
|
using NRSER::Types
|
|
8
6
|
|
|
9
|
-
module NRSER
|
|
10
|
-
module Meta
|
|
11
7
|
|
|
12
|
-
|
|
8
|
+
# Definitions
|
|
9
|
+
# =======================================================================
|
|
10
|
+
|
|
11
|
+
module NRSER::Meta::Props
|
|
13
12
|
DEFAULT_CLASS_KEY = '__class__';
|
|
14
13
|
|
|
15
14
|
PROPS_VARIABLE_NAME = :@__NRSER_props
|
|
@@ -19,7 +18,7 @@ module Props
|
|
|
19
18
|
# Module Methods (Utilities)
|
|
20
19
|
# =====================================================================
|
|
21
20
|
#
|
|
22
|
-
# These are *NOT* mixed in to including classes, and must be accessed
|
|
21
|
+
# These are *NOT* mixed in to including classes, and must be accessed
|
|
23
22
|
# via `NRSER::Meta::Props.<method_name>`.
|
|
24
23
|
#
|
|
25
24
|
# They're utilities that should only really need to be used internally.
|
|
@@ -48,13 +47,13 @@ module Props
|
|
|
48
47
|
#
|
|
49
48
|
# **WARNING**
|
|
50
49
|
#
|
|
51
|
-
# I'm sure this is all-sorts of unsafe. Please don't ever think this is
|
|
50
|
+
# I'm sure this is all-sorts of unsafe. Please don't ever think this is
|
|
52
51
|
# reasonable to use on untrusted data.
|
|
53
52
|
#
|
|
54
53
|
# @param [Hash<String, Object>] data
|
|
55
54
|
# Data hash to load from.
|
|
56
55
|
#
|
|
57
|
-
# @param
|
|
56
|
+
# @param
|
|
58
57
|
#
|
|
59
58
|
# @return [NRSER::Meta::Props]
|
|
60
59
|
# Instance of a propertied class.
|
|
@@ -64,7 +63,7 @@ module Props
|
|
|
64
63
|
|
|
65
64
|
unless data.key?( class_key )
|
|
66
65
|
raise ArgumentError.new binding.erb <<-ERB
|
|
67
|
-
Data is missing <%= class_key %> key - no idea what class to
|
|
66
|
+
Data is missing <%= class_key %> key - no idea what class to
|
|
68
67
|
instantiate.
|
|
69
68
|
|
|
70
69
|
Data:
|
|
@@ -122,7 +121,7 @@ module Props
|
|
|
122
121
|
|
|
123
122
|
|
|
124
123
|
# Mixed-In Class Methods
|
|
125
|
-
# =====================================================================
|
|
124
|
+
# =====================================================================
|
|
126
125
|
|
|
127
126
|
# Methods added to the including *class* via `extend`.
|
|
128
127
|
#
|
|
@@ -171,7 +170,7 @@ module Props
|
|
|
171
170
|
# Constructor options for {NRSER::Meta::Props::Prop}.
|
|
172
171
|
#
|
|
173
172
|
# @return [NRSER::Meta::Props::Prop]
|
|
174
|
-
# The newly created prop, thought you probably don't need it (it's
|
|
173
|
+
# The newly created prop, thought you probably don't need it (it's
|
|
175
174
|
# already all bound up on the class at this point), but why not?
|
|
176
175
|
#
|
|
177
176
|
def prop name, **opts
|
|
@@ -284,13 +283,13 @@ module Props
|
|
|
284
283
|
# Create a "data" representation suitable for transport, storage, etc.
|
|
285
284
|
#
|
|
286
285
|
# The result is meant to consist of only basic data types and structures -
|
|
287
|
-
# strings, numbers, arrays, hashes, datetimes, etc... though it depends on
|
|
288
|
-
# any custom objects it encounters correctly responding to `#to_data` for
|
|
286
|
+
# strings, numbers, arrays, hashes, datetimes, etc... though it depends on
|
|
287
|
+
# any custom objects it encounters correctly responding to `#to_data` for
|
|
289
288
|
# this to happen (as is implemented from classes that mix in Props here).
|
|
290
289
|
#
|
|
291
290
|
# Prop names are converted to strings (from symbols) since though YAML
|
|
292
291
|
# supports symbol values, they have poor portability across languages,
|
|
293
|
-
# and they mean the same thing in this situation.
|
|
292
|
+
# and they mean the same thing in this situation.
|
|
294
293
|
#
|
|
295
294
|
# @param [type] arg_name
|
|
296
295
|
# @todo Add name param description.
|
|
@@ -344,8 +343,9 @@ module Props
|
|
|
344
343
|
|
|
345
344
|
end # module Props
|
|
346
345
|
|
|
347
|
-
|
|
348
|
-
|
|
346
|
+
|
|
347
|
+
# Post-Processing
|
|
348
|
+
# =======================================================================
|
|
349
349
|
|
|
350
350
|
require_relative './props/prop'
|
|
351
|
-
require_relative './props/base'
|
|
351
|
+
require_relative './props/base'
|
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
# Refinements
|
|
2
2
|
# =======================================================================
|
|
3
3
|
|
|
4
|
-
require 'nrser/refinements'
|
|
5
4
|
using NRSER
|
|
6
5
|
|
|
7
6
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
module Props
|
|
7
|
+
# Definitions
|
|
8
|
+
# =======================================================================
|
|
11
9
|
|
|
12
|
-
class Base
|
|
10
|
+
class NRSER::Meta::Props::Base
|
|
13
11
|
include NRSER::Meta::Props
|
|
14
12
|
|
|
15
13
|
def initialize **values
|
|
@@ -30,8 +28,4 @@ class Base
|
|
|
30
28
|
#<#{ self.class.name } #{ props_str }>
|
|
31
29
|
END
|
|
32
30
|
end # #to_s
|
|
33
|
-
end # class Base
|
|
34
|
-
|
|
35
|
-
end # module Props
|
|
36
|
-
end # module Meta
|
|
37
|
-
end # module NRSER
|
|
31
|
+
end # class NRSER::Meta::Props::Base
|
|
@@ -1,23 +1,7 @@
|
|
|
1
|
-
# Requirements
|
|
2
|
-
# =======================================================================
|
|
3
|
-
|
|
4
|
-
# Stdlib
|
|
5
|
-
# -----------------------------------------------------------------------
|
|
6
|
-
|
|
7
|
-
# Deps
|
|
8
|
-
# -----------------------------------------------------------------------
|
|
9
|
-
|
|
10
|
-
# Project / Package
|
|
11
|
-
# -----------------------------------------------------------------------
|
|
12
|
-
|
|
13
|
-
|
|
14
1
|
# Refinements
|
|
15
2
|
# =======================================================================
|
|
16
3
|
|
|
17
|
-
require 'nrser/refinements'
|
|
18
4
|
using NRSER
|
|
19
|
-
|
|
20
|
-
require 'nrser/refinements/types'
|
|
21
5
|
using NRSER::Types
|
|
22
6
|
|
|
23
7
|
|
|
@@ -65,7 +49,7 @@ class NRSER::Meta::Props::Prop
|
|
|
65
49
|
# method (method that takes no arguments) that provides the property's
|
|
66
50
|
# value.
|
|
67
51
|
#
|
|
68
|
-
# Props that have a source are considered *derived*, those that don't are
|
|
52
|
+
# Props that have a source are considered *derived*, those that don't are
|
|
69
53
|
# called *primary*.
|
|
70
54
|
#
|
|
71
55
|
# @return [Symbol | String]
|
|
@@ -104,7 +88,7 @@ class NRSER::Meta::Props::Prop
|
|
|
104
88
|
|
|
105
89
|
@source = source # TODO fix this: t.maybe( t.label ).check source
|
|
106
90
|
|
|
107
|
-
# Detect if the source
|
|
91
|
+
# Detect if the source
|
|
108
92
|
if source.nil?
|
|
109
93
|
@instance_variable_source = false
|
|
110
94
|
else
|
|
@@ -119,7 +103,7 @@ class NRSER::Meta::Props::Prop
|
|
|
119
103
|
# Can't provide both default and default_from
|
|
120
104
|
unless default.nil? || default_from.nil?
|
|
121
105
|
raise NRSER::ConflictError.new binding.erb <<-ERB
|
|
122
|
-
Both `default:` and `default_from:` keyword args provided when
|
|
106
|
+
Both `default:` and `default_from:` keyword args provided when
|
|
123
107
|
constructing <%= self %>. At least one must be `nil`.
|
|
124
108
|
|
|
125
109
|
default:
|
|
@@ -144,7 +128,7 @@ class NRSER::Meta::Props::Prop
|
|
|
144
128
|
@has_default = if source.nil?
|
|
145
129
|
@type.test default
|
|
146
130
|
else
|
|
147
|
-
# NOTE This is up for debate... does a derived property have a
|
|
131
|
+
# NOTE This is up for debate... does a derived property have a
|
|
148
132
|
# default? What does that even mean?
|
|
149
133
|
true # false ?
|
|
150
134
|
end
|
|
@@ -164,7 +148,7 @@ class NRSER::Meta::Props::Prop
|
|
|
164
148
|
# If we passed the check we know the value is valid
|
|
165
149
|
@has_default = true
|
|
166
150
|
|
|
167
|
-
# Set the default value to `default`, freezing it since it will be
|
|
151
|
+
# Set the default value to `default`, freezing it since it will be
|
|
168
152
|
# set on instances without any attempt at duplication, which seems like
|
|
169
153
|
# it *might be ok* since a lot of prop'd classes are being used
|
|
170
154
|
# immutably.
|
|
@@ -201,7 +185,7 @@ class NRSER::Meta::Props::Prop
|
|
|
201
185
|
end # #full_name
|
|
202
186
|
|
|
203
187
|
|
|
204
|
-
# Test if this prop is configured to provide default values -
|
|
188
|
+
# Test if this prop is configured to provide default values -
|
|
205
189
|
#
|
|
206
190
|
# @param [type] arg_name
|
|
207
191
|
# @todo Add name param description.
|
|
@@ -309,7 +293,7 @@ class NRSER::Meta::Props::Prop
|
|
|
309
293
|
def set instance, value
|
|
310
294
|
type.check( value ) do
|
|
311
295
|
binding.erb <<-END
|
|
312
|
-
Value of type <%= value.class.name %> for prop <%= self.full_name %>
|
|
296
|
+
Value of type <%= value.class.name %> for prop <%= self.full_name %>
|
|
313
297
|
failed type check.
|
|
314
298
|
|
|
315
299
|
Must satisfy type:
|
|
@@ -348,7 +332,7 @@ class NRSER::Meta::Props::Prop
|
|
|
348
332
|
set instance, default
|
|
349
333
|
else
|
|
350
334
|
raise TypeError.new binding.erb <<-ERB
|
|
351
|
-
Prop <#= full_name %> has no default value and no value was provided
|
|
335
|
+
Prop <#= full_name %> has no default value and no value was provided
|
|
352
336
|
in values:
|
|
353
337
|
|
|
354
338
|
<%= values.pretty_inspect %>
|
|
@@ -367,14 +351,14 @@ class NRSER::Meta::Props::Prop
|
|
|
367
351
|
# declaration:
|
|
368
352
|
#
|
|
369
353
|
# 1. {nil} *default*
|
|
370
|
-
# - If the property value responds to `#to_data`, the result of
|
|
354
|
+
# - If the property value responds to `#to_data`, the result of
|
|
371
355
|
# invoking that method will be returned.
|
|
372
356
|
#
|
|
373
357
|
# **WARNING**
|
|
374
358
|
#
|
|
375
359
|
# This can cause infinite recursion if an instance has
|
|
376
360
|
# a property value that is also an instance of the same class (as
|
|
377
|
-
# as other more complicated scenarios that boil down to the same
|
|
361
|
+
# as other more complicated scenarios that boil down to the same
|
|
378
362
|
# problem), but, really, what else would it do in this situation?
|
|
379
363
|
#
|
|
380
364
|
# This problem can be avoided by by providing a `to_data:` keyword
|
|
@@ -400,7 +384,7 @@ class NRSER::Meta::Props::Prop
|
|
|
400
384
|
# is returned if we don't have any better options, see above).
|
|
401
385
|
#
|
|
402
386
|
# @raise [TypeError]
|
|
403
|
-
# If {@to_data} (provided via the `to_data:` keyword at property
|
|
387
|
+
# If {@to_data} (provided via the `to_data:` keyword at property
|
|
404
388
|
# declaration) is anything other than {nil}, {String}, {Symbol} or {Proc}.
|
|
405
389
|
#
|
|
406
390
|
def to_data instance
|
|
@@ -491,7 +475,7 @@ class NRSER::Meta::Props::Prop
|
|
|
491
475
|
#
|
|
492
476
|
def to_s
|
|
493
477
|
"#<#{ self.class.name } #{ full_name }:#{ type }>"
|
|
494
|
-
end # #to_s
|
|
478
|
+
end # #to_s
|
|
495
479
|
|
|
496
480
|
|
|
497
481
|
private
|
data/lib/nrser/no_arg.rb
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
require 'singleton'
|
|
2
|
-
|
|
3
1
|
module NRSER
|
|
4
|
-
# A singleton class who's instance is used to denote the lack of value
|
|
2
|
+
# A singleton class who's instance is used to denote the lack of value
|
|
5
3
|
# for an argument when used as the default.
|
|
6
4
|
#
|
|
7
5
|
# For situations where an argument is optional and `nil` is a legitimate
|
data/lib/nrser/refinements.rb
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
# Declare the module
|
|
2
|
+
module NRSER::Refinements; end
|
|
3
|
+
|
|
4
|
+
# Require all refinements
|
|
1
5
|
require_relative './refinements/object'
|
|
2
6
|
require_relative './refinements/string'
|
|
3
7
|
require_relative './refinements/array'
|
|
@@ -9,3 +13,4 @@ require_relative './refinements/set'
|
|
|
9
13
|
require_relative './refinements/open_struct'
|
|
10
14
|
require_relative './refinements/enumerator'
|
|
11
15
|
require_relative './refinements/symbol'
|
|
16
|
+
require_relative './refinements/types'
|
|
@@ -1,23 +1,11 @@
|
|
|
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
|
refine ::Array do
|
|
15
|
-
include NRSER::
|
|
16
|
-
include NRSER::
|
|
3
|
+
include NRSER::Ext::Enumerable
|
|
4
|
+
include NRSER::Ext::Tree
|
|
17
5
|
|
|
18
6
|
|
|
19
7
|
# @return [Array]
|
|
20
|
-
# new array consisting of all elements after the first (which may be
|
|
8
|
+
# new array consisting of all elements after the first (which may be
|
|
21
9
|
# none, resulting in an empty array).
|
|
22
10
|
#
|
|
23
11
|
def rest
|
|
@@ -124,7 +112,7 @@ module NRSER
|
|
|
124
112
|
# anything, especially something as core as `#to_proc` and `Array`.
|
|
125
113
|
#
|
|
126
114
|
# @return [Proc]
|
|
127
|
-
# Lambda proc that accepts a single argument and calls `#dig` with this
|
|
115
|
+
# Lambda proc that accepts a single argument and calls `#dig` with this
|
|
128
116
|
# array's contents as the `#dig` arguments.
|
|
129
117
|
#
|
|
130
118
|
def to_digger
|
|
@@ -136,4 +124,4 @@ module NRSER
|
|
|
136
124
|
|
|
137
125
|
|
|
138
126
|
end # refine ::Array
|
|
139
|
-
end # NRSER
|
|
127
|
+
end # NRSER
|