json_schema_tools 0.5.2 → 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MWMyMGVjNDg3M2IwYzhkMjU0N2Y3ZjY4OThjYTYxMTNkODY0MzYxZg==
4
+ YTU2OGFjZGFhZGI4YzVlNGM4MGI5ZGI4MDI0MjhjMDFiNTc4MjMzYg==
5
5
  data.tar.gz: !binary |-
6
- NjZjYjhiMmFhZmZhOWNjYjE5MzllZWE5ODllZjQzY2VjOGU1MTRlMQ==
6
+ NzRkYTVkMjY2M2ZhYjJhMTA3MWUyMzU3MGZmZTQyOWJmODI1YzdkYQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MDdkNTk5MWMzMmExMDAxZTU0ZTI4MWYyZmU1OGFkZjRlZTRiODhiNDljNzJk
10
- YWMxMjA2OTljZWI1ODBiMjY4YjE5MDc3N2JkNGNlMTM1ZWM1YzVmOGRjMWRj
11
- ZDE2NzIzZTM0NWNjZDk2MWFmNDBiYzFhYjE4Yjg3NWZjNmJkYWM=
9
+ ZjM2MzVlMTUwZDgzNDFhMmQyY2Q3ZTBlNWFkNjg4NDQ4NTBhNzNhNWQxY2Q3
10
+ Mjg1NmUzYTkxYzM1MzEzOTNiYjg4ZTkyZDI3Y2M2MjQxYmUyZGQ4NGI4ZWVm
11
+ YmE4YWU0OWZkNmU0NzM2MGI4NWI5ZTkxNTBmYjEzMDAyZWI2NWQ=
12
12
  data.tar.gz: !binary |-
13
- ZWI5YjZjZTU5MzUzZjliNTEwOTU2Nzc4YTRlMjlmNGMxMmYyNGJlODg1YzU4
14
- OWU0ODJiYzc4MTBiODM5Yzk4MjYxNGIwODk0NDFkNDk3NzQ3YjYwNjFlOTE1
15
- MTI1MjFlNGI3ZWNhMzQ5MzkzNTJhYjFhOWVhYmQxMzk5M2M2ODU=
13
+ MjUyZjE5NDM2ZDE2MTlkZDIzZWRhOGQ5Y2FmOGFmMjQ2Yzg4YTVkMDZlODFj
14
+ MDI1YmQ2ZTNhNzRhZWU3MWU5NDAxN2UwN2Q2YjIxZTlmMWI1ZWM4N2M4YmQw
15
+ OTBkYmFjMzdlOGMxYzJiYWE2Nzk0ZWE1M2I1ZWFlMTJjNTJhMmQ=
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog JSON Schema Tools
2
2
 
3
+ ##2015-01
4
+
5
+ * add :reader option for Obj.as_schema_hash to use a custom reader instance(with its own schema registry), instead of the global one
6
+
3
7
  ##2014-12
4
8
 
5
9
  * object.as_schema_hash converts values to types defined in the schema e.g strings, integers
data/README.md CHANGED
@@ -84,7 +84,8 @@ schema = SchemaTools::Reader.read :client, 'my/path/to/json-files'
84
84
  schemata = SchemaTools::Reader.read_all 'my/path/to/json-files'
85
85
  ```
86
86
 
87
- Don't like the global path and registry? Go local:
87
+ Don't like the global path and registry? Create an instance and your save with
88
+ a local registry. Use if you have schema with same names but different markup!
88
89
 
89
90
  ```ruby
90
91
  reader = SchemaTools::Reader.new
@@ -164,6 +165,14 @@ Set a custom schema path
164
165
  peter.as_schema_json( path: 'path-to/json-files/')
165
166
  ```
166
167
 
168
+ Use your custom reader (preferred over path usage)
169
+
170
+ ```ruby
171
+ reader = SchemaTools::Reader.new
172
+ reader.read_all '/your/custom/path-to-schema-json/
173
+ peter.as_schema_json( reader: reader)
174
+ ```
175
+
167
176
  By default the object hash has the class name (client) and the link-section on
168
177
  root level. This divides the data from the available methods and makes a clear
169
178
  statement about the object type(it's class).
@@ -33,6 +33,8 @@ module SchemaTools
33
33
  # @options opts [Array<String>] :fields to return. If not set all schema
34
34
  # properties are used.
35
35
  # @options opts [String] :path of the schema files overriding global one
36
+ # @options opts [String] :reader instance to read the schemas from instead
37
+ # of the global one
36
38
  # @options opts [String] :base_url used in all links
37
39
  # @options opts [Boolean] :links if set the object hash gets its _links
38
40
  # array inline.
@@ -44,9 +46,15 @@ module SchemaTools
44
46
  # get objects class name without inheritance
45
47
  real_class_name = obj.class.name.split('::').last.underscore
46
48
  class_name = opts[:class_name] || real_class_name
47
- # get schema
48
- inline_schema = opts.delete(:schema) if opts[:schema].present?
49
- schema = inline_schema || SchemaTools::Reader.read(class_name, opts[:path])
49
+ schema = if opts[:reader].present?
50
+ opts[:reader].read(class_name)
51
+ elsif opts[:schema].present?
52
+ # TODO inline schema can be problematic with nested resource types,
53
+ # use a local reader instance until we figured it out
54
+ opts.delete(:schema)
55
+ else
56
+ SchemaTools::Reader.read(class_name, opts[:path])
57
+ end
50
58
 
51
59
  # iterate over the defined schema fields
52
60
  data = parse_properties(obj, schema, opts)
@@ -1,3 +1,3 @@
1
1
  module SchemaTools
2
- VERSION = '0.5.2'
2
+ VERSION = '0.5.3'
3
3
  end
@@ -60,6 +60,20 @@ describe SchemaTools::Hash do
60
60
  hash.keys.should_not include('birthday')
61
61
  end
62
62
 
63
+ it 'should use custom reader' do
64
+ reader = SchemaTools::Reader.new
65
+ reader.read_all File.expand_path('../../fixtures/schemata', __FILE__)
66
+ client = Client.new
67
+ client.first_name = 'Egon'
68
+ a1 = Address.new
69
+ a1.city = 'Cologne'
70
+ client.addresses = [a1]
71
+ # use a object with nesting as this is problematic
72
+ hash = SchemaTools::Hash.from_schema(client, reader: reader)
73
+ hash['first_name'].should == 'Egon'
74
+ hash['addresses'][0]['city'].should == 'Cologne'
75
+ end
76
+
63
77
  it 'should use custom schema path' do
64
78
  custom_path = File.expand_path('../../fixtures/schemata', __FILE__)
65
79
  hash = SchemaTools::Hash.from_schema(contact, path: custom_path)
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.5.2
4
+ version: 0.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Georg Leciejewski
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-18 00:00:00.000000000 Z
11
+ date: 2015-01-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json