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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c51ac19e559376a0c048f7bed77020978dd9c74d
4
- data.tar.gz: cf646e960df49539e2b4de0cc30e496f30b2d0f9
3
+ metadata.gz: 0d5a291270b106ca221fdc0f91804fdf60cdd614
4
+ data.tar.gz: 4a2b44c9bbfe7a4266a61d02429089a88f5e670d
5
5
  SHA512:
6
- metadata.gz: 8ba8fdab723dc2368b1e90a83fb8a433804c7a5edd1f6a905870ef23e4ed33600286009e85f87259694914b831b896cdbe9d7c47b68dec32482db4ad28005c66
7
- data.tar.gz: 326ce9672bc078a27f6fb6a3004cab5a3fd370cc60d228a0fd967b23779199e3962db91f02530b761157ef8f3fc3f23ec45b9a15cc055f2aa42fce589130f3d3
6
+ metadata.gz: a634c484dcc2aae2faa7db335b47b09f732fd48c13c26e6bf59b4ff9047467c710f6a672f1146a7ba3c109fbd58c9b80783d8ec538b2958fa1f3efb5e549e8e1
7
+ data.tar.gz: 1308a7ff3314b2333ce993a353dbd678b579fdb0dccb4c7d0cde62f64d5589152ae25ac5e98f786d3237278e225eb4c9eede30094a323d87f374eaec9413df59
data/.travis.yml CHANGED
@@ -1,6 +1,6 @@
1
1
  rvm:
2
2
  - 1.9.3
3
- - 2.0.0
3
+ - 2.2
4
4
  gemfile:
5
5
  - Gemfile
6
6
  env:
@@ -58,7 +58,7 @@ module SchemaTools
58
58
 
59
59
  def initialize(attributes = {})
60
60
  attributes.each do |name, value|
61
- send("#{name}=", value)
61
+ public_send("#{name}=", value)
62
62
  end
63
63
  end
64
64
 
@@ -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.send(field)
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
- "#{raw_val}"
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.send(match[0]) if obj.respond_to?(match[0])
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.send( field )
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.send( field )
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.send( field )
203
+ rel_obj = obj.public_send( field )
199
204
  rel_obj.present?
200
205
  else
201
206
  false
@@ -1,3 +1,3 @@
1
1
  module SchemaTools
2
- VERSION = '0.6.4'
2
+ VERSION = '0.6.5'
3
3
  end
@@ -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
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-04-11 00:00:00.000000000 Z
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.6
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