simple_schema 0.0.4 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
@@ -11,15 +11,19 @@ module SimpleSchema
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def translate(data)
|
14
|
-
if !data.respond_to?(:each) && !data.respond_to?(:fetch)
|
15
|
-
raise InvalidDataType.new(data.class)
|
16
|
-
end
|
17
|
-
|
18
14
|
translated_data = {}
|
15
|
+
|
19
16
|
@schema.each do |key, properties|
|
20
17
|
|
21
18
|
translated_key = SimpleSchema.translate(key, properties[:key_name])
|
22
|
-
|
19
|
+
#todo: pode ser escolhida a estrategia apenas 1 vez
|
20
|
+
if data.respond_to?(:fetch)
|
21
|
+
value = data.fetch(key, nil)
|
22
|
+
elsif data.respond_to?(:read_attribute)
|
23
|
+
value = data.read_attribute(key)
|
24
|
+
else
|
25
|
+
raise InvalidDataType.new(data.class)
|
26
|
+
end
|
23
27
|
|
24
28
|
@options[:translates].each do |normalizer|
|
25
29
|
value = normalizer.build(value, properties, @options)
|
@@ -32,14 +36,17 @@ module SimpleSchema
|
|
32
36
|
end
|
33
37
|
|
34
38
|
def filter(data, filter)
|
35
|
-
if !data.respond_to?(:each) && !data.respond_to?(:fetch)
|
36
|
-
raise InvalidDataType.new(data.class)
|
37
|
-
end
|
38
|
-
|
39
39
|
translated_data = {}
|
40
40
|
@schema.each do |key, properties|
|
41
|
+
#todo: pode ser escolhida a estrategia apenas 1 vez
|
42
|
+
if data.respond_to?(:fetch)
|
43
|
+
value = data.fetch(key, nil)
|
44
|
+
elsif data.respond_to?(:read_attribute)
|
45
|
+
value = data.read_attribute(key)
|
46
|
+
else
|
47
|
+
raise InvalidDataType.new(data.class)
|
48
|
+
end
|
41
49
|
|
42
|
-
value = data.fetch(key, nil)
|
43
50
|
@options[:filters].each do |normalizer|
|
44
51
|
value = normalizer.build(value, properties, @options , filter)
|
45
52
|
end
|
@@ -4,6 +4,7 @@ module SimpleSchema
|
|
4
4
|
return data unless (schema[:type] == :array)
|
5
5
|
conveter = Converter::new(schema[:items], options)
|
6
6
|
items = []
|
7
|
+
raise InvalidDataType.new(data.class) unless data.respond_to?(:each)
|
7
8
|
data.each do |item|
|
8
9
|
items << conveter.filter(item, filter)
|
9
10
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_schema
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,11 +13,11 @@ authors:
|
|
13
13
|
autorequire:
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
|
-
date: 2011-09-
|
16
|
+
date: 2011-09-17 00:00:00.000000000Z
|
17
17
|
dependencies:
|
18
18
|
- !ruby/object:Gem::Dependency
|
19
19
|
name: rspec
|
20
|
-
requirement: &
|
20
|
+
requirement: &11643600 !ruby/object:Gem::Requirement
|
21
21
|
none: false
|
22
22
|
requirements:
|
23
23
|
- - ! '>='
|
@@ -25,7 +25,7 @@ dependencies:
|
|
25
25
|
version: '0'
|
26
26
|
type: :development
|
27
27
|
prerelease: false
|
28
|
-
version_requirements: *
|
28
|
+
version_requirements: *11643600
|
29
29
|
description: Simple schema validator for Ruby
|
30
30
|
email:
|
31
31
|
- lenon.marcel@gmail.com
|