rasti-form 1.0.0 → 1.0.1
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/rasti/form/validable.rb +28 -0
- data/lib/rasti/form/version.rb +1 -1
- data/lib/rasti/form.rb +3 -20
- data/spec/form_spec.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e569c6d3294a2d755878465ed47c2be552349d22
|
4
|
+
data.tar.gz: eac5ece907a3eb5d36eda217183e2bb9eaae89e4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6363b2f3e2b491231416e2dfb2288a3648c37d2854aa421c839f8863d425ee68462af4b92278c9a99e211582cc4700591794fb8acb2f5abd8ac789df6ec32b70
|
7
|
+
data.tar.gz: 95e29872aba69ce39e2379d7b86fc765ca5eea74043a165ec31877ddbb39271618ad0b0d639c20c3dea10585a0db5c2b359d5fa69e22de09e79afdac508510e2
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Rasti
|
2
|
+
class Form
|
3
|
+
module Validable
|
4
|
+
|
5
|
+
private
|
6
|
+
|
7
|
+
def errors
|
8
|
+
@errors ||= Hash.new { |hash, key| hash[key] = [] }
|
9
|
+
end
|
10
|
+
|
11
|
+
def validate!
|
12
|
+
validate
|
13
|
+
raise ValidationError.new(errors) unless errors.empty?
|
14
|
+
end
|
15
|
+
|
16
|
+
def validate
|
17
|
+
end
|
18
|
+
|
19
|
+
def assert(key, condition, message)
|
20
|
+
return true if condition
|
21
|
+
|
22
|
+
errors[key] << message
|
23
|
+
false
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/rasti/form/version.rb
CHANGED
data/lib/rasti/form.rb
CHANGED
@@ -9,6 +9,8 @@ module Rasti
|
|
9
9
|
require_relative_pattern 'form/*'
|
10
10
|
require_relative_pattern 'form/types/*'
|
11
11
|
|
12
|
+
include Validable
|
13
|
+
|
12
14
|
class << self
|
13
15
|
|
14
16
|
def [](attributes)
|
@@ -85,7 +87,7 @@ module Rasti
|
|
85
87
|
if self.class.attributes.key? name
|
86
88
|
write_attribute name, value
|
87
89
|
else
|
88
|
-
errors[name] << '
|
90
|
+
errors[name] << 'unexpected attribute'
|
89
91
|
end
|
90
92
|
|
91
93
|
rescue CastError => error
|
@@ -137,25 +139,6 @@ module Rasti
|
|
137
139
|
end
|
138
140
|
end
|
139
141
|
|
140
|
-
def validate!
|
141
|
-
validate
|
142
|
-
raise ValidationError.new(errors) unless errors.empty?
|
143
|
-
end
|
144
|
-
|
145
|
-
def validate
|
146
|
-
end
|
147
|
-
|
148
|
-
def errors
|
149
|
-
@errors ||= Hash.new { |hash, key| hash[key] = [] }
|
150
|
-
end
|
151
|
-
|
152
|
-
def assert(key, condition, message)
|
153
|
-
return true if condition
|
154
|
-
|
155
|
-
errors[key] << message
|
156
|
-
false
|
157
|
-
end
|
158
|
-
|
159
142
|
def assert_present(attribute)
|
160
143
|
assert attribute, !fetch(attribute).nil?, 'not present'
|
161
144
|
end
|
data/spec/form_spec.rb
CHANGED
@@ -40,7 +40,7 @@ describe Rasti::Form do
|
|
40
40
|
|
41
41
|
it 'Invalid attributes' do
|
42
42
|
error = proc { point_class.new z: 3 }.must_raise Rasti::Form::ValidationError
|
43
|
-
error.message.must_equal 'Validation error: {"z":["
|
43
|
+
error.message.must_equal 'Validation error: {"z":["unexpected attribute"]}'
|
44
44
|
end
|
45
45
|
|
46
46
|
describe 'Casting' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rasti-form
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gabriel Naiman
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-09-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: multi_require
|
@@ -169,6 +169,7 @@ files:
|
|
169
169
|
- lib/rasti/form/types/symbol.rb
|
170
170
|
- lib/rasti/form/types/time.rb
|
171
171
|
- lib/rasti/form/types/uuid.rb
|
172
|
+
- lib/rasti/form/validable.rb
|
172
173
|
- lib/rasti/form/version.rb
|
173
174
|
- rasti-form.gemspec
|
174
175
|
- spec/coverage_helper.rb
|