eqq 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -3
- data/lib/eqq.rb +13 -6
- data/lib/eqq/buildable.rb +21 -12
- data/lib/eqq/version.rb +1 -1
- data/sig/eqq.rbs +12 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: becfb749a93e73ea402265899e57d3deea45bf0eb457a29a66eafa03965b1572
|
4
|
+
data.tar.gz: 3f6578bd2f0b3334369834ff1f344b4b033318172586a9324496027a057507a0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3d76a45da1f1e181d77b6f9cbfc6f80d88af6abed0782b1da92f6562934bf551c2f55e5691be7108d0acf0521562a042bb5cba6f54f9846af78b7ba4031d35fb
|
7
|
+
data.tar.gz: 2ec4137407dfaf6b4189255532e59669798ac9ed57be8e6ecdb07c31525d132b9246da9d9fd6b98975e31b712e002e2693f523acf285d172df1b13c7c46617d5
|
data/README.md
CHANGED
@@ -12,7 +12,7 @@ Require Ruby 2.6 or later
|
|
12
12
|
Add below code into your Gemfile
|
13
13
|
|
14
14
|
```ruby
|
15
|
-
gem 'eqq', '>= 0.0.
|
15
|
+
gem 'eqq', '>= 0.0.7', '< 0.1.0'
|
16
16
|
```
|
17
17
|
|
18
18
|
### Overview
|
@@ -24,7 +24,7 @@ require 'eqq'
|
|
24
24
|
[42, nil, true, false, '', 0].grep(Eqq.BOOLEAN) #=> [true, false]
|
25
25
|
[42, [], {}, 'string', Object.new, nil].grep(Eqq.CAN(:to_h)) #=> [[], {}, nil]
|
26
26
|
|
27
|
-
pattern = Eqq.
|
27
|
+
pattern = Eqq.build do
|
28
28
|
OR(AND(Float, 20..50), Integer)
|
29
29
|
end
|
30
30
|
|
@@ -107,6 +107,7 @@ Reuse as you wish!
|
|
107
107
|
* SAME(object) - Product returns `true` when matched with `#equal?`
|
108
108
|
* SEND(name, pattern) - Basically provided for Enumerable
|
109
109
|
* BOOLEAN() - Product returns `true` when matched to `true` or `false`
|
110
|
+
* NIL() - Product returns `true` when matched to `nil` (Not consider `nil?`)
|
110
111
|
* ANYTHING() - Product returns `true`, always `true`
|
111
112
|
* NEVER() - Product returns `false`, always `false`
|
112
113
|
* XOR(pattern1, pattern2) - Product returns `true` when matched one of the pattern, when matched both returns `false`
|
@@ -137,7 +138,7 @@ end
|
|
137
138
|
|
138
139
|
When you felt annoy to write `Eqq` in many place, some ways exist.
|
139
140
|
|
140
|
-
* `Eqq.
|
141
|
+
* `Eqq.build(&block)` - In the block scope, all builder methods can be used without receiver
|
141
142
|
* `extend Eqq::Buildable` - In the class/module, all builders can be used as class methods
|
142
143
|
* `include Eqq::Buildable` - In the class/module, all builders can be used as instance methods
|
143
144
|
|
data/lib/eqq.rb
CHANGED
@@ -35,17 +35,24 @@ module Eqq
|
|
35
35
|
|
36
36
|
# @api private
|
37
37
|
def satisfy?(object)
|
38
|
-
(Proc === object) && object.lambda? && (object.arity == 1)
|
38
|
+
(Proc === object) && object.lambda? && (object.arity == 1) && object.respond_to?(:inspect)
|
39
39
|
end
|
40
40
|
|
41
|
-
# @return [
|
42
|
-
# @raise [InvalidProductError] if the return value is
|
43
|
-
def
|
41
|
+
# @return [Proc]
|
42
|
+
# @raise [InvalidProductError] if the return value is not looks to be built with builders
|
43
|
+
def build(&block)
|
44
|
+
raise ArgumentError, 'might be mis used the `Eqq.build` in your code' unless block
|
45
|
+
|
44
46
|
pattern = DSLScope.new.instance_exec(&block)
|
45
|
-
raise InvalidProductError unless satisfy?(pattern)
|
47
|
+
raise InvalidProductError, 'might be mis used the `Eqq.build` in your code' unless satisfy?(pattern)
|
46
48
|
|
47
49
|
pattern
|
48
50
|
end
|
51
|
+
|
52
|
+
# @deprecated Use {build} instead. This will be dropped since `0.1.0`
|
53
|
+
def define(&block)
|
54
|
+
build(&block)
|
55
|
+
end
|
49
56
|
end
|
50
57
|
end
|
51
58
|
|
@@ -57,5 +64,5 @@ module Eqq
|
|
57
64
|
class DSLScope
|
58
65
|
include Buildable
|
59
66
|
end
|
60
|
-
private_constant
|
67
|
+
private_constant(:DSLScope)
|
61
68
|
end
|
data/lib/eqq/buildable.rb
CHANGED
@@ -256,37 +256,46 @@ module Eqq
|
|
256
256
|
product
|
257
257
|
end
|
258
258
|
|
259
|
-
|
260
|
-
define_inspect_on(
|
261
|
-
private_constant :ANYTHING
|
259
|
+
EQQ_BUILTIN_ANYTHING = ->_v { true }
|
260
|
+
define_inspect_on(EQQ_BUILTIN_ANYTHING, name: 'ANYTHING', arguments: [])
|
262
261
|
|
263
262
|
# Product returns `true`, always `true`
|
264
263
|
#
|
265
264
|
# @return [Proc]
|
266
265
|
def ANYTHING
|
267
|
-
|
266
|
+
EQQ_BUILTIN_ANYTHING
|
268
267
|
end
|
269
268
|
|
270
|
-
|
271
|
-
define_inspect_on(
|
272
|
-
private_constant :NEVER
|
269
|
+
EQQ_BUILTIN_NEVER = ->_v { false }
|
270
|
+
define_inspect_on(EQQ_BUILTIN_NEVER, name: 'NEVER', arguments: [])
|
273
271
|
|
274
272
|
# Product returns `false`, always `false`
|
275
273
|
#
|
276
274
|
# @return [Proc]
|
277
275
|
def NEVER
|
278
|
-
|
276
|
+
EQQ_BUILTIN_NEVER
|
279
277
|
end
|
280
278
|
|
281
|
-
|
282
|
-
define_inspect_on(
|
283
|
-
private_constant :BOOLEAN
|
279
|
+
EQQ_BUILTIN_BOOLEAN = ->v { true.equal?(v) || false.equal?(v) }
|
280
|
+
define_inspect_on(EQQ_BUILTIN_BOOLEAN, name: 'BOOLEAN', arguments: [])
|
284
281
|
|
285
282
|
# Product returns `true` when matched to `true` or `false`
|
286
283
|
#
|
287
284
|
# @return [Proc]
|
288
285
|
def BOOLEAN
|
289
|
-
|
286
|
+
EQQ_BUILTIN_BOOLEAN
|
290
287
|
end
|
288
|
+
|
289
|
+
EQQ_BUILTIN_NIL = ->v { nil.equal?(v) }
|
290
|
+
define_inspect_on(EQQ_BUILTIN_NIL, name: 'NIL', arguments: [])
|
291
|
+
|
292
|
+
# Product returns `true` when matched to `nil` (Not consider `nil?`)
|
293
|
+
#
|
294
|
+
# @return [Proc]
|
295
|
+
def NIL
|
296
|
+
EQQ_BUILTIN_NIL
|
297
|
+
end
|
298
|
+
|
299
|
+
private_constant(:EQQ_BUILTIN_ANYTHING, :EQQ_BUILTIN_NEVER, :EQQ_BUILTIN_BOOLEAN, :EQQ_BUILTIN_NIL)
|
291
300
|
end
|
292
301
|
end
|
data/lib/eqq/version.rb
CHANGED
data/sig/eqq.rbs
CHANGED
@@ -17,13 +17,16 @@ module Eqq
|
|
17
17
|
type product = patternable_lambda & _Inspectable
|
18
18
|
|
19
19
|
# A private constant. Should not be used in your code.
|
20
|
-
|
20
|
+
EQQ_BUILTIN_ANYTHING: product
|
21
21
|
|
22
22
|
# A private constant. Should not be used in your code.
|
23
|
-
|
23
|
+
EQQ_BUILTIN_NEVER: product
|
24
24
|
|
25
25
|
# A private constant. Should not be used in your code.
|
26
|
-
|
26
|
+
EQQ_BUILTIN_BOOLEAN: product
|
27
|
+
|
28
|
+
# A private constant. Should not be used in your code.
|
29
|
+
EQQ_BUILTIN_NIL: product
|
27
30
|
|
28
31
|
# A private API. Should not be used in your code.
|
29
32
|
def self.safe_inspect_for: (untyped object)-> String
|
@@ -78,6 +81,9 @@ module Eqq
|
|
78
81
|
|
79
82
|
# Product returns `true` when matched to `true` or `false`
|
80
83
|
def BOOLEAN: () -> product
|
84
|
+
|
85
|
+
# Product returns `true` when matched to `nil` (Not consider `nil?`)
|
86
|
+
def NIL: () -> product
|
81
87
|
end
|
82
88
|
|
83
89
|
extend Buildable
|
@@ -108,5 +114,8 @@ module Eqq
|
|
108
114
|
def self.satisfy?: (untyped object) -> bool
|
109
115
|
|
110
116
|
# In the block scope, all builder methods can be used without receiver
|
117
|
+
def self.build: { () -> _Patternable } -> _Patternable
|
118
|
+
|
119
|
+
# Alias of `build`. But deperecated. Do not use in your code anymore.
|
111
120
|
def self.define: { () -> _Patternable } -> _Patternable
|
112
121
|
end
|