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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d0645f6178f68b0a105efa1bcf389bd3c0b1f056cd94a6c6684b0d18bc9284f8
4
- data.tar.gz: a93f3a7df8098fbb1e7bdb61b5ad36c29a67e4471e563c63bb562b7896cfa60d
3
+ metadata.gz: becfb749a93e73ea402265899e57d3deea45bf0eb457a29a66eafa03965b1572
4
+ data.tar.gz: 3f6578bd2f0b3334369834ff1f344b4b033318172586a9324496027a057507a0
5
5
  SHA512:
6
- metadata.gz: a5d02720dfa28fc5aefed2907008e14e76dc00fd087eb83eb6c89bbf8c976b0258410d554592fc1368938bfcda8e96efc99ae2a811f285dfba33b210bf795ba5
7
- data.tar.gz: e8077c6bd4ab3c5e363abeaa5154dca3bf8154140a73f75d238883cefe92855fb8da843ba46037c12ffb9bc710b9449b1d121a6e2119dc774520bd237f71d564
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.6', '< 0.1.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.define do
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.define(&block)` - In the block scope, all builder methods can be used without receiver
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 invalid as a pattern object
43
- def define(&block)
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 :DSLScope
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
- ANYTHING = ->_v { true }
260
- define_inspect_on(ANYTHING, name: 'ANYTHING', arguments: [])
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
- ANYTHING
266
+ EQQ_BUILTIN_ANYTHING
268
267
  end
269
268
 
270
- NEVER = ->_v { false }
271
- define_inspect_on(NEVER, name: 'NEVER', arguments: [])
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
- NEVER
276
+ EQQ_BUILTIN_NEVER
279
277
  end
280
278
 
281
- BOOLEAN = ->v { true.equal?(v) || false.equal?(v) }
282
- define_inspect_on(BOOLEAN, name: 'BOOLEAN', arguments: [])
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
- BOOLEAN
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
@@ -3,5 +3,5 @@
3
3
 
4
4
  module Eqq
5
5
  # This will be same as latest published gem version
6
- VERSION = '0.0.6'
6
+ VERSION = '0.0.7'
7
7
  end
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
- ANYTHING: product
20
+ EQQ_BUILTIN_ANYTHING: product
21
21
 
22
22
  # A private constant. Should not be used in your code.
23
- NEVER: product
23
+ EQQ_BUILTIN_NEVER: product
24
24
 
25
25
  # A private constant. Should not be used in your code.
26
- BOOLEAN: product
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eqq
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kenichi Kamiya