tram-policy 2.0.0 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +44 -0
- data/.rubocop.yml +1 -1
- data/CHANGELOG.md +19 -0
- data/README.md +0 -2
- data/lib/tram/policy/dsl.rb +3 -3
- data/lib/tram/policy/error.rb +3 -3
- data/lib/tram/policy/errors.rb +3 -3
- data/lib/tram/policy/rspec.rb +1 -1
- data/lib/tram/policy.rb +1 -1
- data/spec/tram/policy/error_spec.rb +1 -1
- data/tram-policy.gemspec +2 -2
- metadata +5 -5
- data/.travis.yml +0 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ee9ed362efd81c55cfe3097f6188f8da61af5b3ec78eee0eb6e5182bbfd62245
|
4
|
+
data.tar.gz: f2ab09546f5c6c5a70fca9459b1e2658dab85b0b2f9ffd27685ba61b00c62f06
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4ff7aaa1632158f2c5664b7bd492cd3a0f7d574f91c7232a97fb2a45b8ebdaf4923578716d805b56c66098ab4ddb7dbe2a2a506832f42d5a03c2e4128675acb4
|
7
|
+
data.tar.gz: 8d28126a3d030a3b7ff4a59e11f3444865bb634358997fd690af1117380b9001d2221b40456d2a727cd32ba2fd0ed2a03fd6eef3618caa13e3e068f5427f8da5
|
@@ -0,0 +1,44 @@
|
|
1
|
+
name: CI
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches:
|
6
|
+
- master
|
7
|
+
pull_request:
|
8
|
+
branches:
|
9
|
+
- "*"
|
10
|
+
|
11
|
+
jobs:
|
12
|
+
build:
|
13
|
+
name: Ruby ${{ matrix.ruby }}
|
14
|
+
|
15
|
+
strategy:
|
16
|
+
fail-fast: true
|
17
|
+
matrix:
|
18
|
+
ruby:
|
19
|
+
- "2.5.0"
|
20
|
+
- "3.0.0"
|
21
|
+
- "head"
|
22
|
+
|
23
|
+
runs-on: ubuntu-latest
|
24
|
+
|
25
|
+
steps:
|
26
|
+
- name: Checkout
|
27
|
+
uses: actions/checkout@v2
|
28
|
+
|
29
|
+
- name: Install dependent libraries
|
30
|
+
run: sudo apt-get install libpq-dev
|
31
|
+
|
32
|
+
- name: Install Ruby ${{ matrix.ruby }}
|
33
|
+
uses: ruby/setup-ruby@v1.61.1
|
34
|
+
with:
|
35
|
+
ruby-version: ${{ matrix.ruby }}
|
36
|
+
bundler-cache: true # 'bundle install' and cache
|
37
|
+
|
38
|
+
- name: Check code style
|
39
|
+
run: bundle exec rubocop
|
40
|
+
continue-on-error: false
|
41
|
+
|
42
|
+
- name: Run tests
|
43
|
+
run: bundle exec rake --trace
|
44
|
+
continue-on-error: false
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,22 @@ 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
|
+
## [2.2.0] - [2022-06-18]
|
8
|
+
|
9
|
+
### Added
|
10
|
+
- Support for Ruby 3+ (HolyWalley)
|
11
|
+
|
12
|
+
## [2.1.0] - [2021-11-30]
|
13
|
+
|
14
|
+
### Fixed
|
15
|
+
- Difference between last positional and keyword arguments in Ruby 3.0+ (mrexox)
|
16
|
+
|
17
|
+
## [2.0.1] - [2019-11-14]
|
18
|
+
|
19
|
+
### Fixed
|
20
|
+
- Allow translation :scope to be customized in the #merge operation (sclinede)
|
21
|
+
Before the fix, the customized value was always replaced by the default value.
|
22
|
+
|
7
23
|
## [2.0.0] - [2019-07-04]
|
8
24
|
|
9
25
|
### Changed
|
@@ -212,3 +228,6 @@ This is a first public release (@nepalez, @charlie-wasp, @JewelSam, @sergey-chec
|
|
212
228
|
[1.0.0]: https://github.com/tram-rb/tram-policy/compare/v0.4.0...v1.0.0
|
213
229
|
[1.0.1]: https://github.com/tram-rb/tram-policy/compare/v1.0.0...v1.0.1
|
214
230
|
[2.0.0]: https://github.com/tram-rb/tram-policy/compare/v1.0.1...v2.0.0
|
231
|
+
[2.0.1]: https://github.com/tram-rb/tram-policy/compare/v2.0.0...v2.0.1
|
232
|
+
[2.1.0]: https://github.com/tram-rb/tram-policy/compare/v2.0.1...v2.1.0
|
233
|
+
[2.1.0]: https://github.com/tram-rb/tram-policy/compare/v2.1.0...v2.2.0
|
data/README.md
CHANGED
@@ -6,7 +6,6 @@ Policy Object Pattern
|
|
6
6
|
<img src="https://evilmartians.com/badges/sponsored-by-evil-martians.svg" alt="Sponsored by Evil Martians" width="236" height="54"></a>
|
7
7
|
|
8
8
|
[![Gem Version][gem-badger]][gem]
|
9
|
-
[![Build Status][travis-badger]][travis]
|
10
9
|
[![Inline docs][inch-badger]][inch]
|
11
10
|
|
12
11
|
## Intro
|
@@ -340,7 +339,6 @@ The gem is available as open source under the terms of the [MIT License](http://
|
|
340
339
|
[inch-badger]: http://inch-ci.org/github/tram-rb/tram-policy.svg
|
341
340
|
[inch]: https://inch-ci.org/github/tram-rb/tram-policy
|
342
341
|
[travis-badger]: https://img.shields.io/travis/tram-rb/tram-policy/master.svg?style=flat
|
343
|
-
[travis]: https://travis-ci.org/tram-rb/tram-policy
|
344
342
|
[active-model-validation]: http://api.rubyonrails.org/classes/ActiveModel/Validations.html
|
345
343
|
[active-record-validation]: http://guides.rubyonrails.org/active_record_validations.html
|
346
344
|
[dry-validation]: http://dry-rb.org/gems/dry-validation/
|
data/lib/tram/policy/dsl.rb
CHANGED
@@ -9,7 +9,7 @@ class Tram::Policy
|
|
9
9
|
# @return [self]
|
10
10
|
#
|
11
11
|
def validate(name = nil, **opts, &block)
|
12
|
-
local_validators << Validator.new(name, block, opts)
|
12
|
+
local_validators << Validator.new(name, block, **opts)
|
13
13
|
self
|
14
14
|
end
|
15
15
|
|
@@ -18,8 +18,8 @@ class Tram::Policy
|
|
18
18
|
# @param [Object] *args
|
19
19
|
# @return [Tram::Policy]
|
20
20
|
#
|
21
|
-
def [](*args)
|
22
|
-
new(*args)
|
21
|
+
def [](*args, **kwargs)
|
22
|
+
new(*args, **kwargs)
|
23
23
|
end
|
24
24
|
|
25
25
|
# Sets the root scope of the policy and its subclasses
|
data/lib/tram/policy/error.rb
CHANGED
@@ -41,7 +41,7 @@ class Tram::Policy
|
|
41
41
|
# @return [String]
|
42
42
|
#
|
43
43
|
def message
|
44
|
-
key.is_a?(Symbol) ? I18n.t(
|
44
|
+
key.is_a?(Symbol) ? I18n.t(key, **tags) : key.to_s
|
45
45
|
end
|
46
46
|
|
47
47
|
# Fetches an option
|
@@ -105,8 +105,8 @@ class Tram::Policy
|
|
105
105
|
true
|
106
106
|
end
|
107
107
|
|
108
|
-
def method_missing(name, *args, &block)
|
109
|
-
args.any? || block ? super : tags[name]
|
108
|
+
def method_missing(name, *args, **kwargs, &block)
|
109
|
+
args.any? || kwargs.any? || block ? super : tags[name]
|
110
110
|
end
|
111
111
|
end
|
112
112
|
end
|
data/lib/tram/policy/errors.rb
CHANGED
@@ -24,7 +24,7 @@ class Tram::Policy
|
|
24
24
|
raise ArgumentError.new("Error message should be defined") unless message
|
25
25
|
|
26
26
|
tap do
|
27
|
-
tags =
|
27
|
+
tags = { scope: scope }.merge(tags) if message.is_a?(Symbol)
|
28
28
|
@set << Tram::Policy::Error.new(message, **tags)
|
29
29
|
end
|
30
30
|
end
|
@@ -47,7 +47,7 @@ class Tram::Policy
|
|
47
47
|
#
|
48
48
|
def filter(key = nil, **tags)
|
49
49
|
list = each_with_object(Set.new) do |error, obj|
|
50
|
-
obj << error if error.contain?(key, tags)
|
50
|
+
obj << error if error.contain?(key, **tags)
|
51
51
|
end
|
52
52
|
self.class.new(scope: scope, errors: list)
|
53
53
|
end
|
@@ -95,7 +95,7 @@ class Tram::Policy
|
|
95
95
|
other.each do |err|
|
96
96
|
key, opts = err.item
|
97
97
|
opts = yield(opts) if block_given?
|
98
|
-
add key, opts.merge(options)
|
98
|
+
add key, **opts.merge(options)
|
99
99
|
end
|
100
100
|
|
101
101
|
self
|
data/lib/tram/policy/rspec.rb
CHANGED
@@ -6,7 +6,7 @@ RSpec::Matchers.define :be_invalid_at do |**tags|
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def check(policy, tags)
|
9
|
-
@errors ||= policy.errors.filter(tags).map do |error|
|
9
|
+
@errors ||= policy.errors.filter(**tags).map do |error|
|
10
10
|
{ item: error.item }.tap do |obj|
|
11
11
|
locales.each { |l| obj[l] = I18n.with_locale(l) { error.message } }
|
12
12
|
end
|
data/lib/tram/policy.rb
CHANGED
data/tram-policy.gemspec
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
Gem::Specification.new do |gem|
|
2
2
|
gem.name = "tram-policy"
|
3
|
-
gem.version = "2.
|
3
|
+
gem.version = "2.2.0"
|
4
4
|
gem.author = ["Viktor Sokolov (gzigzigzeo)", "Andrew Kozin (nepalez)"]
|
5
5
|
gem.email = "andrew.kozin@gmail.com"
|
6
|
-
gem.homepage = "https://github.com/tram/tram-policy"
|
6
|
+
gem.homepage = "https://github.com/tram-rb/tram-policy"
|
7
7
|
gem.summary = "Policy Object Pattern"
|
8
8
|
gem.license = "MIT"
|
9
9
|
|
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: 2.
|
4
|
+
version: 2.2.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:
|
12
|
+
date: 2022-06-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: dry-initializer
|
@@ -125,10 +125,10 @@ extra_rdoc_files:
|
|
125
125
|
- CHANGELOG.md
|
126
126
|
files:
|
127
127
|
- ".codeclimate.yml"
|
128
|
+
- ".github/workflows/ci.yml"
|
128
129
|
- ".gitignore"
|
129
130
|
- ".rspec"
|
130
131
|
- ".rubocop.yml"
|
131
|
-
- ".travis.yml"
|
132
132
|
- CHANGELOG.md
|
133
133
|
- Gemfile
|
134
134
|
- LICENSE.txt
|
@@ -160,7 +160,7 @@ files:
|
|
160
160
|
- spec/tram/policy/validation_error_spec.rb
|
161
161
|
- spec/tram/policy_spec.rb
|
162
162
|
- tram-policy.gemspec
|
163
|
-
homepage: https://github.com/tram/tram-policy
|
163
|
+
homepage: https://github.com/tram-rb/tram-policy
|
164
164
|
licenses:
|
165
165
|
- MIT
|
166
166
|
metadata: {}
|
@@ -179,7 +179,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
179
179
|
- !ruby/object:Gem::Version
|
180
180
|
version: '0'
|
181
181
|
requirements: []
|
182
|
-
rubygems_version: 3.
|
182
|
+
rubygems_version: 3.2.3
|
183
183
|
signing_key:
|
184
184
|
specification_version: 4
|
185
185
|
summary: Policy Object Pattern
|
data/.travis.yml
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
---
|
2
|
-
language: ruby
|
3
|
-
sudo: false
|
4
|
-
cache: bundler
|
5
|
-
bundler_args: --without benchmarks tools
|
6
|
-
script:
|
7
|
-
- bundle exec rake
|
8
|
-
- bundle exec rubocop
|
9
|
-
rvm:
|
10
|
-
- 2.3.0
|
11
|
-
- 2.6.2
|
12
|
-
- ruby-head
|
13
|
-
- jruby-9.2.7.0
|
14
|
-
- truffleruby
|
15
|
-
env:
|
16
|
-
global:
|
17
|
-
- JRUBY_OPTS='--dev -J-Xmx1024M'
|
18
|
-
matrix:
|
19
|
-
allow_failures:
|
20
|
-
- rvm: ruby-head
|
21
|
-
- rvm: jruby-head
|
22
|
-
- rvm: truffleruby
|