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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 09ba062822c3985b958c2be7c6ab804fd3673d1d
4
- data.tar.gz: c5a2d25a70bb06c81bc1e3198a41246ca9920e0d
3
+ metadata.gz: e569c6d3294a2d755878465ed47c2be552349d22
4
+ data.tar.gz: eac5ece907a3eb5d36eda217183e2bb9eaae89e4
5
5
  SHA512:
6
- metadata.gz: 438c5305cb38e15abf2fb1c34c4dbf24e1c4baabe848f93d2f743572b3be5ab8738e1b4625d19cb62546bbeb39c3c80210a65e861ba772891f1c1c0640c323dd
7
- data.tar.gz: 7af935310495c9dcc0012e704441523366d87c288c0f82e57a5ba161457e2e2110399e77976afb5c3ee6c3e89d5c3de49f99180f6c9c7a4afc861616f8ff04bf
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
@@ -1,5 +1,5 @@
1
1
  module Rasti
2
2
  class Form
3
- VERSION = '1.0.0'
3
+ VERSION = '1.0.1'
4
4
  end
5
5
  end
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] << 'Unexpected attribute'
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":["Unexpected attribute"]}'
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.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-08-30 00:00:00.000000000 Z
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