json_schema_tools 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +9 -5
- data/lib/schema_tools/modules/hash.rb +2 -2
- data/lib/schema_tools/version.rb +1 -1
- metadata +4 -4
data/README.md
CHANGED
|
@@ -6,7 +6,7 @@ Set of tools to help working with JSON Schemata:
|
|
|
6
6
|
|
|
7
7
|
* read schema files into a ruby hash
|
|
8
8
|
* add schema properties to a class
|
|
9
|
-
* convert any object into it's schema
|
|
9
|
+
* convert any object into it's schema JSON markup
|
|
10
10
|
* clean parameters according to a schema (e.g. in an api controller)
|
|
11
11
|
|
|
12
12
|
## Usage
|
|
@@ -23,12 +23,16 @@ schema.json files are located.
|
|
|
23
23
|
|
|
24
24
|
SchemaTools.schema_path = '/path/to/schema-json-files'
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
Read a single schema:
|
|
27
27
|
|
|
28
28
|
schema = SchemaTools::Reader.read :client
|
|
29
|
-
|
|
29
|
+
|
|
30
|
+
Read multiple schemas, all *.json files in schema path
|
|
31
|
+
|
|
30
32
|
schemata = SchemaTools::Reader.read_all
|
|
31
|
-
|
|
33
|
+
|
|
34
|
+
Schemata are cached in registry
|
|
35
|
+
|
|
32
36
|
SchemaTools::Reader.registry[:client]
|
|
33
37
|
|
|
34
38
|
Read files from a custom path?
|
|
@@ -43,7 +47,7 @@ Don't like the global path and registry? Go local:
|
|
|
43
47
|
reader.registry
|
|
44
48
|
|
|
45
49
|
|
|
46
|
-
## Object to Schema
|
|
50
|
+
## Object to Schema JSON
|
|
47
51
|
|
|
48
52
|
A schema provides a (public) contract about an object definition. Therefore an
|
|
49
53
|
internal object is converted to it's schema version on delivery(API access).
|
|
@@ -41,8 +41,8 @@ module SchemaTools
|
|
|
41
41
|
# get objects class name without inheritance
|
|
42
42
|
real_class_name = obj.class.name.split('::').last.underscore
|
|
43
43
|
class_name = opts[:class_name] || real_class_name
|
|
44
|
-
|
|
45
|
-
return obj if ['
|
|
44
|
+
# directly return array & hash values
|
|
45
|
+
return obj if ['array', 'hash'].include? class_name
|
|
46
46
|
|
|
47
47
|
data = {}
|
|
48
48
|
# get schema
|
data/lib/schema_tools/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: json_schema_tools
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.5
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date: 2012-12-
|
|
12
|
+
date: 2012-12-30 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: json
|
|
@@ -140,7 +140,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
140
140
|
version: '0'
|
|
141
141
|
segments:
|
|
142
142
|
- 0
|
|
143
|
-
hash:
|
|
143
|
+
hash: -301574637564117079
|
|
144
144
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
145
145
|
none: false
|
|
146
146
|
requirements:
|
|
@@ -149,7 +149,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
149
149
|
version: '0'
|
|
150
150
|
segments:
|
|
151
151
|
- 0
|
|
152
|
-
hash:
|
|
152
|
+
hash: -301574637564117079
|
|
153
153
|
requirements: []
|
|
154
154
|
rubyforge_project:
|
|
155
155
|
rubygems_version: 1.8.24
|