nrser 0.3.9 → 0.3.10

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 (141) hide show
  1. checksums.yaml +4 -4
  2. data/lib/nrser/char/alpha_numeric_sub.rb +9 -19
  3. data/lib/nrser/char/special.rb +5 -5
  4. data/lib/nrser/core_ext/array.rb +36 -13
  5. data/lib/nrser/core_ext/enumerable.rb +1 -0
  6. data/lib/nrser/core_ext/enumerable/find_map.rb +1 -1
  7. data/lib/nrser/core_ext/hash/bury.rb +3 -0
  8. data/lib/nrser/core_ext/hash/extract_values_at.rb +2 -2
  9. data/lib/nrser/core_ext/method/full_name.rb +1 -1
  10. data/lib/nrser/core_ext/module/method_objects.rb +1 -1
  11. data/lib/nrser/core_ext/module/source_locations.rb +27 -15
  12. data/lib/nrser/core_ext/object/lazy_var.rb +1 -1
  13. data/lib/nrser/core_ext/pathname.rb +67 -12
  14. data/lib/nrser/core_ext/pathname/subpath.rb +86 -0
  15. data/lib/nrser/core_ext/string.rb +28 -1
  16. data/lib/nrser/core_ext/symbol.rb +11 -12
  17. data/lib/nrser/errors/README.md +154 -0
  18. data/lib/nrser/errors/attr_error.rb +146 -53
  19. data/lib/nrser/errors/count_error.rb +61 -12
  20. data/lib/nrser/errors/nicer_error.rb +42 -71
  21. data/lib/nrser/errors/value_error.rb +53 -58
  22. data/lib/nrser/functions.rb +0 -2
  23. data/lib/nrser/functions/enumerable.rb +5 -17
  24. data/lib/nrser/functions/enumerable/associate.rb +14 -5
  25. data/lib/nrser/functions/enumerable/find_all_map.rb +1 -1
  26. data/lib/nrser/functions/enumerable/include_slice/array_include_slice.rb +1 -1
  27. data/lib/nrser/functions/hash/bury.rb +2 -12
  28. data/lib/nrser/functions/merge_by.rb +2 -2
  29. data/lib/nrser/functions/module/method_objects.rb +2 -2
  30. data/lib/nrser/functions/path.rb +185 -165
  31. data/lib/nrser/functions/path/normalized.rb +84 -0
  32. data/lib/nrser/functions/string.rb +4 -4
  33. data/lib/nrser/functions/text/README.md +4 -0
  34. data/lib/nrser/functions/text/format.rb +53 -0
  35. data/lib/nrser/functions/text/indentation.rb +6 -6
  36. data/lib/nrser/functions/text/word_wrap.rb +2 -2
  37. data/lib/nrser/functions/tree/map_leaves.rb +3 -3
  38. data/lib/nrser/functions/tree/map_tree.rb +2 -2
  39. data/lib/nrser/functions/tree/transform.rb +1 -18
  40. data/lib/nrser/gem_ext/README.md +4 -0
  41. data/lib/nrser/labs/README.md +8 -0
  42. data/lib/nrser/labs/config.rb +163 -0
  43. data/lib/nrser/labs/i8.rb +49 -159
  44. data/lib/nrser/labs/i8/struct.rb +167 -0
  45. data/lib/nrser/labs/i8/struct/hash.rb +140 -0
  46. data/lib/nrser/labs/i8/struct/vector.rb +149 -0
  47. data/lib/nrser/labs/i8/surjection.rb +211 -0
  48. data/lib/nrser/labs/lots/consumer.rb +19 -0
  49. data/lib/nrser/labs/lots/parser.rb +21 -1
  50. data/lib/nrser/labs/stash.rb +4 -4
  51. data/lib/nrser/log.rb +25 -21
  52. data/lib/nrser/log/appender/sync.rb +15 -11
  53. data/lib/nrser/log/formatters/color.rb +0 -3
  54. data/lib/nrser/log/formatters/mixin.rb +4 -4
  55. data/lib/nrser/log/logger.rb +54 -6
  56. data/lib/nrser/log/mixin.rb +2 -1
  57. data/lib/nrser/log/plugin.rb +6 -6
  58. data/lib/nrser/log/types.rb +46 -29
  59. data/lib/nrser/mean_streak.rb +0 -8
  60. data/lib/nrser/mean_streak/document.rb +1 -4
  61. data/lib/nrser/message.rb +3 -3
  62. data/lib/nrser/meta/README.md +4 -0
  63. data/lib/nrser/meta/lazy_attr.rb +2 -2
  64. data/lib/nrser/meta/source/location.rb +1 -1
  65. data/lib/nrser/props.rb +34 -3
  66. data/lib/nrser/props/class_methods.rb +2 -1
  67. data/lib/nrser/props/instance_methods.rb +9 -9
  68. data/lib/nrser/props/metadata.rb +4 -12
  69. data/lib/nrser/props/mutable/stash.rb +5 -2
  70. data/lib/nrser/props/prop.rb +10 -19
  71. data/lib/nrser/rspex.rb +1 -20
  72. data/lib/nrser/rspex/example_group/describe_attribute.rb +3 -0
  73. data/lib/nrser/rspex/example_group/describe_called_with.rb +9 -4
  74. data/lib/nrser/rspex/example_group/describe_case.rb +1 -0
  75. data/lib/nrser/rspex/example_group/describe_class.rb +2 -0
  76. data/lib/nrser/rspex/example_group/describe_group.rb +1 -1
  77. data/lib/nrser/rspex/example_group/describe_instance.rb +3 -1
  78. data/lib/nrser/rspex/example_group/describe_message.rb +1 -1
  79. data/lib/nrser/rspex/example_group/describe_method.rb +64 -30
  80. data/lib/nrser/rspex/example_group/describe_response_to.rb +1 -1
  81. data/lib/nrser/rspex/example_group/describe_section.rb +4 -1
  82. data/lib/nrser/rspex/example_group/describe_sent_to.rb +1 -1
  83. data/lib/nrser/rspex/example_group/describe_setup.rb +1 -0
  84. data/lib/nrser/rspex/example_group/describe_source_file.rb +1 -1
  85. data/lib/nrser/rspex/example_group/describe_spec_file.rb +4 -2
  86. data/lib/nrser/rspex/example_group/describe_when.rb +2 -1
  87. data/lib/nrser/rspex/example_group/describe_x.rb +5 -5
  88. data/lib/nrser/rspex/format.rb +0 -15
  89. data/lib/nrser/sugar/method_missing_forwarder.rb +3 -3
  90. data/lib/nrser/sys/env/path.rb +2 -28
  91. data/lib/nrser/types.rb +63 -12
  92. data/lib/nrser/types/README.md +76 -0
  93. data/lib/nrser/types/arrays.rb +192 -137
  94. data/lib/nrser/types/attributes.rb +269 -0
  95. data/lib/nrser/types/booleans.rb +134 -83
  96. data/lib/nrser/types/bounded.rb +110 -47
  97. data/lib/nrser/types/collections.rb +119 -0
  98. data/lib/nrser/types/combinators.rb +283 -196
  99. data/lib/nrser/types/doc/display_table.md +66 -0
  100. data/lib/nrser/types/eqiuvalent.rb +91 -0
  101. data/lib/nrser/types/errors/check_error.rb +5 -11
  102. data/lib/nrser/types/errors/from_string_error.rb +3 -3
  103. data/lib/nrser/types/factory.rb +287 -20
  104. data/lib/nrser/types/hashes.rb +227 -179
  105. data/lib/nrser/types/in.rb +73 -36
  106. data/lib/nrser/types/is.rb +67 -60
  107. data/lib/nrser/types/is_a.rb +141 -84
  108. data/lib/nrser/types/labels.rb +45 -16
  109. data/lib/nrser/types/maybe.rb +6 -3
  110. data/lib/nrser/types/nil.rb +64 -27
  111. data/lib/nrser/types/not.rb +92 -34
  112. data/lib/nrser/types/numbers.rb +224 -169
  113. data/lib/nrser/types/pairs.rb +113 -89
  114. data/lib/nrser/types/paths.rb +250 -137
  115. data/lib/nrser/types/responds.rb +167 -89
  116. data/lib/nrser/types/selector.rb +234 -0
  117. data/lib/nrser/types/shape.rb +136 -65
  118. data/lib/nrser/types/strings.rb +189 -63
  119. data/lib/nrser/types/symbols.rb +83 -33
  120. data/lib/nrser/types/top.rb +89 -0
  121. data/lib/nrser/types/tuples.rb +134 -98
  122. data/lib/nrser/types/type.rb +617 -505
  123. data/lib/nrser/types/when.rb +123 -98
  124. data/lib/nrser/types/where.rb +182 -91
  125. data/lib/nrser/version.rb +1 -1
  126. data/spec/lib/nrser/core_ext/pathname/subpath_spec.rb +22 -0
  127. data/spec/lib/nrser/errors/attr_error_spec.rb +68 -0
  128. data/spec/lib/nrser/errors/count_error_spec.rb +69 -0
  129. data/spec/lib/nrser/functions/path/normalize_path_spec.rb +35 -0
  130. data/spec/lib/nrser/functions/tree/map_tree_spec.rb +74 -96
  131. data/spec/lib/nrser/functions/tree/transform_spec.rb +11 -11
  132. data/spec/lib/nrser/labs/config_spec.rb +22 -0
  133. data/spec/lib/nrser/labs/i8/struct_spec.rb +39 -0
  134. data/spec/lib/nrser/types/display_spec.rb +50 -0
  135. data/spec/lib/nrser/types/paths_spec.rb +16 -10
  136. data/spec/lib/nrser/types/selector_spec.rb +125 -0
  137. data/spec/spec_helper.rb +4 -5
  138. metadata +105 -22
  139. data/lib/nrser/types/any.rb +0 -41
  140. data/lib/nrser/types/attrs.rb +0 -213
  141. data/lib/nrser/types/trees.rb +0 -42
@@ -1,36 +1,86 @@
1
+ # encoding: UTF-8
2
+ # frozen_string_literal: true
3
+
4
+ # Requirements
5
+ # =======================================================================
6
+
7
+ # Project / Package
8
+ # -----------------------------------------------------------------------
9
+
1
10
  require_relative './is'
2
11
  require_relative './is_a'
3
12
 
4
- module NRSER::Types
5
-
6
- def_factory(
7
- :Symbol,
8
- aliases: [ :sym, :symbol ],
9
- ) do |from_s: :to_sym.to_proc, **options|
10
- is_a \
11
- ::Symbol,
12
- from_s: from_s,
13
- **options
14
- end # sym
15
-
16
-
17
- def_factory(
18
- :EmptySymbol,
19
- aliases: [ :empty_sym, :empty_symbol ],
20
- ) do |name: 'EmptySymbol', **options|
21
- is :'', name: name, **options
22
- end
23
-
24
-
25
- def_factory(
26
- :NonEmptySymbol,
27
- aliases: [ :non_empty_sym, :non_empty_symbol ],
28
- ) do |name: 'NonEmptySymbol', **options|
29
- intersection \
30
- sym,
31
- self.not( empty_sym ),
32
- name: name,
33
- **options
34
- end
35
-
36
- end # NRSER::Types
13
+
14
+ # Namespace
15
+ # ========================================================================
16
+
17
+ module NRSER
18
+ module Types
19
+
20
+
21
+ # Definitions
22
+ # ========================================================================
23
+
24
+ # @!group Symbol Type Factories
25
+ # ----------------------------------------------------------------------------
26
+
27
+ #@!method self.Symbol **options
28
+ # {Symbol} instances. Load from strings as you would expect {::String#to_sym}.
29
+ #
30
+ # @param [Hash] options
31
+ # Passed to {Type#initialize}.
32
+ #
33
+ # @return [Type]
34
+ #
35
+ def_type :Symbol,
36
+ aliases: [ :sym ],
37
+ from_s: :to_sym.to_proc,
38
+ &->( **options ) do
39
+ self.IsA ::Symbol, **options
40
+ end # .Symbol
41
+
42
+
43
+ #@!method self.EmptySymbol **options
44
+ # Exactly `:''`.
45
+ #
46
+ # Pretty much just exists for use in {.NonEmptySymbol}, which pretty much
47
+ # just exists for use in {.Label}, which actually has some use ;)
48
+ #
49
+ # @param [Hash] options
50
+ # Passed to {Type#initialize}.
51
+ #
52
+ # @return [Type]
53
+ #
54
+ def_type :EmptySymbol,
55
+ aliases: [ :empty_sym ],
56
+ from_s: :to_sym.to_proc,
57
+ &->( **options ) do
58
+ self.Is :'', **options
59
+ end # .EmptySymbol
60
+
61
+
62
+ #@!method self.NonEmptySymbol **options
63
+ # A {Symbol} that is *not* `:''`.
64
+ #
65
+ # @param [Hash] options
66
+ # Passed to {Type#initialize}.
67
+ #
68
+ # @return [Type]
69
+ #
70
+ def_type :NonEmptySymbol,
71
+ aliases: [ :non_empty_sym ],
72
+ &->( **options ) do
73
+ self.Intersection \
74
+ self.Symbol,
75
+ ~self.EmptySymbol,
76
+ **options
77
+ end # .NonEmptySymbol
78
+
79
+ # @!endgroup Symbol Type Factories # *****************************************
80
+
81
+
82
+ # /Namespace
83
+ # ========================================================================
84
+
85
+ end # module Types
86
+ end # module NRSER
@@ -0,0 +1,89 @@
1
+ # encoding: UTF-8
2
+ # frozen_string_literal: true
3
+
4
+
5
+ # Requirements
6
+ # ========================================================================
7
+
8
+ # Project / Package
9
+ # ------------------------------------------------------------------------
10
+
11
+ require_relative './type'
12
+
13
+
14
+ # Namespace
15
+ # ========================================================================
16
+
17
+ module NRSER
18
+ module Types
19
+
20
+
21
+ # Definitions
22
+ # ========================================================================
23
+
24
+ # The top type is the universal type - all values are members.
25
+ #
26
+ # @see https://en.wikipedia.org/wiki/Top_type
27
+ #
28
+ class Top < NRSER::Types::Type
29
+ NAME = '*'
30
+
31
+ def initialize
32
+ super name: NAME
33
+ end
34
+
35
+ def test? value
36
+ true
37
+ end
38
+
39
+ def explain
40
+ 'Top'
41
+ end
42
+
43
+ def symbolic
44
+ '*' # '⊤'
45
+ end
46
+
47
+ def has_from_s?
48
+ true
49
+ end
50
+
51
+ def from_s string
52
+ string
53
+ end
54
+
55
+
56
+ # {AnyType} instances are all equal.
57
+ #
58
+ # @note
59
+ # `other`'s class must be {AnyType} exactly - we make no assumptions
60
+ # about anything that has subclasses {AnyType}.
61
+ #
62
+ # @param [*] other
63
+ # Object to compare to.
64
+ #
65
+ # @return [Boolean]
66
+ # `true` if `other#class` equals {AnyType}.
67
+ #
68
+ def == other
69
+ other.class == Top
70
+ end
71
+
72
+ end # class Top
73
+
74
+ # Anything at all...
75
+ #
76
+ def_type(
77
+ :Top,
78
+ aliases: [ :everything, :all, :any ],
79
+ ) do
80
+ # Top type gets used as a default a lot, so cache it...
81
+ @_top_type_instance ||= Top.new
82
+ end
83
+
84
+
85
+ # /Namespace
86
+ # ========================================================================
87
+
88
+ end # module Types
89
+ end # module NRSER
@@ -1,3 +1,7 @@
1
+ # encoding: UTF-8
2
+ # frozen_string_literal: true
3
+
4
+
1
5
  # Requirements
2
6
  # =======================================================================
3
7
 
@@ -6,112 +10,144 @@
6
10
  require_relative './arrays'
7
11
 
8
12
 
13
+
14
+ # Namespace
15
+ # ========================================================================
16
+
17
+ module NRSER
18
+ module Types
19
+
20
+
9
21
  # Definitions
10
- # =======================================================================
22
+ # ========================================================================
11
23
 
12
- module NRSER::Types
24
+ # Tuple type - array of fixed length and types (though those could be
25
+ # {.Top}).
26
+ #
27
+ # @note
28
+ # Construct {Tuple} types using the {.Tuple} factory.
29
+ #
30
+ class Tuple < ArrayType
13
31
 
14
- # Tuple type - array of fixed length and types (though those could be
15
- # {NRSER::Types.any}).
32
+ # Attributes
33
+ # ======================================================================
34
+
35
+ # The types of each of the tuple indexes.
16
36
  #
17
- class TupleType < NRSER::Types::ArrayType
18
-
19
- # Attributes
20
- # ======================================================================
21
-
22
- # The types of each of the tuple indexes.
23
- #
24
- # @return [Array<NRSER::Types::Type>]
25
- #
26
- attr_reader :types
27
-
28
-
29
- # Constructor
30
- # ======================================================================
31
-
32
- # Instantiate a new `TupleType`.
33
- #
34
- # @param [Array] *types
35
- # Tuple value types by their index in the tuples.
36
- #
37
- # Entries are passed through {NRSER::Types.make} to create the type
38
- # if needed.
39
- #
40
- # @param [Hash<Symbol, *>] **options
41
- # Type options; see {NRSER::Types::Type#initialize}.
42
- #
43
- def initialize *types, **options
44
- super **options
45
- @types = types.map( &NRSER::Types.method(:make) ).freeze
46
- end # #initialize
47
-
48
-
49
- # @return [String]
50
- # See {NRSER::Types::Type#explain}
51
- #
52
- def explain
53
- 'Array<(' + @types.map( &:explain ).join( ', ' ) + ')>'
54
- end
55
-
56
-
57
- # Instance Methods
58
- # ======================================================================
59
-
60
- # Test value for membership.
61
- #
62
- # @param (see NRSER::Types::Type#test?)
63
- # @return (see NRSER::Types::Type#test?)
64
- # @raise (see NRSER::Types::Type#test?)
65
- #
66
- def test? value
67
- # Test the super class first
68
- return false unless super( value )
69
-
70
- # If it's not the right length then it doesn't pass
71
- return false unless value.length == @types.length
72
-
73
- # Test each item type
74
- @types.each_with_index.all? { |type, index|
75
- type.test value[index]
76
- }
77
- end # #test?
78
-
79
-
80
- # @return [Boolean]
81
- # `true` if this type can load values from a string, which is true if
82
- # *all* it's types can load values from strings.
83
- #
84
- def has_from_s?
85
- @from_s || @types.all?( &:has_from_s? )
86
- end # #has_from_s?
87
-
37
+ # @return [Array<Type>]
38
+ #
39
+ attr_reader :types
40
+
41
+
42
+ # Constructor
43
+ # ======================================================================
44
+
45
+ # Instantiate a new `Tuple`.
46
+ #
47
+ # @param [Array] types
48
+ # Tuple value types by their index in the tuples.
49
+ #
50
+ # Entries are passed through {NRSER::Types.make} to create the type
51
+ # if needed.
52
+ #
53
+ # @param [Hash<Symbol, *>] options
54
+ # Type options; see {Type#initialize}.
55
+ #
56
+ def initialize *types, **options
57
+ super **options
58
+ @types = types.map( &NRSER::Types.method(:make) ).freeze
59
+ end # #initialize
60
+
61
+
62
+ def default_name
63
+ 'Array<(' + types.map( &:name ).join( ', ' ) + ')>'
64
+ end
65
+
66
+
67
+ def default_symbolic
68
+ '[' + types.map( &:symbolic ).join( ', ' ) + ']'
69
+ end
70
+
71
+
72
+ # @return [String]
73
+ # See {Type#explain}
74
+ #
75
+ def explain
76
+ 'Array<(' + types.map( &:explain ).join( ', ' ) + ')>'
77
+ end
78
+
79
+
80
+ # Instance Methods
81
+ # ======================================================================
82
+
83
+ # Test value for membership.
84
+ #
85
+ # @param (see Type#test?)
86
+ # @return (see Type#test?)
87
+ # @raise (see Type#test?)
88
+ #
89
+ def test? value
90
+ # Test the super class first
91
+ return false unless super( value )
88
92
 
89
- # Load each value in an array of strings split out by
90
- # {NRSER::Types::ArrayType#from_s} by passing each value to `#from_s` in
91
- # the type of the corresponding index.
92
- #
93
- # @param [Array<String>] strings
94
- #
95
- # @return [Array]
96
- #
97
- def items_from_strings strings
98
- @types.each_with_index.map { |type, index|
99
- type.from_s strings[index]
100
- }
101
- end
93
+ # If it's not the right length then it doesn't pass
94
+ return false unless value.length == types.length
102
95
 
103
- end # class TupleType
96
+ # Test each item type
97
+ types.each_with_index.all? { |type, index|
98
+ type.test value[index]
99
+ }
100
+ end # #test?
104
101
 
105
-
106
- # Get a tuple type.
102
+
103
+ # @return [Boolean]
104
+ # `true` if this type can load values from a string, which is true if
105
+ # *all* it's types can load values from strings.
106
+ #
107
+ def has_from_s?
108
+ @from_s || types.all?( &:has_from_s? )
109
+ end # #has_from_s?
110
+
111
+
112
+ # Load each value in an array of strings split out by
113
+ # {ArrayType#from_s} by passing each value to `#from_s` in
114
+ # the type of the corresponding index.
107
115
  #
108
- # @param *types (see TupleType#initialize)
109
- # @param **options (see TupleType#initialize)
116
+ # @param [Array<String>] strings
110
117
  #
111
- # @return [NRSER::Types::Type]
118
+ # @return [Array]
112
119
  #
113
- def_factory :tuple do |*types, **options|
114
- TupleType.new *types, **options
115
- end # .tuple
120
+ def items_from_strings strings
121
+ types.each_with_index.map { |type, index|
122
+ type.from_s strings[index]
123
+ }
124
+ end
116
125
 
117
- end # module NRSER::Types
126
+ end # class Tuple
127
+
128
+
129
+ #@!method self.Tuple *types, **options
130
+ # Get a {Tuple} type.
131
+ #
132
+ # @param [Array<TYPE>] types
133
+ # The types of the tuple values, in order they will appear. If entries are
134
+ # not {Type} instances, they will be {.make} into them.
135
+ #
136
+ # @param [Hash] options
137
+ # Passed to {Type#initialize}.
138
+ #
139
+ # @return [Tuple]
140
+ #
141
+ def_type :Tuple,
142
+ default_name: false,
143
+ parameterize: :types,
144
+ &->( *types, **options ) do
145
+ Tuple.new *types, **options
146
+ end # .Tuple
147
+
148
+
149
+ # /Namespace
150
+ # ========================================================================
151
+
152
+ end # module Types
153
+ end # module NRSER