eqq 0.0.5 → 0.0.6
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/README.md +28 -5
- data/lib/eqq.rb +12 -2
- data/lib/eqq/buildable.rb +1 -1
- data/lib/eqq/version.rb +1 -1
- data/sig/eqq.rbs +7 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d0645f6178f68b0a105efa1bcf389bd3c0b1f056cd94a6c6684b0d18bc9284f8
|
4
|
+
data.tar.gz: a93f3a7df8098fbb1e7bdb61b5ad36c29a67e4471e563c63bb562b7896cfa60d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a5d02720dfa28fc5aefed2907008e14e76dc00fd087eb83eb6c89bbf8c976b0258410d554592fc1368938bfcda8e96efc99ae2a811f285dfba33b210bf795ba5
|
7
|
+
data.tar.gz: e8077c6bd4ab3c5e363abeaa5154dca3bf8154140a73f75d238883cefe92855fb8da843ba46037c12ffb9bc710b9449b1d121a6e2119dc774520bd237f71d564
|
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.6', '< 0.1.0'
|
16
16
|
```
|
17
17
|
|
18
18
|
### Overview
|
@@ -113,14 +113,37 @@ Reuse as you wish!
|
|
113
113
|
* NAND(*patterns) - Product is an inverted `AND`
|
114
114
|
* NOR(*patterns) - Product is an inverted `OR`
|
115
115
|
|
116
|
-
###
|
116
|
+
### Best fit for RSpec's `satisfy` matcher too
|
117
117
|
|
118
|
-
|
118
|
+
All builders actually generate a `Proc (lambda)` instance.
|
119
|
+
The signature will fit for RSpec's built-in [`satisfy` matcher](https://relishapp.com/rspec/rspec-expectations/v/3-10/docs/built-in-matchers/satisfy-matcher) too.
|
120
|
+
|
121
|
+
```ruby
|
122
|
+
RSpec.describe RSpec::Matchers::BuiltIn::Satisfy do
|
123
|
+
let(:product) { Eqq.AND(Integer, 24..42) }
|
124
|
+
|
125
|
+
it 'perfectly works' do
|
126
|
+
expect(23).not_to satisfy(&product)
|
127
|
+
expect(24).to satisfy(&product)
|
128
|
+
expect(24.0).not_to satisfy(&product)
|
129
|
+
expect(42).to satisfy(&product)
|
130
|
+
expect(42.0).not_to satisfy(&product)
|
131
|
+
expect(43).not_to satisfy(&product)
|
132
|
+
end
|
133
|
+
end
|
134
|
+
```
|
135
|
+
|
136
|
+
### Use builders without receiver specifying
|
137
|
+
|
138
|
+
When you felt annoy to write `Eqq` in many place, some ways exist.
|
119
139
|
|
120
140
|
* `Eqq.define(&block)` - In the block scope, all builder methods can be used without receiver
|
121
|
-
* `
|
141
|
+
* `extend Eqq::Buildable` - In the class/module, all builders can be used as class methods
|
142
|
+
* `include Eqq::Buildable` - In the class/module, all builders can be used as instance methods
|
143
|
+
|
144
|
+
### Signature
|
122
145
|
|
123
|
-
This gem provides [ruby/rbs](https://github.com/ruby/rbs)
|
146
|
+
* This gem provides [ruby/rbs](https://github.com/ruby/rbs) signature file
|
124
147
|
|
125
148
|
## Links
|
126
149
|
|
data/lib/eqq.rb
CHANGED
@@ -15,7 +15,7 @@ module Eqq
|
|
15
15
|
class InvalidProductError < Error; end
|
16
16
|
|
17
17
|
class << self
|
18
|
-
def
|
18
|
+
def pattern?(object)
|
19
19
|
case object
|
20
20
|
when Proc, Method
|
21
21
|
object.arity == 1
|
@@ -28,11 +28,21 @@ module Eqq
|
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
|
+
# @deprecated Use {pattern?} instead. This will be dropped since `0.1.0`
|
32
|
+
def valid?(object)
|
33
|
+
pattern?(object)
|
34
|
+
end
|
35
|
+
|
36
|
+
# @api private
|
37
|
+
def satisfy?(object)
|
38
|
+
(Proc === object) && object.lambda? && (object.arity == 1)
|
39
|
+
end
|
40
|
+
|
31
41
|
# @return [#===]
|
32
42
|
# @raise [InvalidProductError] if the return value is invalid as a pattern object
|
33
43
|
def define(&block)
|
34
44
|
pattern = DSLScope.new.instance_exec(&block)
|
35
|
-
raise InvalidProductError unless
|
45
|
+
raise InvalidProductError unless satisfy?(pattern)
|
36
46
|
|
37
47
|
pattern
|
38
48
|
end
|
data/lib/eqq/buildable.rb
CHANGED
@@ -38,7 +38,7 @@ module Eqq
|
|
38
38
|
# @api private
|
39
39
|
# @return [void]
|
40
40
|
def validate_patterns(*patterns)
|
41
|
-
invalids = patterns.reject { |pattern| Eqq.
|
41
|
+
invalids = patterns.reject { |pattern| Eqq.pattern?(pattern) }
|
42
42
|
invalid_inspections = invalids.map { |invalid| safe_inspect_for(invalid) }.join(', ')
|
43
43
|
raise ArgumentError, "given `#{invalid_inspections}` are invalid as pattern objects" unless invalids.empty?
|
44
44
|
end
|
data/lib/eqq/version.rb
CHANGED
data/sig/eqq.rbs
CHANGED
@@ -98,8 +98,15 @@ module Eqq
|
|
98
98
|
VERSION: String
|
99
99
|
|
100
100
|
# Returns `true` when given object has patternable signature
|
101
|
+
def self.pattern?: (untyped object) -> bool
|
102
|
+
|
103
|
+
# Alias of `pattern?`. But deperecated. Do not use in your code anymore.
|
101
104
|
def self.valid?: (untyped object) -> bool
|
102
105
|
|
106
|
+
# Returns `true` when given object has correct signature as a product of builders
|
107
|
+
# Basically this is a private API. Should not be used in your code.
|
108
|
+
def self.satisfy?: (untyped object) -> bool
|
109
|
+
|
103
110
|
# In the block scope, all builder methods can be used without receiver
|
104
111
|
def self.define: { () -> _Patternable } -> _Patternable
|
105
112
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eqq
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kenichi Kamiya
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-06-
|
11
|
+
date: 2021-06-06 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |2
|
14
14
|
Pattern objects builder.
|