rasti-form 0.1.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +2 -1
- data/lib/rasti/form.rb +7 -3
- data/lib/rasti/form/types/enum.rb +10 -0
- data/lib/rasti/form/version.rb +1 -1
- data/spec/form_spec.rb +3 -8
- data/spec/types/enum_spec.rb +8 -0
- data/spec/types/form_spec.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 09ba062822c3985b958c2be7c6ab804fd3673d1d
|
4
|
+
data.tar.gz: c5a2d25a70bb06c81bc1e3198a41246ca9920e0d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 438c5305cb38e15abf2fb1c34c4dbf24e1c4baabe848f93d2f743572b3be5ab8738e1b4625d19cb62546bbeb39c3c80210a65e861ba772891f1c1c0640c323dd
|
7
|
+
data.tar.gz: 7af935310495c9dcc0012e704441523366d87c288c0f82e57a5ba161457e2e2110399e77976afb5c3ee6c3e89d5c3de49f99180f6c9c7a4afc861616f8ff04bf
|
data/Rakefile
CHANGED
@@ -3,7 +3,8 @@ require 'rake/testtask'
|
|
3
3
|
|
4
4
|
Rake::TestTask.new(:spec) do |t|
|
5
5
|
t.libs << 'spec'
|
6
|
-
t.
|
6
|
+
t.libs << 'lib'
|
7
|
+
t.pattern = ENV['DIR'] ? File.join(ENV['DIR'], '**', '*_spec.rb') : 'spec/**/*_spec.rb'
|
7
8
|
t.verbose = false
|
8
9
|
t.warning = false
|
9
10
|
t.loader = nil if ENV['TEST']
|
data/lib/rasti/form.rb
CHANGED
@@ -80,9 +80,13 @@ module Rasti
|
|
80
80
|
private
|
81
81
|
|
82
82
|
def assign_attributes(attrs={})
|
83
|
-
|
83
|
+
attrs.each do |name, value|
|
84
84
|
begin
|
85
|
-
|
85
|
+
if self.class.attributes.key? name
|
86
|
+
write_attribute name, value
|
87
|
+
else
|
88
|
+
errors[name] << 'Unexpected attribute'
|
89
|
+
end
|
86
90
|
|
87
91
|
rescue CastError => error
|
88
92
|
errors[name] << error.message
|
@@ -91,7 +95,7 @@ module Rasti
|
|
91
95
|
error.errors.each do |inner_name, inner_errors|
|
92
96
|
inner_errors.each { |message| errors["#{name}.#{inner_name}"] << message }
|
93
97
|
end
|
94
|
-
end
|
98
|
+
end
|
95
99
|
end
|
96
100
|
end
|
97
101
|
|
@@ -20,6 +20,7 @@ module Rasti
|
|
20
20
|
|
21
21
|
def initialize(values)
|
22
22
|
@values = values.map(&:to_s)
|
23
|
+
define_getters
|
23
24
|
end
|
24
25
|
|
25
26
|
def valid?(value)
|
@@ -32,6 +33,15 @@ module Rasti
|
|
32
33
|
String.cast value
|
33
34
|
end
|
34
35
|
|
36
|
+
def define_getters
|
37
|
+
values.each do |value|
|
38
|
+
getter_name = value.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').gsub(/([a-z])([A-Z])/, '\1_\2').downcase
|
39
|
+
define_singleton_method getter_name do
|
40
|
+
value
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
35
45
|
end
|
36
46
|
end
|
37
47
|
end
|
data/lib/rasti/form/version.rb
CHANGED
data/spec/form_spec.rb
CHANGED
@@ -38,14 +38,9 @@ describe Rasti::Form do
|
|
38
38
|
point.assigned?(:y).must_equal false
|
39
39
|
end
|
40
40
|
|
41
|
-
it '
|
42
|
-
|
43
|
-
|
44
|
-
point.y.must_be_nil
|
45
|
-
point.assigned?(:x).must_equal false
|
46
|
-
point.assigned?(:y).must_equal false
|
47
|
-
proc { point.z }.must_raise NoMethodError
|
48
|
-
point.attributes.must_be_empty
|
41
|
+
it 'Invalid attributes' do
|
42
|
+
error = proc { point_class.new z: 3 }.must_raise Rasti::Form::ValidationError
|
43
|
+
error.message.must_equal 'Validation error: {"z":["Unexpected attribute"]}'
|
49
44
|
end
|
50
45
|
|
51
46
|
describe 'Casting' do
|
data/spec/types/enum_spec.rb
CHANGED
@@ -17,4 +17,12 @@ describe Rasti::Form::Types::Enum do
|
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
+
it 'Constants' do
|
21
|
+
enum = Rasti::Form::Types::Enum[:first_value, 'SecondValue', 'THIRD_VALUE']
|
22
|
+
|
23
|
+
enum.first_value.must_equal 'first_value'
|
24
|
+
enum.second_value.must_equal 'SecondValue'
|
25
|
+
enum.third_value.must_equal 'THIRD_VALUE'
|
26
|
+
end
|
27
|
+
|
20
28
|
end
|
data/spec/types/form_spec.rb
CHANGED
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:
|
4
|
+
version: 1.0.0
|
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-08-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: multi_require
|