dry-logic 1.0.0 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +12 -1
  3. data/CONTRIBUTING.md +3 -3
  4. data/Gemfile +2 -0
  5. data/Rakefile +2 -0
  6. data/benchmarks/rule_application.rb +2 -0
  7. data/benchmarks/setup.rb +2 -0
  8. data/bin/console +1 -0
  9. data/dry-logic.gemspec +2 -0
  10. data/examples/basic.rb +2 -0
  11. data/lib/dry-logic.rb +2 -0
  12. data/lib/dry/logic.rb +2 -0
  13. data/lib/dry/logic/appliable.rb +2 -0
  14. data/lib/dry/logic/evaluator.rb +2 -0
  15. data/lib/dry/logic/operations.rb +2 -0
  16. data/lib/dry/logic/operations/abstract.rb +2 -0
  17. data/lib/dry/logic/operations/and.rb +2 -0
  18. data/lib/dry/logic/operations/attr.rb +2 -0
  19. data/lib/dry/logic/operations/binary.rb +2 -0
  20. data/lib/dry/logic/operations/check.rb +2 -0
  21. data/lib/dry/logic/operations/each.rb +2 -0
  22. data/lib/dry/logic/operations/implication.rb +2 -0
  23. data/lib/dry/logic/operations/key.rb +2 -0
  24. data/lib/dry/logic/operations/negation.rb +2 -0
  25. data/lib/dry/logic/operations/or.rb +2 -0
  26. data/lib/dry/logic/operations/set.rb +2 -0
  27. data/lib/dry/logic/operations/unary.rb +2 -0
  28. data/lib/dry/logic/operations/xor.rb +2 -0
  29. data/lib/dry/logic/operators.rb +2 -0
  30. data/lib/dry/logic/predicates.rb +11 -0
  31. data/lib/dry/logic/result.rb +2 -0
  32. data/lib/dry/logic/rule.rb +2 -0
  33. data/lib/dry/logic/rule/interface.rb +2 -0
  34. data/lib/dry/logic/rule/predicate.rb +2 -0
  35. data/lib/dry/logic/rule_compiler.rb +2 -0
  36. data/lib/dry/logic/version.rb +3 -1
  37. data/spec/integration/result_spec.rb +2 -0
  38. data/spec/integration/rule_spec.rb +2 -0
  39. data/spec/shared/predicates.rb +2 -0
  40. data/spec/shared/rule.rb +2 -0
  41. data/spec/spec_helper.rb +2 -0
  42. data/spec/support/mutant.rb +2 -0
  43. data/spec/unit/operations/and_spec.rb +2 -0
  44. data/spec/unit/operations/attr_spec.rb +2 -0
  45. data/spec/unit/operations/check_spec.rb +2 -0
  46. data/spec/unit/operations/each_spec.rb +2 -0
  47. data/spec/unit/operations/implication_spec.rb +2 -0
  48. data/spec/unit/operations/key_spec.rb +2 -0
  49. data/spec/unit/operations/negation_spec.rb +2 -0
  50. data/spec/unit/operations/or_spec.rb +2 -0
  51. data/spec/unit/operations/set_spec.rb +2 -0
  52. data/spec/unit/operations/xor_spec.rb +2 -0
  53. data/spec/unit/predicates/array_spec.rb +2 -0
  54. data/spec/unit/predicates/attr_spec.rb +2 -0
  55. data/spec/unit/predicates/bool_spec.rb +3 -1
  56. data/spec/unit/predicates/case_spec.rb +2 -0
  57. data/spec/unit/predicates/date_spec.rb +2 -0
  58. data/spec/unit/predicates/date_time_spec.rb +3 -1
  59. data/spec/unit/predicates/decimal_spec.rb +3 -1
  60. data/spec/unit/predicates/empty_spec.rb +2 -0
  61. data/spec/unit/predicates/eql_spec.rb +2 -0
  62. data/spec/unit/predicates/even_spec.rb +2 -0
  63. data/spec/unit/predicates/excluded_from_spec.rb +2 -0
  64. data/spec/unit/predicates/excludes_spec.rb +2 -0
  65. data/spec/unit/predicates/false_spec.rb +3 -1
  66. data/spec/unit/predicates/filled_spec.rb +2 -0
  67. data/spec/unit/predicates/float_spec.rb +2 -0
  68. data/spec/unit/predicates/format_spec.rb +2 -0
  69. data/spec/unit/predicates/gt_spec.rb +2 -0
  70. data/spec/unit/predicates/gteq_spec.rb +2 -0
  71. data/spec/unit/predicates/included_in_spec.rb +2 -0
  72. data/spec/unit/predicates/int_spec.rb +2 -0
  73. data/spec/unit/predicates/key_spec.rb +2 -0
  74. data/spec/unit/predicates/lt_spec.rb +2 -0
  75. data/spec/unit/predicates/lteq_spec.rb +2 -0
  76. data/spec/unit/predicates/max_size_spec.rb +2 -0
  77. data/spec/unit/predicates/min_size_spec.rb +2 -0
  78. data/spec/unit/predicates/none_spec.rb +2 -0
  79. data/spec/unit/predicates/not_eql_spec.rb +2 -0
  80. data/spec/unit/predicates/number_spec.rb +2 -0
  81. data/spec/unit/predicates/odd_spec.rb +2 -0
  82. data/spec/unit/predicates/respond_to_spec.rb +31 -0
  83. data/spec/unit/predicates/size_spec.rb +2 -0
  84. data/spec/unit/predicates/str_spec.rb +2 -0
  85. data/spec/unit/predicates/time_spec.rb +3 -1
  86. data/spec/unit/predicates/true_spec.rb +3 -1
  87. data/spec/unit/predicates/type_spec.rb +2 -0
  88. data/spec/unit/predicates/uuid_v4_spec.rb +29 -0
  89. data/spec/unit/predicates_spec.rb +2 -0
  90. data/spec/unit/rule/predicate_spec.rb +2 -0
  91. data/spec/unit/rule_compiler_spec.rb +2 -0
  92. data/spec/unit/rule_spec.rb +4 -2
  93. metadata +7 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cc0793c95681757b6d069c1d7c6bc59278457069edac35f329845dc283e69c22
4
- data.tar.gz: e46cd2a8f4e03c78778f35e51a3c616a2dc32881eb703aa6b441da1d34603733
3
+ metadata.gz: '092fd6393e21a754ce653a7b24dfdcb2dacb719723b9e3bb6607c2ba73962bde'
4
+ data.tar.gz: 3b3a2407f0cdf5f4d17c3bae1888f32d8c63ca666cecc5d6266ee4604ce6f551
5
5
  SHA512:
6
- metadata.gz: 732504942a364347befcdc7bee439777a0fd60b470b288cd793d9a21835ff13cc5399b2b6fd514ca0d586708fe044acd664dc2403b6a6a821851b4183533f494
7
- data.tar.gz: 811ba73afd3bc3f0bb13511ca69fa6af54a24638a7dc02cbc867df7529a276ed7b559c4cae7863b8b21a529b2095f8bbfc33eb027ea6f80e1d29076656cf13de
6
+ metadata.gz: a0ddca4a58b60a896077cc5c1d4b66e4c54470fb4182475e343bc90e3cdb6ec0e913784fc0c992c6e247532cfcdd50c2d47f48f467f443b71cab0f92fbf5d6da
7
+ data.tar.gz: a164d2b12242437c48d035e0cb139b1a24373d1d79f074d6b718fb81e7a6303f23cfc85c352fbfe8fdd9adf9602e44049d0bdcb15689d376b43a5b56fce549a6
@@ -1,6 +1,17 @@
1
+ # v1.0.1 2019-06-04 (yanked)
2
+
3
+ ### Added
4
+
5
+ - `uuid_v4?` predicate (radar)
6
+ - `respond_to?` predicate (waiting-for-dev)
7
+
8
+ [Compare v1.0.0...v1.0.1](https://github.com/dry-rb/dry-logic/compare/v1.0.0...v1.0.1)
9
+
10
+ This release was removed from rubygems because it broke dry-schema.
11
+
1
12
  # v1.0.0 2019-04-23
2
13
 
3
- Version bump to 1.0.0
14
+ * Version bump to `1.0.0` (flash-gordon)
4
15
 
5
16
  [Compare v0.6.1...v1.0.0](https://github.com/dry-rb/dry-logic/compare/v0.6.1...v1.0.0)
6
17
 
@@ -6,11 +6,11 @@ If you found a bug, report an issue and describe what's the expected behavior ve
6
6
 
7
7
  ## Reporting feature requests
8
8
 
9
- Report a feature request **only after discussing it first on [discuss.dry-rb.org](https://discuss.dry-rb.org)** where it was accepted. Please provide a concise description of the feature, don't link to a discussion thread, and instead summarize what was discussed.
9
+ Report a feature request **only after discussing it first on [discourse.dry-rb.org](https://discourse.dry-rb.org)** where it was accepted. Please provide a concise description of the feature, don't link to a discussion thread, and instead summarize what was discussed.
10
10
 
11
11
  ## Reporting questions, support requests, ideas, concerns etc.
12
12
 
13
- **PLEASE DON'T** - use [discuss.dry-rb.org](http://discuss.dry-rb.org) instead.
13
+ **PLEASE DON'T** - use [discourse.dry-rb.org](https://discourse.dry-rb.org) instead.
14
14
 
15
15
  # Pull Request Guidelines
16
16
 
@@ -26,4 +26,4 @@ Other requirements:
26
26
 
27
27
  # Asking for help
28
28
 
29
- If these guidelines aren't helpful, and you're stuck, please post a message on [discuss.dry-rb.org](https://discuss.dry-rb.org).
29
+ If these guidelines aren't helpful, and you're stuck, please post a message on [discourse.dry-rb.org](https://discourse.dry-rb.org).
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  gemspec
data/Rakefile CHANGED
@@ -1,4 +1,6 @@
1
1
  #!/usr/bin/env rake
2
+ # frozen_string_literal: true
3
+
2
4
  require 'bundler/gem_tasks'
3
5
 
4
6
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), 'lib'))
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'setup'
2
4
 
3
5
  unless Dry::Logic::Rule.respond_to?(:build)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'benchmark/ips'
2
4
  require 'hotch'
3
5
  ENV['HOTCH_VIEWER'] ||= 'open'
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require "bundler/setup"
4
5
  require 'dry/logic'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require File.expand_path('../lib/dry/logic/version', __FILE__)
2
4
 
3
5
  Gem::Specification.new do |spec|
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/logic'
2
4
  require 'dry/logic/predicates'
3
5
 
@@ -1 +1,3 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/logic'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # A collection of micro-libraries, each intended to encapsulate
2
4
  # a common task in Ruby
3
5
  module Dry
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Dry
2
4
  module Logic
3
5
  module Appliable
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/equalizer'
2
4
 
3
5
  module Dry
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/logic/operations/and'
2
4
  require 'dry/logic/operations/or'
3
5
  require 'dry/logic/operations/xor'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/core/constants'
2
4
  require 'dry/equalizer'
3
5
  require 'dry/logic/operators'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/logic/operations/binary'
2
4
  require 'dry/logic/result'
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/logic/operations/key'
2
4
 
3
5
  module Dry
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/logic/operations/abstract'
2
4
 
3
5
  module Dry
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/logic/operations/unary'
2
4
  require 'dry/logic/evaluator'
3
5
  require 'dry/logic/result'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/logic/operations/unary'
2
4
  require 'dry/logic/result'
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/logic/operations/binary'
2
4
  require 'dry/logic/result'
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/logic/operations/unary'
2
4
  require 'dry/logic/evaluator'
3
5
  require 'dry/logic/result'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/logic/operations/unary'
2
4
  require 'dry/logic/result'
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/logic/operations/binary'
2
4
  require 'dry/logic/result'
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/logic/operations/abstract'
2
4
  require 'dry/logic/result'
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/logic/operations/abstract'
2
4
 
3
5
  module Dry
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/logic/operations/binary'
2
4
  require 'dry/logic/result'
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Dry
2
4
  module Logic
3
5
  module Operators
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'bigdecimal'
2
4
  require 'bigdecimal/util'
3
5
  require 'date'
@@ -197,6 +199,15 @@ module Dry
197
199
  pattern === input
198
200
  end
199
201
 
202
+ def uuid_v4?(input)
203
+ uuid_v4_format = /^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i
204
+ format?(uuid_v4_format, input)
205
+ end
206
+
207
+ def respond_to?(method, input)
208
+ input.respond_to?(method)
209
+ end
210
+
200
211
  def predicate(name, &block)
201
212
  define_singleton_method(name, &block)
202
213
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/core/constants'
2
4
 
3
5
  module Dry
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'concurrent/map'
2
4
  require 'dry/core/constants'
3
5
  require 'dry/equalizer'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Dry
2
4
  module Logic
3
5
  class Rule
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/logic/rule'
2
4
 
3
5
  module Dry
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/core/constants'
2
4
 
3
5
  require 'dry/logic/rule'
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Dry
2
4
  module Logic
3
- VERSION = '1.0.0'.freeze
5
+ VERSION = '1.0.2'.freeze
4
6
  end
5
7
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  RSpec.describe Result do
2
4
  include_context 'predicates'
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry-logic'
2
4
 
3
5
  RSpec.describe 'Rules' do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/logic/predicates'
2
4
 
3
5
  RSpec.shared_examples 'predicates' do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  shared_examples_for Dry::Logic::Rule do
2
4
  let(:arity) { 2 }
3
5
  let(:predicate) { double(:predicate, arity: arity, name: predicate_name) }
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  if RUBY_ENGINE == 'ruby' && ENV['COVERAGE'] == 'true'
2
4
  require 'yaml'
3
5
  rubies = YAML.load(File.read(File.join(__dir__, '..', '.travis.yml')))['rvm']
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Mutant
2
4
  class Selector
3
5
  class Expression < self
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  RSpec.describe Operations::And do
2
4
  subject(:operation) { Operations::And.new(left, right) }
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  RSpec.describe Operations::Attr do
2
4
  subject(:operation) { Operations::Attr.new(Rule::Predicate.build(str?), name: :name) }
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  RSpec.describe Operations::Check do
2
4
  include_context 'predicates'
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  RSpec.describe Operations::Each do
2
4
  subject(:operation) { Operations::Each.new(is_string) }
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  RSpec.describe Operations::Implication do
2
4
  subject(:operation) { Operations::Implication.new(left, right) }
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  RSpec.describe Operations::Key do
2
4
  subject(:operation) { Operations::Key.new(predicate, name: :user) }
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  RSpec.describe Operations::Negation do
2
4
  subject(:operation) { Operations::Negation.new(is_int) }
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  RSpec.describe Operations::Or do
2
4
  subject(:operation) { Operations::Or.new(left, right) }
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  RSpec.describe Operations::Set do
2
4
  subject(:operation) { Operations::Set.new(is_int, gt_18) }
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  RSpec.describe Operations::Xor do
2
4
  subject(:operation) { Operations::Xor.new(left, right) }
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/logic/predicates'
2
4
 
3
5
  RSpec.describe Dry::Logic::Predicates do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/logic/predicates'
2
4
 
3
5
  RSpec.describe Dry::Logic::Predicates do
@@ -1,10 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/logic/predicates'
2
4
 
3
5
  RSpec.describe Dry::Logic::Predicates do
4
6
  describe '#bool?' do
5
7
  let(:predicate_name) { :bool? }
6
8
 
7
- context 'when value is a date' do
9
+ context 'when value is a boolean' do
8
10
  let(:arguments_list) do
9
11
  [[true], [false]]
10
12
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/logic/predicates'
2
4
 
3
5
  RSpec.describe Dry::Logic::Predicates do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/logic/predicates'
2
4
 
3
5
  RSpec.describe Dry::Logic::Predicates do
@@ -1,10 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/logic/predicates'
2
4
 
3
5
  RSpec.describe Dry::Logic::Predicates do
4
6
  describe '#date_time?' do
5
7
  let(:predicate_name) { :date_time? }
6
8
 
7
- context 'when value is a date' do
9
+ context 'when value is a datetime' do
8
10
  let(:arguments_list) do
9
11
  [[DateTime.now]]
10
12
  end
@@ -1,10 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/logic/predicates'
2
4
 
3
5
  RSpec.describe Dry::Logic::Predicates do
4
6
  describe '#decimal?' do
5
7
  let(:predicate_name) { :decimal? }
6
8
 
7
- context 'when value is a date' do
9
+ context 'when value is a decimal' do
8
10
  let(:arguments_list) do
9
11
  [[1.2.to_d]]
10
12
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/logic/predicates'
2
4
 
3
5
  RSpec.describe Dry::Logic::Predicates do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/logic/predicates'
2
4
 
3
5
  RSpec.describe Dry::Logic::Predicates, '#eql?' do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/logic/predicates'
2
4
 
3
5
  RSpec.describe Dry::Logic::Predicates do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/logic/predicates'
2
4
 
3
5
  RSpec.describe Dry::Logic::Predicates do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/logic/predicates'
2
4
 
3
5
  RSpec.describe Dry::Logic::Predicates do
@@ -1,10 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/logic/predicates'
2
4
 
3
5
  RSpec.describe Dry::Logic::Predicates do
4
6
  describe '#false?' do
5
7
  let(:predicate_name) { :false? }
6
8
 
7
- context 'when value is a date' do
9
+ context 'when value is false' do
8
10
  let(:arguments_list) do
9
11
  [[false]]
10
12
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/logic/predicates'
2
4
 
3
5
  RSpec.describe Dry::Logic::Predicates do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/logic/predicates'
2
4
 
3
5
  RSpec.describe Dry::Logic::Predicates do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/logic/predicates'
2
4
 
3
5
  RSpec.describe Dry::Logic::Predicates, '#format?' do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/logic/predicates'
2
4
 
3
5
  RSpec.describe Dry::Logic::Predicates do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/logic/predicates'
2
4
 
3
5
  RSpec.describe Dry::Logic::Predicates do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/logic/predicates'
2
4
 
3
5
  RSpec.describe Dry::Logic::Predicates do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/logic/predicates'
2
4
 
3
5
  RSpec.describe Dry::Logic::Predicates do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/logic/predicates'
2
4
 
3
5
  RSpec.describe Dry::Logic::Predicates do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/logic/predicates'
2
4
 
3
5
  RSpec.describe Dry::Logic::Predicates do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/logic/predicates'
2
4
 
3
5
  RSpec.describe Dry::Logic::Predicates do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/logic/predicates'
2
4
 
3
5
  RSpec.describe Dry::Logic::Predicates do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/logic/predicates'
2
4
 
3
5
  RSpec.describe Dry::Logic::Predicates do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/logic/predicates'
2
4
 
3
5
  RSpec.describe Dry::Logic::Predicates do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/logic/predicates'
2
4
 
3
5
  RSpec.describe Dry::Logic::Predicates, '#not_eql?' do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/logic/predicates'
2
4
 
3
5
  RSpec.describe Dry::Logic::Predicates do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/logic/predicates'
2
4
 
3
5
  RSpec.describe Dry::Logic::Predicates do
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'dry/logic/predicates'
4
+
5
+ RSpec.describe Dry::Logic::Predicates do
6
+ describe '#respond_to?' do
7
+ let(:predicate_name) { :respond_to? }
8
+
9
+ context 'when value responds to method' do
10
+ let(:arguments_list) do
11
+ [
12
+ [:method, Object],
13
+ [:new, Hash]
14
+ ]
15
+ end
16
+
17
+ it_behaves_like 'a passing predicate'
18
+ end
19
+
20
+ context 'when value does not respond to method' do
21
+ let(:arguments_list) do
22
+ [
23
+ [:foo, Object],
24
+ [:bar, Hash]
25
+ ]
26
+ end
27
+
28
+ it_behaves_like 'a failing predicate'
29
+ end
30
+ end
31
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/logic/predicates'
2
4
 
3
5
  RSpec.describe Dry::Logic::Predicates do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/logic/predicates'
2
4
 
3
5
  RSpec.describe Dry::Logic::Predicates do
@@ -1,10 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/logic/predicates'
2
4
 
3
5
  RSpec.describe Dry::Logic::Predicates do
4
6
  describe '#time?' do
5
7
  let(:predicate_name) { :time? }
6
8
 
7
- context 'when value is a date' do
9
+ context 'when value is a time' do
8
10
  let(:arguments_list) do
9
11
  [[Time.now]]
10
12
  end
@@ -1,10 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/logic/predicates'
2
4
 
3
5
  RSpec.describe Dry::Logic::Predicates do
4
6
  describe '#true?' do
5
7
  let(:predicate_name) { :true? }
6
8
 
7
- context 'when value is a date' do
9
+ context 'when value is true' do
8
10
  let(:arguments_list) do
9
11
  [[true]]
10
12
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/logic/predicates'
2
4
 
3
5
  RSpec.describe Dry::Logic::Predicates do
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'dry/logic/predicates'
4
+
5
+ RSpec.describe Dry::Logic::Predicates do
6
+ describe '#uuid_v4?' do
7
+ let(:predicate_name) { :uuid_v4? }
8
+
9
+ context 'when value is a valid V4 UUID' do
10
+ let(:arguments_list) do
11
+ [['f2d26c57-e07c-4416-a749-57e937930e04']]
12
+ end
13
+
14
+ it_behaves_like 'a passing predicate'
15
+ end
16
+
17
+ context 'with value is not a valid V4 UUID' do
18
+ let(:arguments_list) do
19
+ [
20
+ ['f2d26c57-e07c-3416-a749-57e937930e04'], # wrong version number (3, not 4)
21
+ ['20633928-6a07-11e9-a923-1681be663d3e'], # UUID V1
22
+ ['not-a-uuid-at-all']
23
+ ]
24
+ end
25
+
26
+ it_behaves_like 'a failing predicate'
27
+ end
28
+ end
29
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/logic/predicates'
2
4
 
3
5
  RSpec.describe Predicates do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  RSpec.describe Rule::Predicate do
2
4
  subject(:rule) { Rule::Predicate.build(predicate) }
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/logic/rule_compiler'
2
4
 
3
5
  RSpec.describe Dry::Logic::RuleCompiler, '#call' do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  RSpec.describe Dry::Logic::Rule do
2
4
  subject(:rule) { Rule.build(predicate, options) }
3
5
 
@@ -178,8 +180,8 @@ RSpec.describe Dry::Logic::Rule do
178
180
  end
179
181
 
180
182
  describe 'arbitrary arity' do
181
- let(:arity) { rand(20) }
182
- let(:curried) { arity.zero? ? 0 : rand(arity) }
183
+ let(:arity) { rand(1..20) }
184
+ let(:curried) { rand(arity) }
183
185
 
184
186
  let(:options) { { args: [1] * curried, arity: arity } }
185
187
  let(:predicate) { double(:predicate) }
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.0
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotr Solnica
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-04-23 00:00:00.000000000 Z
11
+ date: 2019-06-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -188,11 +188,13 @@ files:
188
188
  - spec/unit/predicates/not_eql_spec.rb
189
189
  - spec/unit/predicates/number_spec.rb
190
190
  - spec/unit/predicates/odd_spec.rb
191
+ - spec/unit/predicates/respond_to_spec.rb
191
192
  - spec/unit/predicates/size_spec.rb
192
193
  - spec/unit/predicates/str_spec.rb
193
194
  - spec/unit/predicates/time_spec.rb
194
195
  - spec/unit/predicates/true_spec.rb
195
196
  - spec/unit/predicates/type_spec.rb
197
+ - spec/unit/predicates/uuid_v4_spec.rb
196
198
  - spec/unit/predicates_spec.rb
197
199
  - spec/unit/rule/predicate_spec.rb
198
200
  - spec/unit/rule_compiler_spec.rb
@@ -216,7 +218,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
216
218
  - !ruby/object:Gem::Version
217
219
  version: '0'
218
220
  requirements: []
219
- rubygems_version: 3.0.3
221
+ rubygems_version: 3.0.1
220
222
  signing_key:
221
223
  specification_version: 4
222
224
  summary: Predicate logic with rule composition
@@ -267,11 +269,13 @@ test_files:
267
269
  - spec/unit/predicates/not_eql_spec.rb
268
270
  - spec/unit/predicates/number_spec.rb
269
271
  - spec/unit/predicates/odd_spec.rb
272
+ - spec/unit/predicates/respond_to_spec.rb
270
273
  - spec/unit/predicates/size_spec.rb
271
274
  - spec/unit/predicates/str_spec.rb
272
275
  - spec/unit/predicates/time_spec.rb
273
276
  - spec/unit/predicates/true_spec.rb
274
277
  - spec/unit/predicates/type_spec.rb
278
+ - spec/unit/predicates/uuid_v4_spec.rb
275
279
  - spec/unit/predicates_spec.rb
276
280
  - spec/unit/rule/predicate_spec.rb
277
281
  - spec/unit/rule_compiler_spec.rb