formeze 4.2.1 → 4.3.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 +2 -2
- data/formeze.gemspec +2 -1
- data/lib/formeze/condition.rb +11 -0
- data/lib/formeze/field.rb +7 -15
- data/lib/formeze/presence.rb +7 -4
- data/lib/formeze/validation.rb +1 -1
- data/lib/formeze.rb +3 -2
- metadata +18 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 65adcff0153dbcbf39d46bbdb6ad7a60765e57e8329b89d3003ed1e4c9c9bcf5
|
4
|
+
data.tar.gz: 99f871b6b7228ec472abaf8a2dbe820ea33a7cc5b3f3ef6dcd83f95a18410bda
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d1a01576d7f38d324e8aa7c33279fd25f36227d49e124b8f53f6f56605cd632478e88616cf13c9e4c37994472905bea37cc7fe211f85ac6e98aca5dbe2bf37c1
|
7
|
+
data.tar.gz: 12564e8c34d417f605c886fe43202fdde129aea2370699ee8411cb3e4703f99fbeb4ba5a4ad054a295ae8387708da3fe6db80454a5de3f779c69852e3c7777db
|
data/CHANGES.md
CHANGED
data/README.md
CHANGED
@@ -174,7 +174,7 @@ the `defined_if` or `defined_unless` options with a proc. Here's an example
|
|
174
174
|
of using the defined_if option:
|
175
175
|
|
176
176
|
```ruby
|
177
|
-
field :business_name, defined_if:
|
177
|
+
field :business_name, defined_if: ->{ @account.business? }
|
178
178
|
```
|
179
179
|
|
180
180
|
In this example the `business_name` field will only be defined and validated
|
@@ -185,7 +185,7 @@ Here's an example of using the defined_unless option:
|
|
185
185
|
```ruby
|
186
186
|
field :same_address, values: %w(true), key_required: false
|
187
187
|
|
188
|
-
field :billing_address_line_one, defined_unless:
|
188
|
+
field :billing_address_line_one, defined_unless: ->{ same_address? }
|
189
189
|
|
190
190
|
def same_address?
|
191
191
|
same_address == 'true'
|
data/formeze.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'formeze'
|
3
|
-
s.version = '4.
|
3
|
+
s.version = '4.3.0'
|
4
4
|
s.license = 'LGPL-3.0'
|
5
5
|
s.platform = Gem::Platform::RUBY
|
6
6
|
s.authors = ['Tim Craft']
|
@@ -17,4 +17,5 @@ Gem::Specification.new do |s|
|
|
17
17
|
'bug_tracker_uri' => 'https://github.com/readysteady/formeze/issues',
|
18
18
|
'changelog_uri' => 'https://github.com/readysteady/formeze/blob/main/CHANGES.md'
|
19
19
|
}
|
20
|
+
s.add_dependency 'cgi'
|
20
21
|
end
|
data/lib/formeze/field.rb
CHANGED
@@ -14,12 +14,16 @@ class Formeze::Field
|
|
14
14
|
|
15
15
|
values.each do |value|
|
16
16
|
if String === value
|
17
|
-
validate(value, form)
|
17
|
+
value = validate(value, form)
|
18
18
|
else
|
19
|
-
|
19
|
+
form.add_error(self, :not_accepted, 'is not an accepted file type') unless acceptable_file?(value)
|
20
20
|
|
21
21
|
size += value.size
|
22
22
|
end
|
23
|
+
|
24
|
+
value = Array(form.send(name)).push(value) if multiple?
|
25
|
+
|
26
|
+
form.send(:"#{name}=", value)
|
23
27
|
end
|
24
28
|
|
25
29
|
form.add_error(self, :too_large, 'is too large') if maxsize? && size > maxsize
|
@@ -44,19 +48,7 @@ class Formeze::Field
|
|
44
48
|
form.add_error(self, :bad_value, 'is invalid') if values? && !values.include?(value)
|
45
49
|
end
|
46
50
|
|
47
|
-
value
|
48
|
-
|
49
|
-
form.send(:"#{name}=", value)
|
50
|
-
end
|
51
|
-
|
52
|
-
def validate_file(object, form)
|
53
|
-
unless acceptable_file?(object)
|
54
|
-
form.add_error(self, :not_accepted, 'is not an accepted file type')
|
55
|
-
end
|
56
|
-
|
57
|
-
object = Array(form.send(name)).push(object) if multiple?
|
58
|
-
|
59
|
-
form.send(:"#{name}=", object)
|
51
|
+
value
|
60
52
|
end
|
61
53
|
|
62
54
|
def acceptable_file?(object)
|
data/lib/formeze/presence.rb
CHANGED
@@ -1,11 +1,14 @@
|
|
1
1
|
module Formeze::Presence
|
2
2
|
REGEXP = /\S/
|
3
3
|
|
4
|
-
def present?(
|
5
|
-
|
4
|
+
def present?(value)
|
5
|
+
return false if value.nil?
|
6
|
+
return false if value.respond_to?(:empty?) && value.empty?
|
7
|
+
return false if value.is_a?(String) && value !~ REGEXP
|
8
|
+
return true
|
6
9
|
end
|
7
10
|
|
8
|
-
def blank?(
|
9
|
-
|
11
|
+
def blank?(value)
|
12
|
+
!present?(value)
|
10
13
|
end
|
11
14
|
end
|
data/lib/formeze/validation.rb
CHANGED
data/lib/formeze.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Formeze
|
4
|
+
autoload :Condition, 'formeze/condition'
|
4
5
|
autoload :Errors, 'formeze/errors'
|
5
6
|
autoload :Field, 'formeze/field'
|
6
7
|
autoload :Form, 'formeze/form'
|
@@ -134,9 +135,9 @@ module Formeze
|
|
134
135
|
|
135
136
|
def field_defined?(field)
|
136
137
|
if field.defined_if?
|
137
|
-
|
138
|
+
Formeze::Condition.evaluate(self, field.defined_if)
|
138
139
|
elsif field.defined_unless?
|
139
|
-
!
|
140
|
+
!Formeze::Condition.evaluate(self, field.defined_unless)
|
140
141
|
else
|
141
142
|
true
|
142
143
|
end
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: formeze
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.
|
4
|
+
version: 4.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tim Craft
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
12
|
-
dependencies:
|
11
|
+
date: 2024-04-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: cgi
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
description: Ruby gem for validating form data
|
14
28
|
email:
|
15
29
|
- mail@timcraft.com
|
@@ -22,6 +36,7 @@ files:
|
|
22
36
|
- README.md
|
23
37
|
- formeze.gemspec
|
24
38
|
- lib/formeze.rb
|
39
|
+
- lib/formeze/condition.rb
|
25
40
|
- lib/formeze/errors.rb
|
26
41
|
- lib/formeze/field.rb
|
27
42
|
- lib/formeze/form.rb
|