tram-policy 0.2.5 → 0.3.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
  SHA1:
3
- metadata.gz: 3913b597392415b305007f399b5317685104cccb
4
- data.tar.gz: 743ffbff684480d4f679babae66553747b12824f
3
+ metadata.gz: 30e038480a8f83d0dbca7d8f6020c98ed083ec0d
4
+ data.tar.gz: e991d7c12a0535892491612d6530fede02527816
5
5
  SHA512:
6
- metadata.gz: 12e2a5195230cf121e840bc72912818a5368602aa0380a3899dc516ccf1524780b45633cc319dbc8d14f3ca1cccd77b7a45a9aa79d1939b39d6a19e9b761d4b8
7
- data.tar.gz: 71fba806cb08df6b02d51d690169e7b53bb3b097e456e4b21d25cee6d8a7570aec1ca64fb3b66ee329e19bde902076fd065c85236f2efd2df9e523243bc11e18
6
+ metadata.gz: 589f343a85a7e02e64e0cf7322de87ba5bda694a2deaca139b48af6427f266f82fbb25c50d3d1fb42d3fda9e6bbfb0718b339afea05dd252e790fc721c2e398d
7
+ data.tar.gz: 04f3bde859bce4d67981c67ef00d356805ff1c6e1a3ac7cf453cd632eb45d526fc64f17c7a45ab27e83b2495ded610299121f3c4af010fda7b6e418ef15cb61c
data/CHANGELOG.md CHANGED
@@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
4
4
  The format is based on [Keep a Changelog](http://keepachangelog.com/)
5
5
  and this project adheres to [Semantic Versioning](http://semver.org/).
6
6
 
7
+ ## [0.3.0] - [2018-01-05]
8
+
9
+ ### Added
10
+ - Allow returning from block in `validate` by using lambdas (nepalez)
11
+
7
12
  ## [0.2.5] - [2018-01-05]
8
13
 
9
14
  ### Added
@@ -129,3 +134,6 @@ This is a first public release (@nepalez, @charlie-wasp, @JewelSam, @sergey-chec
129
134
  [0.2.1]: https://github.com/tram-rb/tram-policy/compare/v0.2.0...v0.2.1
130
135
  [0.2.2]: https://github.com/tram-rb/tram-policy/compare/v0.2.1...v0.2.2
131
136
  [0.2.3]: https://github.com/tram-rb/tram-policy/compare/v0.2.2...v0.2.3
137
+ [0.2.4]: https://github.com/tram-rb/tram-policy/compare/v0.2.3...v0.2.4
138
+ [0.2.5]: https://github.com/tram-rb/tram-policy/compare/v0.2.4...v0.2.5
139
+ [0.3.0]: https://github.com/tram-rb/tram-policy/compare/v0.2.5...v0.3.0
data/README.md CHANGED
@@ -42,7 +42,10 @@ class Article::ReadinessPolicy < Tram::Policy
42
42
  # define what methods and in what order we should use to validate an article
43
43
  validate :title_presence
44
44
  validate :subtitle_presence
45
- validate { errors.add :empty, field: "text", level: "error" if text.empty? }
45
+ validate do # use anonymous lambda
46
+ return unless text.empty?
47
+ errors.add :empty, field: "text", level: "error"
48
+ end
46
49
 
47
50
  private
48
51
 
@@ -15,7 +15,7 @@ class Tram::Policy
15
15
 
16
16
  def initialize(name, block, stop_on_failure: false)
17
17
  @name = name&.to_sym
18
- @block = block
18
+ @block = lambda(&block) if block
19
19
  raise "Provide either method name or a block" unless !name ^ !block
20
20
  @stop_on_failure = stop_on_failure
21
21
  end
@@ -1,5 +1,8 @@
1
1
  class Test::CustomerPolicy < Tram::Policy
2
2
  option :name
3
3
 
4
- validate { errors.add :name_presence, field: "name" unless name }
4
+ validate do
5
+ return if name
6
+ errors.add :name_presence, field: "name"
7
+ end
5
8
  end
data/tram-policy.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |gem|
2
2
  gem.name = "tram-policy"
3
- gem.version = "0.2.5"
3
+ gem.version = "0.3.0"
4
4
  gem.author = ["Viktor Sokolov (gzigzigzeo)", "Andrew Kozin (nepalez)"]
5
5
  gem.email = "andrew.kozin@gmail.com"
6
6
  gem.homepage = "https://github.com/tram/tram-policy"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tram-policy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Viktor Sokolov (gzigzigzeo)
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-01-04 00:00:00.000000000 Z
12
+ date: 2018-01-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: dry-initializer