dry-logic 1.0.7 → 1.0.8

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: 828bea190b3733a29b940d0fa6bbb1270bb12ee6bbbef77d1ce6bbfd7ff11a27
4
- data.tar.gz: 319087e0aa57490d3a0bbff76efd6b01119a55135de7dbe0829d64cfee604d82
3
+ metadata.gz: 18fd19e7ba009817c12de16b828fb0e1dd04f1e5d2305fa9eeb8be9a55681473
4
+ data.tar.gz: a4f2ff3297ab4684323489bd0a371f759b1b99d0a5c5f5425a3158f4d8af45e7
5
5
  SHA512:
6
- metadata.gz: 5e3d3d3d7c486aec5e4c01ebc15f90ba485dfe4d10086c11a732ea3ffac5749de02b4ecc0fb0beafe8bcc593fa07286c1c8c30f2973baaf70598a3f212e949eb
7
- data.tar.gz: beb0445b376e9e8f545615d69af4c7cc1ad76db1ac55de9bd54784d8ff914165afec81ce174843efac5cffeda8bba494bca9e686d75052f00dee87abbfef03b3
6
+ metadata.gz: c57af697d43afe951a6cfdce3a9afd2ce12399b95e6d48f9468c84a2de33299d8a20b8f1851652a86cb922868974b2be80f434d38c8086022db42d9baa7df5dc
7
+ data.tar.gz: a33e8cfcec95668d7189ac1921bce8c88602dd25fea59f10174cef42ff7130cd9bb4285884d4c241eeb98fcd842a5268078c14649851e1b24fc20a56633fcd43
@@ -1,3 +1,13 @@
1
+ ## unreleased
2
+
3
+
4
+ ### Fixed
5
+
6
+ - Better Ruby 3 support with fixed specialization for rules of negative arity (@flash-gordon)
7
+
8
+
9
+ [Compare v1.0.7...master](https://github.com/dry-rb/dry-logic/compare/v1.0.7...master)
10
+
1
11
  ## 1.0.7 2020-08-13
2
12
 
3
13
 
@@ -4,6 +4,8 @@ module Dry
4
4
  module Logic
5
5
  class Rule
6
6
  class Interface < ::Module
7
+ SPLAT = ["*rest"].freeze
8
+
7
9
  attr_reader :arity
8
10
 
9
11
  attr_reader :curried
@@ -18,12 +20,10 @@ module Dry
18
20
 
19
21
  define_constructor if curried?
20
22
 
21
- if variable_arity?
22
- define_splat_application
23
- elsif constant?
23
+ if constant?
24
24
  define_constant_application
25
25
  else
26
- define_fixed_application
26
+ define_application
27
27
  end
28
28
  end
29
29
 
@@ -32,7 +32,7 @@ module Dry
32
32
  end
33
33
 
34
34
  def variable_arity?
35
- arity.equal?(-1)
35
+ arity.negative?
36
36
  end
37
37
 
38
38
  def curried?
@@ -41,7 +41,13 @@ module Dry
41
41
 
42
42
  def unapplied
43
43
  if variable_arity?
44
- -1
44
+ unapplied = arity.abs - 1 - curried
45
+
46
+ if unapplied.negative?
47
+ 0
48
+ else
49
+ unapplied
50
+ end
45
51
  else
46
52
  arity - curried
47
53
  end
@@ -51,8 +57,19 @@ module Dry
51
57
  if constant?
52
58
  "Constant"
53
59
  else
54
- arity_str = variable_arity? ? "VariableArity" : "#{arity}Arity"
55
- curried_str = curried? ? "#{curried}Curried" : EMPTY_STRING
60
+ arity_str =
61
+ if variable_arity?
62
+ "Variable#{arity.abs - 1}Arity"
63
+ else
64
+ "#{arity}Arity"
65
+ end
66
+
67
+ curried_str =
68
+ if curried?
69
+ "#{curried}Curried"
70
+ else
71
+ EMPTY_STRING
72
+ end
56
73
 
57
74
  "#{arity_str}#{curried_str}"
58
75
  end
@@ -91,32 +108,10 @@ module Dry
91
108
  end
92
109
  end
93
110
 
94
- def define_splat_application
95
- application =
96
- if curried?
97
- "@predicate[#{curried_args.join(", ")}, *input]"
98
- else
99
- "@predicate[*input]"
100
- end
101
-
102
- module_eval(<<~RUBY, __FILE__, __LINE__ + 1)
103
- def call(*input)
104
- if #{application}
105
- Result::SUCCESS
106
- else
107
- Result.new(false, id) { ast(*input) }
108
- end
109
- end
110
-
111
- def [](*input)
112
- #{application}
113
- end
114
- RUBY
115
- end
116
-
117
- def define_fixed_application
118
- parameters = unapplied_args.join(", ")
119
- application = "@predicate[#{(curried_args + unapplied_args).join(", ")}]"
111
+ def define_application
112
+ splat = variable_arity? ? SPLAT : EMPTY_ARRAY
113
+ parameters = (unapplied_args + splat).join(", ")
114
+ application = "@predicate[#{(curried_args + unapplied_args + splat).join(", ")}]"
120
115
 
121
116
  module_eval(<<~RUBY, __FILE__, __LINE__ + 1)
122
117
  def call(#{parameters})
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Dry
4
4
  module Logic
5
- VERSION = "1.0.7"
5
+ VERSION = "1.0.8"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dry-logic
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.7
4
+ version: 1.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotr Solnica
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-08-13 00:00:00.000000000 Z
11
+ date: 2020-09-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby