formeze 3.1.0 → 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.md +8 -0
- data/README.md +15 -11
- data/formeze.gemspec +3 -3
- data/lib/formeze.rb +26 -16
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 966031b2657f2210d398a97d3c8dd6a1cc4e424e39972db1c3bad968cfe3bc8e
|
4
|
+
data.tar.gz: 140936f1897241dc7ee598fd8e63296d3d7918879dd263d825e68299897e1a1f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '092df6a16316cd7fb65f997e3e25e65622a1e8e112a5da8db6c56ca4146dc4485502fcc1ed7b9cb6a34e452878e3a6151a7c3c7c47e759ef7fe6349d35f5c1e4'
|
7
|
+
data.tar.gz: 0b4641a90d0d9e7e0cface189b699f12ebd60e94de2350a7dcbee537be6e22bd8b721587199ce3e24202ea5ccb8c1083438abd9bfa5d55538556825e08cbe0bc
|
data/CHANGES.md
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
# 4.0.0
|
2
|
+
|
3
|
+
* Removed support for older rubies. **Required ruby version is now 2.4.0**
|
4
|
+
|
5
|
+
* Changed the code to use keyword arguments for options
|
6
|
+
|
7
|
+
* Renamed the `when` validation option to `if`
|
8
|
+
|
1
9
|
# 3.1.0
|
2
10
|
|
3
11
|
* Added `'commit'` to the list of Rails form keys to ignore (#4)
|
data/README.md
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
![Gem Version](https://badge.fury.io/rb/formeze.svg)
|
4
4
|
![Build Status](https://github.com/readysteady/formeze/workflows/Test/badge.svg)
|
5
5
|
|
6
|
-
|
6
|
+
Ruby gem for validating form data.
|
7
7
|
|
8
8
|
|
9
9
|
## Motivation
|
@@ -18,14 +18,18 @@ Formeze adopts the approach of being "strict by default", forcing the applicatio
|
|
18
18
|
code to be explicit in what it accepts as input.
|
19
19
|
|
20
20
|
|
21
|
-
##
|
21
|
+
## Install
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
|
23
|
+
Using Bundler:
|
24
|
+
|
25
|
+
$ bundle add formeze
|
26
|
+
|
27
|
+
Using RubyGems:
|
28
|
+
|
29
|
+
$ gem install formeze
|
26
30
|
|
27
31
|
|
28
|
-
##
|
32
|
+
## Usage
|
29
33
|
|
30
34
|
Here is a minimal example, which defines a form with a single field:
|
31
35
|
|
@@ -254,16 +258,16 @@ class ExampleForm < Formeze::Form
|
|
254
258
|
end
|
255
259
|
```
|
256
260
|
|
257
|
-
Specify the `
|
261
|
+
Specify the `if` option with a proc to peform the validation conditionally.
|
258
262
|
Similar to the `defined_if` and `defined_unless` field options, the proc is
|
259
263
|
evaluated in the scope of the form instance. For example:
|
260
264
|
|
261
265
|
```ruby
|
262
266
|
class ExampleForm < Formeze::Form
|
263
|
-
field :business_name, :
|
264
|
-
field :vat_number, :
|
267
|
+
field :business_name, defined_if: :business_account?
|
268
|
+
field :vat_number, defined_if: :business_account?
|
265
269
|
|
266
|
-
validates :vat_number, :
|
270
|
+
validates :vat_number, if: :business_account? do
|
267
271
|
# ...
|
268
272
|
end
|
269
273
|
|
@@ -290,7 +294,7 @@ class ExampleForm < Formeze::Form
|
|
290
294
|
|
291
295
|
validates :email, &EmailAddress.method(:valid?)
|
292
296
|
|
293
|
-
validates :password_confirmation, :
|
297
|
+
validates :password_confirmation, error: :does_not_match do
|
294
298
|
password_confirmation == password
|
295
299
|
end
|
296
300
|
end
|
data/formeze.gemspec
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'formeze'
|
3
|
-
s.version = '
|
3
|
+
s.version = '4.0.0'
|
4
4
|
s.license = 'LGPL-3.0'
|
5
5
|
s.platform = Gem::Platform::RUBY
|
6
6
|
s.authors = ['Tim Craft']
|
7
7
|
s.email = ['mail@timcraft.com']
|
8
8
|
s.homepage = 'https://github.com/readysteady/formeze'
|
9
|
-
s.description = '
|
9
|
+
s.description = 'Ruby gem for validating form data'
|
10
10
|
s.summary = 'See description'
|
11
11
|
s.files = Dir.glob('lib/**/*.rb') + %w(CHANGES.md LICENSE.txt README.md formeze.gemspec)
|
12
|
-
s.required_ruby_version = '>=
|
12
|
+
s.required_ruby_version = '>= 2.4.0'
|
13
13
|
s.require_path = 'lib'
|
14
14
|
s.metadata = {
|
15
15
|
'homepage' => 'https://github.com/readysteady/formeze',
|
data/lib/formeze.rb
CHANGED
@@ -21,7 +21,7 @@ module Formeze
|
|
21
21
|
|
22
22
|
attr_reader :name
|
23
23
|
|
24
|
-
def initialize(name, options
|
24
|
+
def initialize(name, **options)
|
25
25
|
@name, @options = name, options
|
26
26
|
end
|
27
27
|
|
@@ -80,7 +80,7 @@ module Formeze
|
|
80
80
|
end
|
81
81
|
|
82
82
|
def error(key, default)
|
83
|
-
Formeze.translate(key,
|
83
|
+
Formeze.translate(key, scope: ERRORS_SCOPE, default: default)
|
84
84
|
end
|
85
85
|
|
86
86
|
def key
|
@@ -92,7 +92,7 @@ module Formeze
|
|
92
92
|
end
|
93
93
|
|
94
94
|
def label
|
95
|
-
@options.fetch(:label) { Formeze.translate(name,
|
95
|
+
@options.fetch(:label) { Formeze.translate(name, scope: LABELS_SCOPE, default: Formeze.label(name)) }
|
96
96
|
end
|
97
97
|
|
98
98
|
def required?
|
@@ -167,20 +167,22 @@ module Formeze
|
|
167
167
|
class Validation
|
168
168
|
include Presence
|
169
169
|
|
170
|
-
def initialize(field,
|
171
|
-
@field
|
172
|
-
|
170
|
+
def initialize(field, **kwargs, &block)
|
171
|
+
@field = field
|
172
|
+
|
173
|
+
@error = kwargs[:error] || :invalid
|
173
174
|
|
174
|
-
|
175
|
-
|
175
|
+
@precondition = kwargs[:if]
|
176
|
+
|
177
|
+
@block = block
|
176
178
|
end
|
177
179
|
|
178
180
|
def error_message
|
179
|
-
Formeze.translate(
|
181
|
+
Formeze.translate(@error, scope: ERRORS_SCOPE, default: 'is invalid')
|
180
182
|
end
|
181
183
|
|
182
184
|
def validates?(form)
|
183
|
-
@
|
185
|
+
@precondition ? form.instance_eval(&@precondition) : true
|
184
186
|
end
|
185
187
|
|
186
188
|
def field_value?(form)
|
@@ -209,8 +211,8 @@ module Formeze
|
|
209
211
|
@fields ||= {}
|
210
212
|
end
|
211
213
|
|
212
|
-
def field(
|
213
|
-
field = Field.new(
|
214
|
+
def field(name, **options)
|
215
|
+
field = Field.new(name, **options)
|
214
216
|
|
215
217
|
fields[field.name] = field
|
216
218
|
|
@@ -221,8 +223,8 @@ module Formeze
|
|
221
223
|
@validations ||= []
|
222
224
|
end
|
223
225
|
|
224
|
-
def validates(field_name, options
|
225
|
-
validations << Validation.new(fields[field_name], options, &block)
|
226
|
+
def validates(field_name, **options, &block)
|
227
|
+
validations << Validation.new(fields[field_name], **options, &block)
|
226
228
|
end
|
227
229
|
end
|
228
230
|
|
@@ -376,8 +378,16 @@ module Formeze
|
|
376
378
|
end
|
377
379
|
end
|
378
380
|
|
379
|
-
|
380
|
-
|
381
|
+
ERRORS_SCOPE = [:formeze, :errors].freeze
|
382
|
+
|
383
|
+
private_constant :ERRORS_SCOPE
|
384
|
+
|
385
|
+
LABELS_SCOPE = [:formeze, :labels].freeze
|
386
|
+
|
387
|
+
private_constant :LABELS_SCOPE
|
388
|
+
|
389
|
+
def self.translate(key, **options)
|
390
|
+
defined?(I18n) ? I18n.translate(key, **options) : options.fetch(:default)
|
381
391
|
end
|
382
392
|
|
383
393
|
def self.setup(form)
|
metadata
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: formeze
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 4.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tim Craft
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-07-13 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description:
|
13
|
+
description: Ruby gem for validating form data
|
14
14
|
email:
|
15
15
|
- mail@timcraft.com
|
16
16
|
executables: []
|
@@ -30,7 +30,7 @@ metadata:
|
|
30
30
|
source_code_uri: https://github.com/readysteady/formeze
|
31
31
|
bug_tracker_uri: https://github.com/readysteady/formeze/issues
|
32
32
|
changelog_uri: https://github.com/readysteady/formeze/blob/master/CHANGES.md
|
33
|
-
post_install_message:
|
33
|
+
post_install_message:
|
34
34
|
rdoc_options: []
|
35
35
|
require_paths:
|
36
36
|
- lib
|
@@ -38,7 +38,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
38
38
|
requirements:
|
39
39
|
- - ">="
|
40
40
|
- !ruby/object:Gem::Version
|
41
|
-
version:
|
41
|
+
version: 2.4.0
|
42
42
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
43
43
|
requirements:
|
44
44
|
- - ">="
|
@@ -46,7 +46,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
46
46
|
version: '0'
|
47
47
|
requirements: []
|
48
48
|
rubygems_version: 3.1.2
|
49
|
-
signing_key:
|
49
|
+
signing_key:
|
50
50
|
specification_version: 4
|
51
51
|
summary: See description
|
52
52
|
test_files: []
|