reform-rails 0.2.6 → 0.3.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 +87 -20
- data/.gitignore +1 -1
- data/CHANGES.md +5 -0
- data/Gemfile-rails5 +9 -0
- data/Gemfile-rails6.0 +9 -0
- data/Gemfile-rails6.1 +9 -0
- data/Gemfile-rails7.0 +9 -0
- data/Gemfile-rails7.1 +9 -0
- data/Gemfile-rails7.2 +9 -0
- data/Gemfile-rails8 +9 -0
- data/README.md +5 -4
- data/lib/reform/form/orm.rb +5 -1
- data/lib/reform/form/validation/unique_validator.rb +25 -1
- data/lib/reform/rails/version.rb +1 -1
- data/lib/reform/rails.rb +26 -0
- data/reform-rails.gemspec +3 -0
- metadata +52 -4
- data/Gemfile +0 -33
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 43ce92d480a18dfc398266771235ed677f949aaefef85fca362c787d49b3443b
|
4
|
+
data.tar.gz: f6d7d3f34e15f3ee674aacdba842cc0f42d43850f71dbc29d24704903342427a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 51d6a79615a1b7e4d191c80a3be1584f7e719f7c1907583600225c160938400ecdfac6b616440669f49c0b98bf3f36224bfb2f9a2355e94cd994be16355bfcf9
|
7
|
+
data.tar.gz: 95904bb3946944f63c6c802191dbd91b95e8d9d663a8dc2c8665ac1f94a9f863a729c27606e79be2e5cf960b6a4c8c54aa50a08be8357b6c354bf2e5522e4edd
|
data/.github/workflows/ci.yml
CHANGED
@@ -1,28 +1,95 @@
|
|
1
1
|
name: CI
|
2
|
+
|
2
3
|
on: [push, pull_request]
|
4
|
+
|
3
5
|
jobs:
|
4
|
-
test:
|
5
|
-
strategy:
|
6
|
-
fail-fast: false
|
7
|
-
matrix:
|
8
|
-
# Due to https://github.com/actions/runner/issues/849, we have to use quotes for '3.0'
|
9
|
-
ruby: [2.5, 2.6, 2.7, '3.0', head]
|
10
|
-
rails: ['6.1', '6.0', '5.2']
|
11
|
-
mongodb-version: ['4.4']
|
12
|
-
exclude:
|
13
|
-
- ruby: '3.0'
|
14
|
-
rails: 5.2
|
15
|
-
- ruby: head
|
16
|
-
rails: 5.2
|
6
|
+
test-rails5:
|
17
7
|
runs-on: ubuntu-latest
|
18
8
|
steps:
|
19
|
-
- uses: actions/checkout@
|
20
|
-
- uses: supercharge/mongodb-github-action@1.
|
9
|
+
- uses: actions/checkout@v5
|
10
|
+
- uses: supercharge/mongodb-github-action@1.12.0
|
21
11
|
with:
|
22
|
-
mongodb-version:
|
12
|
+
mongodb-version: "4.4"
|
23
13
|
- uses: ruby/setup-ruby@v1
|
24
14
|
with:
|
25
|
-
ruby-version:
|
26
|
-
|
27
|
-
- run:
|
28
|
-
|
15
|
+
ruby-version: "2.5"
|
16
|
+
- run: BUNDLE_GEMFILE=Gemfile-rails5 bundle install
|
17
|
+
- run: BUNDLE_GEMFILE=Gemfile-rails5 bundle exec rake
|
18
|
+
|
19
|
+
test-rails6_0:
|
20
|
+
runs-on: ubuntu-latest
|
21
|
+
steps:
|
22
|
+
- uses: actions/checkout@v5
|
23
|
+
- uses: supercharge/mongodb-github-action@1.12.0
|
24
|
+
with:
|
25
|
+
mongodb-version: "4.4"
|
26
|
+
- uses: ruby/setup-ruby@v1
|
27
|
+
with:
|
28
|
+
ruby-version: "2.6"
|
29
|
+
- run: BUNDLE_GEMFILE=Gemfile-rails6.0 bundle install
|
30
|
+
- run: BUNDLE_GEMFILE=Gemfile-rails6.0 bundle exec rake
|
31
|
+
|
32
|
+
test-rails6_1:
|
33
|
+
runs-on: ubuntu-latest
|
34
|
+
steps:
|
35
|
+
- uses: actions/checkout@v5
|
36
|
+
- uses: supercharge/mongodb-github-action@1.12.0
|
37
|
+
with:
|
38
|
+
mongodb-version: "4.4"
|
39
|
+
- uses: ruby/setup-ruby@v1
|
40
|
+
with:
|
41
|
+
ruby-version: "3.0"
|
42
|
+
- run: BUNDLE_GEMFILE=Gemfile-rails6.1 bundle install
|
43
|
+
- run: BUNDLE_GEMFILE=Gemfile-rails6.1 bundle exec rake
|
44
|
+
|
45
|
+
test-rails7_0:
|
46
|
+
runs-on: ubuntu-latest
|
47
|
+
steps:
|
48
|
+
- uses: actions/checkout@v5
|
49
|
+
- uses: supercharge/mongodb-github-action@1.12.0
|
50
|
+
with:
|
51
|
+
mongodb-version: "4.4"
|
52
|
+
- uses: ruby/setup-ruby@v1
|
53
|
+
with:
|
54
|
+
ruby-version: "3.0"
|
55
|
+
- run: BUNDLE_GEMFILE=Gemfile-rails7.0 bundle install
|
56
|
+
- run: BUNDLE_GEMFILE=Gemfile-rails7.0 bundle exec rake
|
57
|
+
|
58
|
+
test-rails7_1:
|
59
|
+
runs-on: ubuntu-latest
|
60
|
+
steps:
|
61
|
+
- uses: actions/checkout@v5
|
62
|
+
- uses: supercharge/mongodb-github-action@1.12.0
|
63
|
+
with:
|
64
|
+
mongodb-version: "4.4"
|
65
|
+
- uses: ruby/setup-ruby@v1
|
66
|
+
with:
|
67
|
+
ruby-version: "3.2"
|
68
|
+
- run: BUNDLE_GEMFILE=Gemfile-rails7.1 bundle install
|
69
|
+
- run: BUNDLE_GEMFILE=Gemfile-rails7.1 bundle exec rake
|
70
|
+
|
71
|
+
test-rails7_2:
|
72
|
+
runs-on: ubuntu-latest
|
73
|
+
steps:
|
74
|
+
- uses: actions/checkout@v5
|
75
|
+
- uses: supercharge/mongodb-github-action@1.12.0
|
76
|
+
with:
|
77
|
+
mongodb-version: "4.4"
|
78
|
+
- uses: ruby/setup-ruby@v1
|
79
|
+
with:
|
80
|
+
ruby-version: "3.3"
|
81
|
+
- run: BUNDLE_GEMFILE=Gemfile-rails7.2 bundle install
|
82
|
+
- run: BUNDLE_GEMFILE=Gemfile-rails7.2 bundle exec rake
|
83
|
+
|
84
|
+
test-rails8:
|
85
|
+
runs-on: ubuntu-latest
|
86
|
+
steps:
|
87
|
+
- uses: actions/checkout@v5
|
88
|
+
- uses: supercharge/mongodb-github-action@1.12.0
|
89
|
+
with:
|
90
|
+
mongodb-version: "4.4"
|
91
|
+
- uses: ruby/setup-ruby@v1
|
92
|
+
with:
|
93
|
+
ruby-version: "3.3"
|
94
|
+
- run: BUNDLE_GEMFILE=Gemfile-rails8 bundle install
|
95
|
+
- run: BUNDLE_GEMFILE=Gemfile-rails8 bundle exec rake
|
data/.gitignore
CHANGED
data/CHANGES.md
CHANGED
data/Gemfile-rails5
ADDED
data/Gemfile-rails6.0
ADDED
data/Gemfile-rails6.1
ADDED
data/Gemfile-rails7.0
ADDED
data/Gemfile-rails7.1
ADDED
data/Gemfile-rails7.2
ADDED
data/Gemfile-rails8
ADDED
data/README.md
CHANGED
@@ -28,14 +28,15 @@ Reform-rails needs Reform >= 2.3.
|
|
28
28
|
|
29
29
|
## Contributing
|
30
30
|
|
31
|
-
|
32
|
-
Please ensure that you test your changes against all supported ruby and rails versions (see .travis.yml)
|
31
|
+
Please ensure that you test your changes against all supported ruby and rails versions
|
33
32
|
|
34
33
|
You can run tests for a specific version of rails by running the following:
|
35
34
|
|
36
|
-
|
35
|
+
```shell
|
36
|
+
BUNDLE_GEMFILE=Gemfile-rails7.0 bundle install
|
37
|
+
BUNDLE_GEMFILE=Gemfile-rails7.0 bundle exec rake test
|
38
|
+
```
|
37
39
|
|
38
40
|
## License
|
39
41
|
|
40
42
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
41
|
-
|
data/lib/reform/form/orm.rb
CHANGED
@@ -20,7 +20,11 @@ module Reform::Form::ORM
|
|
20
20
|
@klass = record.class # this is usually done in the super-sucky #setup method.
|
21
21
|
super(record).tap do |res|
|
22
22
|
if record.errors.present?
|
23
|
-
error =
|
23
|
+
error = if Gem::Version.new(ActiveModel::VERSION::STRING) >= Gem::Version.new('6.1.0')
|
24
|
+
self.class.name.include?("Mongoid") ? record.errors.first.type : :taken
|
25
|
+
else
|
26
|
+
self.class.name.include?("Mongoid") ? record.errors.first.last : :taken
|
27
|
+
end
|
24
28
|
form.errors.add(property, error)
|
25
29
|
end
|
26
30
|
end
|
@@ -14,7 +14,7 @@
|
|
14
14
|
# validates :title, unique: { case_sensitive: false }
|
15
15
|
#
|
16
16
|
# = Scope
|
17
|
-
# A scope can be
|
17
|
+
# A scope can be used to filter the records that need to be compare with the
|
18
18
|
# current value to validate. A scope array can have one to many fields define.
|
19
19
|
#
|
20
20
|
# A scope can be define the following ways:
|
@@ -33,6 +33,20 @@
|
|
33
33
|
# This use case is useful if album_id is set to a Song this way:
|
34
34
|
# song = album.songs.new
|
35
35
|
# album_id is automatically set and can't be change by the operation
|
36
|
+
#
|
37
|
+
# = Conditions
|
38
|
+
# A condition can be passed to filter the records with partial indexes
|
39
|
+
#
|
40
|
+
# Conditions can be define the following ways:
|
41
|
+
# validates :title, unique: { conditions: -> { where(archived_at: nil) } }
|
42
|
+
# - This will check that the title is unique for non archived records
|
43
|
+
# validates :title, unique: {
|
44
|
+
# conditions: ->(record) {
|
45
|
+
# published_at = record.published_at
|
46
|
+
# where(published_at: published_at.beginning_of_year..published_at.end_of_year)
|
47
|
+
# }
|
48
|
+
# }
|
49
|
+
#
|
36
50
|
|
37
51
|
class Reform::Form::UniqueValidator < ActiveModel::EachValidator
|
38
52
|
def validate_each(form, attribute, value)
|
@@ -57,6 +71,16 @@ class Reform::Form::UniqueValidator < ActiveModel::EachValidator
|
|
57
71
|
query = query.where(field => form.send(field))
|
58
72
|
end
|
59
73
|
|
74
|
+
if options[:conditions]
|
75
|
+
conditions = options[:conditions]
|
76
|
+
|
77
|
+
query = if conditions.arity.zero?
|
78
|
+
query.instance_exec(&conditions)
|
79
|
+
else
|
80
|
+
query.instance_exec(form, &conditions)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
60
84
|
form.errors.add(attribute, :taken) if query.count > 0
|
61
85
|
end
|
62
86
|
end
|
data/lib/reform/rails/version.rb
CHANGED
data/lib/reform/rails.rb
CHANGED
@@ -4,3 +4,29 @@ require "reform/rails/railtie"
|
|
4
4
|
|
5
5
|
module Reform
|
6
6
|
end
|
7
|
+
|
8
|
+
module ActiveModel
|
9
|
+
module Validations
|
10
|
+
class AcceptanceValidator < EachValidator # :nodoc:
|
11
|
+
def initialize(options)
|
12
|
+
super({ allow_nil: true, accept: ["1", true] }.merge!(options))
|
13
|
+
end
|
14
|
+
|
15
|
+
def validate_each(record, attribute, value)
|
16
|
+
unless acceptable_option?(value)
|
17
|
+
if Gem::Version.new(ActiveModel::VERSION::STRING) >= Gem::Version.new('6.1.0')
|
18
|
+
record.errors.add(attribute, :accepted, **options.except(:accept, :allow_nil))
|
19
|
+
else
|
20
|
+
record.errors.add(attribute, :accepted, options.except(:accept, :allow_nil))
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def acceptable_option?(value)
|
28
|
+
Array(options[:accept]).include?(value)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/reform-rails.gemspec
CHANGED
@@ -22,4 +22,7 @@ Gem::Specification.new do |spec|
|
|
22
22
|
|
23
23
|
spec.add_dependency "reform", ">= 2.3.1", "< 3.0.0"
|
24
24
|
spec.add_dependency "activemodel", ">= 5.0"
|
25
|
+
spec.add_development_dependency "minitest"
|
26
|
+
spec.add_development_dependency "minitest-line"
|
27
|
+
spec.add_development_dependency "debug"
|
25
28
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: reform-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nick Sutterer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-08-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: reform
|
@@ -44,6 +44,48 @@ dependencies:
|
|
44
44
|
- - ">="
|
45
45
|
- !ruby/object:Gem::Version
|
46
46
|
version: '5.0'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: minitest
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: minitest-line
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: debug
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
47
89
|
description: Automatically load and include all common Reform features for a standard
|
48
90
|
Rails environment.
|
49
91
|
email:
|
@@ -55,7 +97,13 @@ files:
|
|
55
97
|
- ".github/workflows/ci.yml"
|
56
98
|
- ".gitignore"
|
57
99
|
- CHANGES.md
|
58
|
-
- Gemfile
|
100
|
+
- Gemfile-rails5
|
101
|
+
- Gemfile-rails6.0
|
102
|
+
- Gemfile-rails6.1
|
103
|
+
- Gemfile-rails7.0
|
104
|
+
- Gemfile-rails7.1
|
105
|
+
- Gemfile-rails7.2
|
106
|
+
- Gemfile-rails8
|
59
107
|
- LICENSE.txt
|
60
108
|
- README.md
|
61
109
|
- Rakefile
|
@@ -95,7 +143,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
95
143
|
- !ruby/object:Gem::Version
|
96
144
|
version: '0'
|
97
145
|
requirements: []
|
98
|
-
rubygems_version: 3.
|
146
|
+
rubygems_version: 3.0.3.1
|
99
147
|
signing_key:
|
100
148
|
specification_version: 4
|
101
149
|
summary: Automatically load and include all common Rails form features.
|
data/Gemfile
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
git_source(:github) do |repo_name|
|
2
|
-
repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
|
3
|
-
"https://github.com/#{repo_name}.git"
|
4
|
-
end
|
5
|
-
|
6
|
-
source "https://rubygems.org"
|
7
|
-
gemspec
|
8
|
-
|
9
|
-
# gem 'pry-byebug'
|
10
|
-
gem "minitest-line"
|
11
|
-
|
12
|
-
case ENV["GEMS_SOURCE"]
|
13
|
-
when "local"
|
14
|
-
gem "reform", path: "../reform"
|
15
|
-
when "github"
|
16
|
-
gem "reform", github: "trailblazer/reform"
|
17
|
-
end
|
18
|
-
|
19
|
-
rails_version = ENV.fetch("RAILS_VERSION", "6.0.0")
|
20
|
-
|
21
|
-
# bored of wrestling with rails...
|
22
|
-
|
23
|
-
gem("mongoid", "< 7.0") unless rails_version.to_i >= 6
|
24
|
-
|
25
|
-
|
26
|
-
gem "activerecord", "~> #{rails_version}"
|
27
|
-
gem "railties", "~> #{rails_version}"
|
28
|
-
if rails_version.to_i >= 6
|
29
|
-
gem "sqlite3", "~> 1.4"
|
30
|
-
else
|
31
|
-
gem "sqlite3", "~> 1.3", "< 1.4"
|
32
|
-
end
|
33
|
-
puts "Rails version #{rails_version}"
|