dry-logic 1.0.6 → 1.2.0

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: a6c0b350baaf47853027db9d61e790c195ced412ff40a9ecaac56b6588172da3
4
- data.tar.gz: 966f1daee610a4eea2eae78743e8e17f0e57084b1106fd3f033483329895a4a1
3
+ metadata.gz: 1e3f807ddbab8319c1c039978115800a4f8c6d41b337815cdaf6226563716a3d
4
+ data.tar.gz: 79cb10c28f23ebc523c15f4cd3da9657aeeb9923f7ed778bfaaa10c5dd59824c
5
5
  SHA512:
6
- metadata.gz: 98002481f3e8cc83affa67ff7b3f8e69b22836f0737112bba1d4c656f39cbc06d9657bdb7865326fb9b6531660a9fd260b60d18d2062d9d149a97f25154a3974
7
- data.tar.gz: cc6163b44e7e2ef296901e35085fa42290ad8b4b936237e26409f7f71d90041e12472322319d3dc8553fb46dcf532b2747b68b1d3a5cd46e81bb94fb298cf56c
6
+ metadata.gz: ad9c5d83eb742610eddb8ea47be7a31cffcfee956223d08a1f595c90b02289d16b78e0dfe4b7ff48cf3fec7b79a586aab148a8e00afc67a9b8e0a6600f8687cc
7
+ data.tar.gz: 1df8067e98f4b90ff921a1d0eccaef3e29aa1b819337110cb2b20deb2e60215433118d2ba30bd54f41e5dec634b76a65d52c18fd924992c62ba4735a5fbd97a1
data/CHANGELOG.md CHANGED
@@ -1,3 +1,59 @@
1
+ <!--- DO NOT EDIT THIS FILE - IT'S AUTOMATICALLY GENERATED VIA DEVTOOLS --->
2
+
3
+ ## 1.2.0 2021-04-26
4
+
5
+
6
+ ### Added
7
+
8
+ - Add predicate and operation builder DSL (@oleander)
9
+
10
+
11
+ [Compare v1.1.1...v1.2.0](https://github.com/dry-rb/dry-logic/compare/v1.1.1...v1.2.0)
12
+
13
+ ## 1.1.1 2021-04-14
14
+
15
+
16
+ ### Fixed
17
+
18
+ - Fixed a crash under jruby caused by arg splatting in Binary operations (@flash-gordon)
19
+
20
+
21
+ [Compare v1.1.0...v1.1.1](https://github.com/dry-rb/dry-logic/compare/v1.1.0...v1.1.1)
22
+
23
+ ## 1.1.0 2020-12-26
24
+
25
+
26
+ ### Fixed
27
+
28
+ - Nested `Check` operations no longer crash under MRI 3.0 (@oleander)
29
+
30
+ ### Changed
31
+
32
+ - Switched to equalizer from dry-core (@solnic)
33
+
34
+ [Compare v1.0.8...v1.1.0](https://github.com/dry-rb/dry-logic/compare/v1.0.8...v1.1.0)
35
+
36
+ ## 1.0.8 2020-09-28
37
+
38
+
39
+ ### Fixed
40
+
41
+ - Better Ruby 3 support with fixed specialization for rules of negative arity (@flash-gordon)
42
+
43
+
44
+ [Compare v1.0.7...v1.0.8](https://github.com/dry-rb/dry-logic/compare/v1.0.7...v1.0.8)
45
+
46
+ ## 1.0.7 2020-08-13
47
+
48
+
49
+ ### Added
50
+
51
+ - A new `uri?` predicate that you can use to verify `URI` strings, ie `uri?("https", "https://dry-rb.org")` (@nerburish)
52
+ - New predicates: `uuid_v1?`, `uuid_v2?`, `uuid_v3?` and `uuid_v5?` (via #75) (@jamesbrauman)
53
+
54
+
55
+ [Compare v1.0.6...v1.0.7](https://github.com/dry-rb/dry-logic/compare/v1.0.6...v1.0.7)
56
+
1
57
  ## 1.0.6 2020-02-10
2
58
 
3
59
 
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2015-2020 dry-rb team
3
+ Copyright (c) 2015-2021 dry-rb team
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy of
6
6
  this software and associated documentation files (the "Software"), to deal in
data/README.md CHANGED
@@ -21,7 +21,7 @@
21
21
 
22
22
  This library officially supports the following Ruby versions:
23
23
 
24
- * MRI >= `2.4`
24
+ * MRI >= `2.5`
25
25
  * jruby >= `9.2`
26
26
 
27
27
  ## License
data/dry-logic.gemspec CHANGED
@@ -25,12 +25,11 @@ Gem::Specification.new do |spec|
25
25
  spec.metadata['source_code_uri'] = 'https://github.com/dry-rb/dry-logic'
26
26
  spec.metadata['bug_tracker_uri'] = 'https://github.com/dry-rb/dry-logic/issues'
27
27
 
28
- spec.required_ruby_version = ">= 2.4.0"
28
+ spec.required_ruby_version = ">= 2.5.0"
29
29
 
30
30
  # to update dependencies edit project.yml
31
31
  spec.add_runtime_dependency "concurrent-ruby", "~> 1.0"
32
- spec.add_runtime_dependency "dry-core", "~> 0.2"
33
- spec.add_runtime_dependency "dry-equalizer", "~> 0.2"
32
+ spec.add_runtime_dependency "dry-core", "~> 0.5", ">= 0.5"
34
33
 
35
34
  spec.add_development_dependency "bundler"
36
35
  spec.add_development_dependency "rake"
data/lib/dry-logic.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'dry/logic'
3
+ require "dry/logic"
data/lib/dry/logic.rb CHANGED
@@ -7,5 +7,5 @@ module Dry
7
7
  end
8
8
  end
9
9
 
10
- require 'dry/logic/rule/predicate'
11
- require 'dry/logic/operations'
10
+ require "dry/logic/rule/predicate"
11
+ require "dry/logic/operations"
@@ -0,0 +1,91 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "dry/logic"
4
+ require "singleton"
5
+ require "delegate"
6
+
7
+ module Dry
8
+ module Logic
9
+ autoload :Operations, "dry/logic/operations"
10
+ autoload :Predicates, "dry/logic/predicates"
11
+ module Builder
12
+ IGNORED_OPERATIONS = %i[
13
+ Abstract
14
+ Binary
15
+ Unary
16
+ ].freeze
17
+
18
+ IGNORED_PREDICATES = [
19
+ :predicate
20
+ ].freeze
21
+
22
+ # Predicate and operation builder
23
+ #
24
+ # @block [Proc]
25
+ # @return [Builder::Result]
26
+ # @example Check if input is zero
27
+ # is_zero = Dry::Logic::Builder.call do
28
+ # negation { lt?(0) ^ gt?(0) }
29
+ # end
30
+ #
31
+ # p is_zero.call(1) # => false
32
+ # p is_zero.call(0) # => true
33
+ # p is_zero.call(-1) # => false
34
+ def call(&context)
35
+ Context.instance.call(&context)
36
+ end
37
+ module_function :call
38
+ alias_method :build, :call
39
+ public :call, :build
40
+
41
+ class Context
42
+ include Dry::Logic
43
+ include Singleton
44
+
45
+ module Predicates
46
+ include Logic::Predicates
47
+ end
48
+
49
+ # @see Builder#call
50
+ def call(&context)
51
+ instance_eval(&context)
52
+ end
53
+
54
+ # Defines custom predicate
55
+ #
56
+ # @name [Symbol] Name of predicate
57
+ # @Context [Proc]
58
+ def predicate(name, &context)
59
+ if singleton_class.method_defined?(name)
60
+ singleton_class.undef_method(name)
61
+ end
62
+
63
+ prerdicate = Rule::Predicate.new(context)
64
+
65
+ define_singleton_method(name) do |*args|
66
+ prerdicate.curry(*args)
67
+ end
68
+ end
69
+
70
+ # Defines methods for operations and predicates
71
+ def initialize
72
+ Operations.constants(false).each do |name|
73
+ next if IGNORED_OPERATIONS.include?(name)
74
+
75
+ operation = Operations.const_get(name)
76
+
77
+ define_singleton_method(name.downcase) do |*args, **kwargs, &block|
78
+ operation.new(*call(&block), *args, **kwargs)
79
+ end
80
+ end
81
+
82
+ Predicates::Methods.instance_methods(false).each do |name|
83
+ unless IGNORED_PREDICATES.include?(name)
84
+ predicate(name, &Predicates[name])
85
+ end
86
+ end
87
+ end
88
+ end
89
+ end
90
+ end
91
+ end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'dry/equalizer'
3
+ require "dry/core/equalizer"
4
4
 
5
5
  module Dry
6
6
  module Logic
@@ -1,15 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'dry/logic/operations/and'
4
- require 'dry/logic/operations/or'
5
- require 'dry/logic/operations/xor'
6
- require 'dry/logic/operations/implication'
7
- require 'dry/logic/operations/negation'
3
+ require "dry/logic/operations/and"
4
+ require "dry/logic/operations/or"
5
+ require "dry/logic/operations/xor"
6
+ require "dry/logic/operations/implication"
7
+ require "dry/logic/operations/negation"
8
8
 
9
- require 'dry/logic/operations/key'
10
- require 'dry/logic/operations/attr'
11
- require 'dry/logic/operations/each'
12
- require 'dry/logic/operations/set'
13
- require 'dry/logic/operations/check'
9
+ require "dry/logic/operations/key"
10
+ require "dry/logic/operations/attr"
11
+ require "dry/logic/operations/each"
12
+ require "dry/logic/operations/set"
13
+ require "dry/logic/operations/check"
14
14
 
15
- require 'dry/logic/operators'
15
+ require "dry/logic/operators"
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'dry/core/constants'
4
- require 'dry/equalizer'
5
- require 'dry/logic/operators'
3
+ require "dry/core/constants"
4
+ require "dry/core/equalizer"
5
+ require "dry/logic/operators"
6
6
 
7
7
  module Dry
8
8
  module Logic
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'dry/logic/operations/binary'
4
- require 'dry/logic/result'
3
+ require "dry/logic/operations/binary"
4
+ require "dry/logic/result"
5
5
 
6
6
  module Dry
7
7
  module Logic
@@ -17,7 +17,7 @@ module Dry
17
17
  def type
18
18
  :and
19
19
  end
20
- alias operator type
20
+ alias_method :operator, :type
21
21
 
22
22
  def call(input)
23
23
  left_result = left.(input)
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'dry/logic/operations/key'
3
+ require "dry/logic/operations/key"
4
4
 
5
5
  module Dry
6
6
  module Logic
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'dry/logic/operations/abstract'
3
+ require "dry/logic/operations/abstract"
4
4
 
5
5
  module Dry
6
6
  module Logic
@@ -10,9 +10,10 @@ module Dry
10
10
 
11
11
  attr_reader :right
12
12
 
13
- def initialize(*rules, **options)
13
+ def initialize(left, right, **options)
14
14
  super
15
- @left, @right = rules
15
+ @left = left
16
+ @right = right
16
17
  end
17
18
 
18
19
  def ast(input = Undefined)
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'dry/logic/operations/unary'
4
- require 'dry/logic/evaluator'
5
- require 'dry/logic/result'
3
+ require "dry/logic/operations/unary"
4
+ require "dry/logic/evaluator"
5
+ require "dry/logic/result"
6
6
 
7
7
  module Dry
8
8
  module Logic
@@ -12,7 +12,7 @@ module Dry
12
12
 
13
13
  def self.new(rule, **options)
14
14
  if options[:evaluator]
15
- super(rule, options)
15
+ super(rule, **options)
16
16
  else
17
17
  keys = options.fetch(:keys)
18
18
  evaluator = Evaluator::Set.new(keys)
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'dry/logic/operations/unary'
4
- require 'dry/logic/result'
3
+ require "dry/logic/operations/unary"
4
+ require "dry/logic/result"
5
5
 
6
6
  module Dry
7
7
  module Logic
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'dry/logic/operations/binary'
4
- require 'dry/logic/result'
3
+ require "dry/logic/operations/binary"
4
+ require "dry/logic/result"
5
5
 
6
6
  module Dry
7
7
  module Logic
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'dry/logic/operations/unary'
4
- require 'dry/logic/evaluator'
5
- require 'dry/logic/result'
3
+ require "dry/logic/operations/unary"
4
+ require "dry/logic/evaluator"
5
+ require "dry/logic/result"
6
6
 
7
7
  module Dry
8
8
  module Logic
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'dry/logic/operations/unary'
4
- require 'dry/logic/result'
3
+ require "dry/logic/operations/unary"
4
+ require "dry/logic/result"
5
5
 
6
6
  module Dry
7
7
  module Logic
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'dry/logic/operations/binary'
4
- require 'dry/logic/result'
3
+ require "dry/logic/operations/binary"
4
+ require "dry/logic/result"
5
5
 
6
6
  module Dry
7
7
  module Logic
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'dry/logic/operations/abstract'
4
- require 'dry/logic/result'
3
+ require "dry/logic/operations/abstract"
4
+ require "dry/logic/result"
5
5
 
6
6
  module Dry
7
7
  module Logic
@@ -29,7 +29,7 @@ module Dry
29
29
  end
30
30
 
31
31
  def to_s
32
- "#{type}(#{rules.map(&:to_s).join(', ')})"
32
+ "#{type}(#{rules.map(&:to_s).join(", ")})"
33
33
  end
34
34
  end
35
35
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'dry/logic/operations/abstract'
3
+ require "dry/logic/operations/abstract"
4
4
 
5
5
  module Dry
6
6
  module Logic
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'dry/logic/operations/binary'
4
- require 'dry/logic/result'
3
+ require "dry/logic/operations/binary"
4
+ require "dry/logic/result"
5
5
 
6
6
  module Dry
7
7
  module Logic
@@ -6,22 +6,22 @@ module Dry
6
6
  def and(other)
7
7
  Operations::And.new(self, other)
8
8
  end
9
- alias & and
9
+ alias_method :&, :and
10
10
 
11
11
  def or(other)
12
12
  Operations::Or.new(self, other)
13
13
  end
14
- alias | or
14
+ alias_method :|, :or
15
15
 
16
16
  def xor(other)
17
17
  Operations::Xor.new(self, other)
18
18
  end
19
- alias ^ xor
19
+ alias_method :^, :xor
20
20
 
21
21
  def then(other)
22
22
  Operations::Implication.new(self, other)
23
23
  end
24
- alias > then
24
+ alias_method :>, :then
25
25
  end
26
26
  end
27
27
  end
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'bigdecimal'
4
- require 'bigdecimal/util'
5
- require 'date'
3
+ require "bigdecimal"
4
+ require "bigdecimal/util"
5
+ require "date"
6
6
 
7
7
  module Dry
8
8
  module Logic
@@ -13,7 +13,7 @@ module Dry
13
13
  end
14
14
 
15
15
  def type?(type, input)
16
- input.kind_of?(type)
16
+ input.is_a?(type)
17
17
  end
18
18
 
19
19
  def nil?(input)
@@ -147,12 +147,12 @@ module Dry
147
147
  end
148
148
 
149
149
  def inclusion?(list, input)
150
- ::Kernel.warn 'inclusion is deprecated - use included_in instead.'
150
+ ::Kernel.warn "inclusion is deprecated - use included_in instead."
151
151
  included_in?(list, input)
152
152
  end
153
153
 
154
154
  def exclusion?(list, input)
155
- ::Kernel.warn 'exclusion is deprecated - use excluded_from instead.'
155
+ ::Kernel.warn "exclusion is deprecated - use excluded_from instead."
156
156
  excluded_from?(list, input)
157
157
  end
158
158
 
@@ -206,11 +206,36 @@ module Dry
206
206
  pattern === input
207
207
  end
208
208
 
209
+ def uuid_v1?(input)
210
+ uuid_v1_format = /\A[0-9A-F]{8}-[0-9A-F]{4}-1[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}\z/i
211
+ format?(uuid_v1_format, input)
212
+ end
213
+
214
+ def uuid_v2?(input)
215
+ uuid_v2_format = /\A[0-9A-F]{8}-[0-9A-F]{4}-2[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}\z/i
216
+ format?(uuid_v2_format, input)
217
+ end
218
+
219
+ def uuid_v3?(input)
220
+ uuid_v3_format = /\A[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}\z/i
221
+ format?(uuid_v3_format, input)
222
+ end
223
+
209
224
  def uuid_v4?(input)
210
225
  uuid_v4_format = /\A[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}\z/i
211
226
  format?(uuid_v4_format, input)
212
227
  end
213
228
 
229
+ def uuid_v5?(input)
230
+ uuid_v5_format = /\A[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}\z/i
231
+ format?(uuid_v5_format, input)
232
+ end
233
+
234
+ def uri?(schemes, input)
235
+ uri_format = URI::DEFAULT_PARSER.make_regexp(schemes)
236
+ format?(uri_format, input)
237
+ end
238
+
214
239
  def respond_to?(method, input)
215
240
  input.respond_to?(method)
216
241
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'dry/core/constants'
3
+ require "dry/core/constants"
4
4
 
5
5
  module Dry
6
6
  module Logic
@@ -69,7 +69,7 @@ module Dry
69
69
  if args.empty?
70
70
  name.to_s
71
71
  else
72
- "#{name}(#{args.map(&:last).map(&:inspect).join(', ')})"
72
+ "#{name}(#{args.map(&:last).map(&:inspect).join(", ")})"
73
73
  end
74
74
  end
75
75
 
@@ -1,11 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'concurrent/map'
4
- require 'dry/core/constants'
5
- require 'dry/equalizer'
6
- require 'dry/logic/operations'
7
- require 'dry/logic/result'
8
- require 'dry/logic/rule/interface'
3
+ require "concurrent/map"
4
+ require "dry/core/constants"
5
+ require "dry/core/equalizer"
6
+ require "dry/logic/operations"
7
+ require "dry/logic/result"
8
+ require "dry/logic/rule/interface"
9
9
 
10
10
  module Dry
11
11
  module Logic
@@ -38,13 +38,13 @@ module Dry
38
38
  base.interfaces.fetch_or_store([arity, curried]) do
39
39
  interface = Interface.new(arity, curried)
40
40
  klass = Class.new(base) { include interface }
41
- base.const_set("#{base.name.split('::').last}#{interface.name}", klass)
41
+ base.const_set("#{base.name.split("::").last}#{interface.name}", klass)
42
42
  klass
43
43
  end
44
44
  end
45
45
 
46
46
  def self.build(predicate, args: EMPTY_ARRAY, arity: predicate.arity, **options)
47
- specialize(arity, args.size).new(predicate, { args: args, arity: arity, **options })
47
+ specialize(arity, args.size).new(predicate, {args: args, arity: arity, **options})
48
48
  end
49
49
 
50
50
  def initialize(predicate, options = EMPTY_HASH)
@@ -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
@@ -49,10 +55,21 @@ module Dry
49
55
 
50
56
  def name
51
57
  if constant?
52
- 'Constant'
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
@@ -61,9 +78,9 @@ module Dry
61
78
  def define_constructor
62
79
  assignment =
63
80
  if curried.equal?(1)
64
- '@arg0 = @args[0]'
81
+ "@arg0 = @args[0]"
65
82
  else
66
- "#{curried_args.join(', ')} = @args"
83
+ "#{curried_args.join(", ")} = @args"
67
84
  end
68
85
 
69
86
  module_eval(<<~RUBY, __FILE__, __LINE__ + 1)
@@ -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})
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'dry/logic/rule'
3
+ require "dry/logic/rule"
4
4
 
5
5
  module Dry
6
6
  module Logic
@@ -19,9 +19,9 @@ module Dry
19
19
 
20
20
  def to_s
21
21
  if args.size > 0
22
- "#{name}(#{args.map(&:inspect).join(', ')})"
22
+ "#{name}(#{args.map(&:inspect).join(", ")})"
23
23
  else
24
- "#{name}"
24
+ name.to_s
25
25
  end
26
26
  end
27
27
 
@@ -1,9 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'dry/core/constants'
3
+ require "dry/core/constants"
4
4
 
5
- require 'dry/logic/rule'
6
- require 'dry/logic/rule/predicate'
5
+ require "dry/logic/rule"
6
+ require "dry/logic/rule/predicate"
7
7
 
8
8
  module Dry
9
9
  module Logic
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Dry
4
4
  module Logic
5
- VERSION = '1.0.6'
5
+ VERSION = "1.2.0"
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.6
4
+ version: 1.2.0
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-02-10 00:00:00.000000000 Z
11
+ date: 2021-04-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -30,28 +30,20 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0.2'
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '0.2'
41
- - !ruby/object:Gem::Dependency
42
- name: dry-equalizer
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
33
+ version: '0.5'
34
+ - - ">="
46
35
  - !ruby/object:Gem::Version
47
- version: '0.2'
36
+ version: '0.5'
48
37
  type: :runtime
49
38
  prerelease: false
50
39
  version_requirements: !ruby/object:Gem::Requirement
51
40
  requirements:
52
41
  - - "~>"
53
42
  - !ruby/object:Gem::Version
54
- version: '0.2'
43
+ version: '0.5'
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0.5'
55
47
  - !ruby/object:Gem::Dependency
56
48
  name: bundler
57
49
  requirement: !ruby/object:Gem::Requirement
@@ -108,6 +100,7 @@ files:
108
100
  - lib/dry-logic.rb
109
101
  - lib/dry/logic.rb
110
102
  - lib/dry/logic/appliable.rb
103
+ - lib/dry/logic/builder.rb
111
104
  - lib/dry/logic/evaluator.rb
112
105
  - lib/dry/logic/operations.rb
113
106
  - lib/dry/logic/operations/abstract.rb
@@ -147,14 +140,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
147
140
  requirements:
148
141
  - - ">="
149
142
  - !ruby/object:Gem::Version
150
- version: 2.4.0
143
+ version: 2.5.0
151
144
  required_rubygems_version: !ruby/object:Gem::Requirement
152
145
  requirements:
153
146
  - - ">="
154
147
  - !ruby/object:Gem::Version
155
148
  version: '0'
156
149
  requirements: []
157
- rubygems_version: 3.0.3
150
+ rubygems_version: 3.1.6
158
151
  signing_key:
159
152
  specification_version: 4
160
153
  summary: Predicate logic with rule composition