dry-logic 0.2.0 → 0.2.1

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
  SHA1:
3
- metadata.gz: 556cffe1d07e756e85274f2af98b8d97245e4420
4
- data.tar.gz: 86695fbdf83593baedb7dd73483c30f41f671280
3
+ metadata.gz: 405fbdd05ed04c6abd40e6f4e0bc82798ce17463
4
+ data.tar.gz: c0d6fb17709b8d8c69594e8fb38caa7161eee873
5
5
  SHA512:
6
- metadata.gz: 05b63d57cfacd055926b256752698078dbca63afcf8bb03aff563cbecff5247e9dc66e999bad29cecc1fc5f37a15a5c6c76525cb1e6654f1c4915777825d5fa3
7
- data.tar.gz: f1a65826b7049c3c5b0083b4c72feda8e911915898ff03a4d9acc5b4d6908954d9105edd36f611e535e0e0320b1f906f9ae658659a062b48ee18b564e1ab0abb
6
+ metadata.gz: b5efcddce3c685049908c67e33fdfc3b473ff173c313469c40169ef02332aaa18e1711e40eaf47b683c29dbe2e2d5dd25bd76fa9c8b53b05457661ac98966f52
7
+ data.tar.gz: 89be8d68859d37e8969ca9ea650bea7ed9225dbc51f0911e5e66dc47df82f6560292879052dcb2906ff7e43d8a3c5f1f2ea2922317fbb82710487fc0cbfc9298
@@ -1,3 +1,17 @@
1
+ # v0.2.1 2016-03-20
2
+
3
+ ### Fixed
4
+
5
+ * Result AST for `Rule::Each` correctly maps elements with eql inputs (solnic)
6
+
7
+ # v0.2.0 2016-03-11
8
+
9
+ ### Changed
10
+
11
+ * Entire AST has been redefined (solnic)
12
+
13
+ [Compare v0.1.4...v0.2.0](https://github.com/dryrb/dry-logic/compare/v0.1.4...v0.2.0)
14
+
1
15
  # v0.1.4 2016-01-27
2
16
 
3
17
  ### Added
data/README.md CHANGED
@@ -1,23 +1,23 @@
1
1
  [gem]: https://rubygems.org/gems/dry-logic
2
- [travis]: https://travis-ci.org/dryrb/dry-logic
3
- [gemnasium]: https://gemnasium.com/dryrb/dry-logic
4
- [codeclimate]: https://codeclimate.com/github/dryrb/dry-logic
5
- [coveralls]: https://coveralls.io/r/dryrb/dry-logic
6
- [inchpages]: http://inch-ci.org/github/dryrb/dry-logic
2
+ [travis]: https://travis-ci.org/dry-rb/dry-logic
3
+ [gemnasium]: https://gemnasium.com/dry-rb/dry-logic
4
+ [codeclimate]: https://codeclimate.com/github/dry-rb/dry-logic
5
+ [coveralls]: https://coveralls.io/r/dry-rb/dry-logic
6
+ [inchpages]: http://inch-ci.org/github/dry-rb/dry-logic
7
7
 
8
- # dry-logic [![Join the chat at https://gitter.im/dryrb/chat](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/dryrb/chat)
8
+ # dry-logic [![Join the chat at https://gitter.im/dry-rb/chat](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/dry-rb/chat)
9
9
 
10
10
  [![Gem Version](https://badge.fury.io/rb/dry-logic.svg)][gem]
11
- [![Build Status](https://travis-ci.org/dryrb/dry-logic.svg?branch=master)][travis]
12
- [![Dependency Status](https://gemnasium.com/dryrb/dry-logic.svg)][gemnasium]
13
- [![Code Climate](https://codeclimate.com/github/dryrb/dry-logic/badges/gpa.svg)][codeclimate]
14
- [![Test Coverage](https://codeclimate.com/github/dryrb/dry-logic/badges/coverage.svg)][codeclimate]
15
- [![Inline docs](http://inch-ci.org/github/dryrb/dry-logic.svg?branch=master)][inchpages]
11
+ [![Build Status](https://travis-ci.org/dry-rb/dry-logic.svg?branch=master)][travis]
12
+ [![Dependency Status](https://gemnasium.com/dry-rb/dry-logic.svg)][gemnasium]
13
+ [![Code Climate](https://codeclimate.com/github/dry-rb/dry-logic/badges/gpa.svg)][codeclimate]
14
+ [![Test Coverage](https://codeclimate.com/github/dry-rb/dry-logic/badges/coverage.svg)][codeclimate]
15
+ [![Inline docs](http://inch-ci.org/github/dry-rb/dry-logic.svg?branch=master)][inchpages]
16
16
 
17
17
  Predicate logic and rule composition used by:
18
18
 
19
- * [dry-data](https://github.com/dryrb/dry-data) for constrained types
20
- * [dry-validation](https://github.com/dryrb/dry-validation) for composing validation rules
19
+ * [dry-types](https://github.com/dry-rb/dry-types) for constrained types
20
+ * [dry-validation](https://github.com/dry-rb/dry-validation) for composing validation rules
21
21
  * your project...?
22
22
 
23
23
  ## Synopsis
@@ -2,9 +2,19 @@ module Dry
2
2
  module Logic
3
3
  class Result::Each < Result::Multi
4
4
  def to_ast
5
- failed_rules = failures.map { |el| [:el, [success.index(el), el.to_ast]] }
5
+ failed_rules = failures.map { |idx, el| [:el, [idx, el.to_ast]] }
6
6
  [:result, [rule.evaluate(input), [:each, failed_rules]]]
7
7
  end
8
+
9
+ def success?
10
+ response.values.all?(&:success?)
11
+ end
12
+
13
+ def failures
14
+ response.each_with_object({}) { |(idx, res), hash|
15
+ hash[idx] = res if res.failure?
16
+ }
17
+ end
8
18
  end
9
19
  end
10
20
  end
@@ -2,7 +2,7 @@ module Dry
2
2
  module Logic
3
3
  class Rule::Each < Rule::Value
4
4
  def apply(input)
5
- input.map { |element| predicate.(element) }
5
+ Hash[input.map.with_index { |element, index| [index, predicate.(element)] }]
6
6
  end
7
7
 
8
8
  def type
@@ -1,5 +1,5 @@
1
1
  module Dry
2
2
  module Logic
3
- VERSION = '0.2.0'.freeze
3
+ VERSION = '0.2.1'.freeze
4
4
  end
5
5
  end
@@ -16,5 +16,16 @@ RSpec.describe Dry::Logic::Rule::Each do
16
16
  expect(address_rule.([nil, 'Address'])).to be_failure
17
17
  expect(address_rule.([:Address, 'Address'])).to be_failure
18
18
  end
19
+
20
+ it 'returns result ast' do
21
+ expect(address_rule.([nil, nil]).to_ast).to eql([
22
+ :result, [[nil, nil], [
23
+ :each, [
24
+ [:el, [0, [:result, [nil, [:val, [:predicate, [:str?, []]]]]]]],
25
+ [:el, [1, [:result, [nil, [:val, [:predicate, [:str?, []]]]]]]]
26
+ ]
27
+ ]]
28
+ ])
29
+ end
19
30
  end
20
31
  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: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotr Solnica
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-11 00:00:00.000000000 Z
11
+ date: 2016-03-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-container