roda-component 0.1.28 → 0.1.29
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/lib/roda/component/form.rb +10 -0
- data/lib/roda/component/form/validations.rb +39 -4
- data/lib/roda/component/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eae3fae4ea91aee88c28f270ebcf6fff1ff7b53f
|
4
|
+
data.tar.gz: 0b75b3ed5a36ca0dea4b387f0ca99c6d1df89ebd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7f5f576648297e189783d00cb7cf92d72f4e4afdf5e91565e677ea911ad45cec3b4aa944d33c1566ba9268034c2b56fff268982d7131ed42ff9b7a84b59f7880
|
7
|
+
data.tar.gz: 49f2db414e872f5f2caf5482a101276c4e676c7d05c9e408b643a054af18df9a84946a63569ba0c38e2b32a0308753076da6cd04f5587fd10f2dc6b393988d70
|
data/lib/roda/component/form.rb
CHANGED
@@ -325,6 +325,16 @@ class Roda
|
|
325
325
|
RUBY_ENGINE == 'opal'
|
326
326
|
end
|
327
327
|
alias :client :client?
|
328
|
+
|
329
|
+
def self.server? &block
|
330
|
+
RUBY_ENGINE == 'ruby'
|
331
|
+
end
|
332
|
+
alias :server :server?
|
333
|
+
|
334
|
+
def self.client?
|
335
|
+
RUBY_ENGINE == 'opal'
|
336
|
+
end
|
337
|
+
alias :client :client?
|
328
338
|
end
|
329
339
|
end
|
330
340
|
end
|
@@ -50,6 +50,25 @@ class Roda
|
|
50
50
|
# :date => [:format] }
|
51
51
|
#
|
52
52
|
module Validations
|
53
|
+
def server? &block
|
54
|
+
RUBY_ENGINE == 'ruby'
|
55
|
+
end
|
56
|
+
alias :server :server?
|
57
|
+
|
58
|
+
def client?
|
59
|
+
RUBY_ENGINE == 'opal'
|
60
|
+
end
|
61
|
+
alias :client :client?
|
62
|
+
|
63
|
+
def self.server? &block
|
64
|
+
RUBY_ENGINE == 'ruby'
|
65
|
+
end
|
66
|
+
alias :server :server?
|
67
|
+
|
68
|
+
def self.client?
|
69
|
+
RUBY_ENGINE == 'opal'
|
70
|
+
end
|
71
|
+
alias :client :client?
|
53
72
|
|
54
73
|
# Check if the current model state is valid. Each call to {#valid?} will
|
55
74
|
# reset the {#errors} array.
|
@@ -127,11 +146,19 @@ class Roda
|
|
127
146
|
# when the validation fails.
|
128
147
|
def assert_numeric(att, error = [att, :not_numeric])
|
129
148
|
if assert_present(att, error)
|
130
|
-
|
149
|
+
if client?
|
150
|
+
assert_format(att, /^\-?\d+$/, error)
|
151
|
+
else
|
152
|
+
assert_format(att, /\A\-?\d+\z/, error)
|
153
|
+
end
|
131
154
|
end
|
132
155
|
end
|
133
156
|
|
134
|
-
|
157
|
+
if client?
|
158
|
+
URL = /^(http|https):\/\/([a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}|(2 5[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3} |localhost)(:[0-9]{1,5})?(\/.*)?$/i
|
159
|
+
else
|
160
|
+
URL = /\A(http|https):\/\/([a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}|(2 5[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3} |localhost)(:[0-9]{1,5})?(\/.*)?\z/i
|
161
|
+
end
|
135
162
|
|
136
163
|
def assert_url(att, error = [att, :not_url])
|
137
164
|
if assert_present(att, error)
|
@@ -139,7 +166,11 @@ class Roda
|
|
139
166
|
end
|
140
167
|
end
|
141
168
|
|
142
|
-
|
169
|
+
if client?
|
170
|
+
EMAIL = /^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/i
|
171
|
+
else
|
172
|
+
EMAIL = /\A[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]\z/i
|
173
|
+
end
|
143
174
|
|
144
175
|
def assert_email(att, error = [att, :not_email])
|
145
176
|
if assert_present(att, error)
|
@@ -158,7 +189,11 @@ class Roda
|
|
158
189
|
end
|
159
190
|
end
|
160
191
|
|
161
|
-
|
192
|
+
if client?
|
193
|
+
DECIMAL = /^\-?(\d+)?(\.\d+)?$/
|
194
|
+
else
|
195
|
+
DECIMAL = /\A\-?(\d+)?(\.\d+)?\z/
|
196
|
+
end
|
162
197
|
|
163
198
|
def assert_decimal(att, error = [att, :not_decimal])
|
164
199
|
assert_format att, DECIMAL, error
|