jimmy 0.4.8 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -0
- data/jimmy.gemspec +1 -1
- data/lib/jimmy/domain.rb +6 -2
- data/lib/jimmy/schema_types/object.rb +3 -1
- data/lib/jimmy/transform_keys.rb +31 -0
- data/lib/jimmy/version.rb +1 -1
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a57c984eab30453b66049bd8720bfcb7a18ff973
|
4
|
+
data.tar.gz: f157a9c9e255a546e79119a2cb1a5d0c9a353b17
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9db24fb7aacca4036027e564cdbe6a0dbbb8e65743958d4e7d41e0aecd85d4d8d5cabb13ecdf8f7e5e40b89ee8154567de3266a074aa1e2873be215b7b9cd124
|
7
|
+
data.tar.gz: 0a863b9d1e2b3c1483f6b7ccf57c29518d89eb66e59da556fd566e92f7e0690af6fd3a0af33eee38beda3bcbbbe03c9316a944b94c7fc94d76aebd05dfd4a559
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.1.5
|
data/jimmy.gemspec
CHANGED
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
|
|
11
11
|
|
12
12
|
spec.summary = 'Jimmy the JSON Schema DSL'
|
13
13
|
spec.description = 'Jimmy makes it a snap to compose detailed JSON schema documents.'
|
14
|
-
spec.homepage = 'https://github.com/
|
14
|
+
spec.homepage = 'https://github.com/hx/jimmy'
|
15
15
|
|
16
16
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
17
|
spec.bindir = 'bin'
|
data/lib/jimmy/domain.rb
CHANGED
@@ -7,16 +7,20 @@ require_relative 'schema_creation'
|
|
7
7
|
|
8
8
|
module Jimmy
|
9
9
|
class Domain
|
10
|
+
DEFAULT_OPTIONS = {
|
11
|
+
transform_keys: nil
|
12
|
+
}
|
10
13
|
|
11
|
-
attr_reader :root, :types, :partials
|
14
|
+
attr_reader :root, :types, :partials, :options
|
12
15
|
|
13
|
-
def initialize(root)
|
16
|
+
def initialize(root, **options)
|
14
17
|
@root = URI(root)
|
15
18
|
@schemas = {}
|
16
19
|
@types = {}
|
17
20
|
@partials = {}
|
18
21
|
@import_paths = []
|
19
22
|
@uri_formatter = -> _, name { @root + "#{name}.json#" }
|
23
|
+
@options = DEFAULT_OPTIONS.merge(options)
|
20
24
|
end
|
21
25
|
|
22
26
|
def domain
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require_relative '../transform_keys'
|
2
|
+
|
1
3
|
module Jimmy
|
2
4
|
class SchemaTypes::Object < SchemaType
|
3
5
|
register!
|
@@ -20,7 +22,7 @@ module Jimmy
|
|
20
22
|
trait(:allow_additional) { attrs[:additional_properties] = true }
|
21
23
|
|
22
24
|
nested do |schema, property_name|
|
23
|
-
(attrs[:properties] ||= {})[property_name] = schema
|
25
|
+
(attrs[:properties] ||= {})[TransformKeys.transformer.transform(property_name, domain.options[:transform_keys])] = schema
|
24
26
|
end
|
25
27
|
|
26
28
|
compile do |hash|
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Jimmy
|
2
|
+
module TransformKeys
|
3
|
+
def camel_upper(str)
|
4
|
+
camel_lower(str).sub(/\A(.)/) { $1.upcase }
|
5
|
+
end
|
6
|
+
|
7
|
+
def camel_lower(str)
|
8
|
+
str.gsub(/[-_\s]+(.)/) { $1.upcase }
|
9
|
+
end
|
10
|
+
|
11
|
+
class Transformer
|
12
|
+
include TransformKeys
|
13
|
+
|
14
|
+
def cache(method)
|
15
|
+
(@cache ||= {})[method] ||= {}
|
16
|
+
end
|
17
|
+
|
18
|
+
def transform(sym, method)
|
19
|
+
if method
|
20
|
+
cache(method)[sym] ||= __send__(method, sym.to_s).to_sym
|
21
|
+
else
|
22
|
+
sym
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.transformer
|
28
|
+
@transformer ||= Transformer.new
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/jimmy/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jimmy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Neil E. Pearson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-12-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json-schema
|
@@ -88,6 +88,7 @@ extensions: []
|
|
88
88
|
extra_rdoc_files: []
|
89
89
|
files:
|
90
90
|
- ".gitignore"
|
91
|
+
- ".ruby-version"
|
91
92
|
- Gemfile
|
92
93
|
- LICENSE
|
93
94
|
- README.md
|
@@ -112,10 +113,11 @@ files:
|
|
112
113
|
- lib/jimmy/schema_types/object.rb
|
113
114
|
- lib/jimmy/schema_types/string.rb
|
114
115
|
- lib/jimmy/symbol_array.rb
|
116
|
+
- lib/jimmy/transform_keys.rb
|
115
117
|
- lib/jimmy/type_reference.rb
|
116
118
|
- lib/jimmy/validation_error.rb
|
117
119
|
- lib/jimmy/version.rb
|
118
|
-
homepage: https://github.com/
|
120
|
+
homepage: https://github.com/hx/jimmy
|
119
121
|
licenses:
|
120
122
|
- Apache License, Version 2.0
|
121
123
|
metadata: {}
|
@@ -135,7 +137,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
135
137
|
version: '0'
|
136
138
|
requirements: []
|
137
139
|
rubyforge_project:
|
138
|
-
rubygems_version: 2.4.
|
140
|
+
rubygems_version: 2.4.3
|
139
141
|
signing_key:
|
140
142
|
specification_version: 4
|
141
143
|
summary: Jimmy the JSON Schema DSL
|