json_schema_tools 0.6.4 → 0.6.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -1
- data/lib/schema_tools/klass_factory.rb +1 -1
- data/lib/schema_tools/modules/hash.rb +11 -6
- data/lib/schema_tools/version.rb +1 -1
- data/spec/schema_tools/hash_spec.rb +10 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0d5a291270b106ca221fdc0f91804fdf60cdd614
|
4
|
+
data.tar.gz: 4a2b44c9bbfe7a4266a61d02429089a88f5e670d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a634c484dcc2aae2faa7db335b47b09f732fd48c13c26e6bf59b4ff9047467c710f6a672f1146a7ba3c109fbd58c9b80783d8ec538b2958fa1f3efb5e549e8e1
|
7
|
+
data.tar.gz: 1308a7ff3314b2333ce993a353dbd678b579fdb0dccb4c7d0cde62f64d5589152ae25ac5e98f786d3237278e225eb4c9eede30094a323d87f374eaec9413df59
|
data/.travis.yml
CHANGED
@@ -86,12 +86,17 @@ module SchemaTools
|
|
86
86
|
data[field] = parse_object(obj, field, prop, opts) if parse_object?(obj, field)
|
87
87
|
else # a simple field is only added if the object knows it
|
88
88
|
next unless obj.respond_to?(field)
|
89
|
-
raw_val = obj.
|
89
|
+
raw_val = obj.public_send(field)
|
90
90
|
# convert field to schema type if set
|
91
91
|
conv_val = if raw_val.nil?
|
92
92
|
raw_val
|
93
93
|
elsif prop['type'] == 'string' # rely on .to_s for format from date/datetime
|
94
|
-
|
94
|
+
case prop['format']
|
95
|
+
when "date", "date-time"
|
96
|
+
raw_val.iso8601
|
97
|
+
else
|
98
|
+
raw_val.to_s
|
99
|
+
end
|
95
100
|
elsif prop['type'] == 'integer'
|
96
101
|
raw_val.to_i
|
97
102
|
else # bool / number rely on .to_s in json lib
|
@@ -118,7 +123,7 @@ module SchemaTools
|
|
118
123
|
matches = href.scan(/{(\w+)}/) #{abc} => abc
|
119
124
|
replaces = []
|
120
125
|
matches.each do |match|
|
121
|
-
obj_val = obj.
|
126
|
+
obj_val = obj.public_send(match[0]) if obj.respond_to?(match[0])
|
122
127
|
replaces << ["{#{match[0]}}", obj_val] if obj_val
|
123
128
|
end
|
124
129
|
replaces.each {|r| href.gsub!(r[0], "#{r[1]}")}
|
@@ -144,7 +149,7 @@ module SchemaTools
|
|
144
149
|
return nil if !obj.respond_to?( field )
|
145
150
|
return nil if !prop['items']
|
146
151
|
|
147
|
-
rel_objects = obj.
|
152
|
+
rel_objects = obj.public_send( field )
|
148
153
|
# force an empty array if values are not present
|
149
154
|
return res if !rel_objects
|
150
155
|
|
@@ -176,7 +181,7 @@ module SchemaTools
|
|
176
181
|
# @param [Hash] opts to_schema options
|
177
182
|
# @return [Array<Hash{String=>String}>]
|
178
183
|
def parse_object(obj, field, prop, opts)
|
179
|
-
rel_obj = obj.
|
184
|
+
rel_obj = obj.public_send( field )
|
180
185
|
res = if prop['properties'].present?
|
181
186
|
opts[:schema] = prop
|
182
187
|
from_schema(rel_obj, opts)
|
@@ -195,7 +200,7 @@ module SchemaTools
|
|
195
200
|
|
196
201
|
def parse_object?(obj, field)
|
197
202
|
if obj.respond_to?( field )
|
198
|
-
rel_obj = obj.
|
203
|
+
rel_obj = obj.public_send( field )
|
199
204
|
rel_obj.present?
|
200
205
|
else
|
201
206
|
false
|
data/lib/schema_tools/version.rb
CHANGED
@@ -5,7 +5,7 @@ require 'spec_helper'
|
|
5
5
|
# json schema is derived from it
|
6
6
|
################################################################################
|
7
7
|
class Client
|
8
|
-
attr_accessor :first_name, :id, :addresses, :work_address
|
8
|
+
attr_accessor :first_name, :id, :addresses, :work_address, :created_at
|
9
9
|
end
|
10
10
|
class Address
|
11
11
|
attr_accessor :city, :zip
|
@@ -43,10 +43,14 @@ describe SchemaTools::Hash do
|
|
43
43
|
context 'from_schema to hash conversion' do
|
44
44
|
|
45
45
|
let(:contact){Contact.new}
|
46
|
+
let(:client){Client.new}
|
47
|
+
|
46
48
|
before :each do
|
47
49
|
contact.first_name = 'Peter'
|
48
50
|
contact.last_name = 'Paul'
|
49
51
|
contact.id = 'SomeID'
|
52
|
+
|
53
|
+
client.created_at = Time.now
|
50
54
|
end
|
51
55
|
after :each do
|
52
56
|
SchemaTools::Reader.registry_reset
|
@@ -57,6 +61,11 @@ describe SchemaTools::Hash do
|
|
57
61
|
hash['last_name'].should == 'Paul'
|
58
62
|
end
|
59
63
|
|
64
|
+
it 'should format date-time fields to iso8601' do
|
65
|
+
hash = SchemaTools::Hash.from_schema(client)
|
66
|
+
hash['created_at'].should == client.created_at.iso8601
|
67
|
+
end
|
68
|
+
|
60
69
|
it 'keeps nil values' do
|
61
70
|
hash = SchemaTools::Hash.from_schema(contact)
|
62
71
|
hash.keys.should include('organisation')
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: json_schema_tools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Georg Leciejewski
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-08-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
@@ -147,7 +147,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
147
147
|
version: '0'
|
148
148
|
requirements: []
|
149
149
|
rubyforge_project:
|
150
|
-
rubygems_version: 2.4.
|
150
|
+
rubygems_version: 2.4.8
|
151
151
|
signing_key:
|
152
152
|
specification_version: 4
|
153
153
|
summary: JSON Schema API tools for server and client side
|