array_enum 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +38 -0
- data/Gemfile.lock +11 -11
- data/README.md +2 -2
- data/lib/array_enum.rb +1 -1
- data/lib/array_enum/subset_validator.rb +3 -1
- data/lib/array_enum/version.rb +1 -1
- metadata +4 -4
- data/.travis.yml +0 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b4f3ef7689bbd8ab0f1fd27d9c1157e40764fd6f991217f64937f903e058753d
|
4
|
+
data.tar.gz: 377266d5f7da9332e61bc7cc825e5db419a76d2c2193b13474027c83fb3b18ef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 06404fcc83bf4b4b1a3ddc3718f1cee0f260a0572c97955e1b0184005950df32f2149e2175e55d20cb8e7f562e905e081fe1499a6007d8d9f22f16cf3f52a3b1
|
7
|
+
data.tar.gz: fd070af7976fdf52f4f5a6672e51172afa51a781e80a07ddf6f4f9a9183249cdf42dd52b61ad92f4cdb284cfa6adc487bf64ef2c41d52ac75e3e7c4d06365534
|
@@ -0,0 +1,38 @@
|
|
1
|
+
name: CI
|
2
|
+
|
3
|
+
on: [push, pull_request]
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
build:
|
7
|
+
runs-on: ubuntu-latest
|
8
|
+
services:
|
9
|
+
postgres:
|
10
|
+
image: postgres:11
|
11
|
+
ports:
|
12
|
+
- 5432:5432
|
13
|
+
env:
|
14
|
+
POSTGRES_PASSWORD: ""
|
15
|
+
|
16
|
+
steps:
|
17
|
+
- name: Install libraries
|
18
|
+
run: |
|
19
|
+
sudo apt-get update
|
20
|
+
sudo apt-get install -y libpq-dev postgresql-client
|
21
|
+
|
22
|
+
- name: Configure database
|
23
|
+
run: |
|
24
|
+
echo "PostgreSQL"
|
25
|
+
psql -h localhost -c 'create database "array_enum_test";' -U postgres
|
26
|
+
|
27
|
+
- uses: actions/checkout@v1
|
28
|
+
|
29
|
+
- name: Set up Ruby
|
30
|
+
uses: actions/setup-ruby@v1
|
31
|
+
with:
|
32
|
+
ruby-version: 2.6.x
|
33
|
+
|
34
|
+
- name: Build and test
|
35
|
+
run: |
|
36
|
+
gem install bundler
|
37
|
+
bundle install --jobs 4 --retry 3
|
38
|
+
bundle exec rake test
|
data/Gemfile.lock
CHANGED
@@ -1,33 +1,33 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
array_enum (1.
|
4
|
+
array_enum (1.2.0)
|
5
5
|
activemodel
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
activemodel (
|
11
|
-
activesupport (=
|
12
|
-
activerecord (
|
13
|
-
activemodel (=
|
14
|
-
activesupport (=
|
15
|
-
|
16
|
-
activesupport (5.2.3)
|
10
|
+
activemodel (6.0.0)
|
11
|
+
activesupport (= 6.0.0)
|
12
|
+
activerecord (6.0.0)
|
13
|
+
activemodel (= 6.0.0)
|
14
|
+
activesupport (= 6.0.0)
|
15
|
+
activesupport (6.0.0)
|
17
16
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
18
17
|
i18n (>= 0.7, < 2)
|
19
18
|
minitest (~> 5.1)
|
20
19
|
tzinfo (~> 1.1)
|
21
|
-
|
20
|
+
zeitwerk (~> 2.1, >= 2.1.8)
|
22
21
|
concurrent-ruby (1.1.5)
|
23
22
|
i18n (1.6.0)
|
24
23
|
concurrent-ruby (~> 1.0)
|
25
24
|
minitest (5.11.3)
|
26
25
|
pg (1.1.4)
|
27
|
-
rake (12.3.
|
26
|
+
rake (12.3.3)
|
28
27
|
thread_safe (0.3.6)
|
29
28
|
tzinfo (1.2.5)
|
30
29
|
thread_safe (~> 0.1)
|
30
|
+
zeitwerk (2.1.9)
|
31
31
|
|
32
32
|
PLATFORMS
|
33
33
|
ruby
|
@@ -41,4 +41,4 @@ DEPENDENCIES
|
|
41
41
|
rake (>= 10.0)
|
42
42
|
|
43
43
|
BUNDLED WITH
|
44
|
-
|
44
|
+
2.0.2
|
data/README.md
CHANGED
@@ -43,6 +43,8 @@ class CreateUser
|
|
43
43
|
attr_accessor :favourite_colors
|
44
44
|
|
45
45
|
validates :favourite_colors, subset: ["green", "blue"]
|
46
|
+
# or:
|
47
|
+
# validates :favourite_colors, subset: { in: ->(record) { Color.pluck(:name) } }
|
46
48
|
end
|
47
49
|
|
48
50
|
CreateUser.new(favourite_colors: ["black"]).valid? # => false
|
@@ -50,8 +52,6 @@ CreateUser.new(favourite_colors: ["black"]).valid? # => false
|
|
50
52
|
|
51
53
|
## Development
|
52
54
|
|
53
|
-
[](https://travis-ci.com/freeletics/array_enum)
|
54
|
-
|
55
55
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
56
56
|
|
57
57
|
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
data/lib/array_enum.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require "array_enum/version"
|
2
2
|
require "array_enum/subset_validator"
|
3
|
-
require "array_enum/railtie" if defined?(Rails)
|
3
|
+
require "array_enum/railtie" if defined?(Rails::Railtie)
|
4
4
|
require "active_support/hash_with_indifferent_access"
|
5
5
|
require "active_support/core_ext/string/inflections"
|
6
6
|
|
@@ -3,7 +3,9 @@ require "active_model/validator"
|
|
3
3
|
class ArrayEnum::SubsetValidator < ActiveModel::EachValidator
|
4
4
|
def validate_each(record, attribute, value)
|
5
5
|
wrapped_value = [value].flatten # Handles nil value
|
6
|
-
|
6
|
+
subset = delimiter.respond_to?(:call) ? delimiter.call(record) : delimiter
|
7
|
+
|
8
|
+
diff = wrapped_value.reject { |element| subset.include?(element) }
|
7
9
|
|
8
10
|
unless diff.empty?
|
9
11
|
record.errors.add(attribute, :inclusion, options.except(:in, :within).merge!(value: diff))
|
data/lib/array_enum/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: array_enum
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Wojciech Wnętrzak
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-09-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -103,8 +103,8 @@ executables: []
|
|
103
103
|
extensions: []
|
104
104
|
extra_rdoc_files: []
|
105
105
|
files:
|
106
|
+
- ".github/workflows/ci.yml"
|
106
107
|
- ".gitignore"
|
107
|
-
- ".travis.yml"
|
108
108
|
- Gemfile
|
109
109
|
- Gemfile.lock
|
110
110
|
- LICENSE.txt
|
@@ -138,7 +138,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
138
138
|
- !ruby/object:Gem::Version
|
139
139
|
version: '0'
|
140
140
|
requirements: []
|
141
|
-
rubygems_version: 3.0.
|
141
|
+
rubygems_version: 3.0.6
|
142
142
|
signing_key:
|
143
143
|
specification_version: 4
|
144
144
|
summary: String to integer mapping for PostgreSQL array columns.
|
data/.travis.yml
DELETED