foraneus 0.0.9 → 0.0.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/foraneus/converters/decimal.rb +0 -7
- data/lib/foraneus.rb +18 -3
- data/spec/lib/foraneus_spec.rb +15 -3
- 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: 7b3cc51401c2bcc207999c402d0609b07e8ccd83
|
4
|
+
data.tar.gz: 8ef4b2c5d0bf8c600c9f1c936e7c6ecaca077539
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f78d1e12309ae8dd947f353218efc74f1458e92f24a88de0d5246a074e60fad6b823ef9a6e942419483ff41adc5d16d61dc9819fa635ee8de26f6b43f18f3aa1
|
7
|
+
data.tar.gz: a84ae675a7f26b4d8027d436ef4dbc6371af391b2a505f05655e6a296bd1528c9858fa5488f0f3b9c99e6aae43068c0af1b160f1094db7a71524632cfda70f4d
|
data/lib/foraneus.rb
CHANGED
@@ -107,11 +107,26 @@ class Foraneus
|
|
107
107
|
# @param [Hash<Symbol, String>] raw_data
|
108
108
|
#
|
109
109
|
# @return [Foraneus] An instance of a form.
|
110
|
-
def self.parse(raw_data)
|
110
|
+
def self.parse(raw_data = {})
|
111
111
|
instance = self.new
|
112
112
|
|
113
|
+
parsed_keys = []
|
114
|
+
|
115
|
+
@fields.each do |k, _|
|
116
|
+
given_key = k
|
117
|
+
v = raw_data.fetch(given_key) do |k|
|
118
|
+
given_key = k.to_sym
|
119
|
+
raw_data.fetch(given_key, nil)
|
120
|
+
end
|
121
|
+
|
122
|
+
parsed_keys << given_key
|
123
|
+
__parse_raw_datum(instance, given_key, v)
|
124
|
+
end
|
125
|
+
|
113
126
|
raw_data.each do |k, v|
|
114
|
-
|
127
|
+
unless parsed_keys.include?(k)
|
128
|
+
__parse_raw_datum(instance, k, v)
|
129
|
+
end
|
115
130
|
end
|
116
131
|
|
117
132
|
instance
|
@@ -122,7 +137,7 @@ class Foraneus
|
|
122
137
|
# @param [Hash<Symbol, Object>] data
|
123
138
|
#
|
124
139
|
# @return [Foraneus] An instance of a form.
|
125
|
-
def self.raw(data)
|
140
|
+
def self.raw(data = {})
|
126
141
|
instance = self.new
|
127
142
|
|
128
143
|
data.each do |k, v|
|
data/spec/lib/foraneus_spec.rb
CHANGED
@@ -125,7 +125,7 @@ describe Foraneus do
|
|
125
125
|
its(:data) { should include(:delay => '') }
|
126
126
|
end
|
127
127
|
|
128
|
-
shared_examples 'an absent parameters handler' do |missing_value|
|
128
|
+
shared_examples 'an absent parameters value handler' do |missing_value|
|
129
129
|
subject(:form) { form_spec.parse(:delay => missing_value) }
|
130
130
|
|
131
131
|
it { should be_valid }
|
@@ -162,11 +162,23 @@ describe Foraneus do
|
|
162
162
|
end
|
163
163
|
|
164
164
|
context 'with nil values' do
|
165
|
-
it_behaves_like 'an absent parameters handler', nil
|
165
|
+
it_behaves_like 'an absent parameters value handler', nil
|
166
166
|
end
|
167
167
|
|
168
168
|
context 'with empty values' do
|
169
|
-
it_behaves_like 'an absent parameters handler', ''
|
169
|
+
it_behaves_like 'an absent parameters value handler', ''
|
170
|
+
end
|
171
|
+
|
172
|
+
context 'when required field' do
|
173
|
+
let(:converter) { Foraneus::Converters::Integer.new(:required => true) }
|
174
|
+
|
175
|
+
context 'when missing input parameter' do
|
176
|
+
subject(:form) { form_spec.parse }
|
177
|
+
|
178
|
+
it { should_not be_valid }
|
179
|
+
|
180
|
+
its(:delay) { should be_nil }
|
181
|
+
end
|
170
182
|
end
|
171
183
|
end
|
172
184
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: foraneus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gianfranco Zas
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-08-
|
11
|
+
date: 2014-08-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|