json_refs 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.travis.yml +1 -2
- data/README.md +22 -0
- data/json_refs.gemspec +1 -1
- data/lib/json_refs.rb +50 -4
- data/lib/json_refs/version.rb +1 -1
- metadata +5 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f9d9b14ec87e1407d7d3b00072fb482411ca869be27fb0a0834b318f36fe67bf
|
4
|
+
data.tar.gz: a2da652fad017f11c8351cea424d5bf9771e1d316fb23c953f28d7f2d34601d9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 227cfbe8ae21a70547f77dd3985b6d7f2213d053e9691edf025cedb884f1a810a019399ab6ec0bba649370ce1da21490f102ceb4977643f968112f558ac671e8
|
7
|
+
data.tar.gz: 9022c0601623fe3c21cfafe5b480ae5c2feeefd2dff89cc6a436b54d0087ab275aaee11c683af8aa1239abdef21baec7476fe3d93743a322272ee24b9ab8c998
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -39,8 +39,30 @@ json = {
|
|
39
39
|
'$ref' => 'http://httpbin.org/user-agent'
|
40
40
|
}
|
41
41
|
}
|
42
|
+
JsonRefs.(json)
|
42
43
|
```
|
43
44
|
|
45
|
+
YAML is also available for file format.
|
46
|
+
```ruby
|
47
|
+
json = {
|
48
|
+
'a' => {
|
49
|
+
'$ref' => '/path/to/yaml.yml'
|
50
|
+
},
|
51
|
+
'b' => {
|
52
|
+
'$ref' => '/path/to/yaml.yaml'
|
53
|
+
}
|
54
|
+
}
|
55
|
+
JsonRefs.(json)
|
56
|
+
```
|
57
|
+
|
58
|
+
In case you don't want to resolve local references or file references, you have the following options
|
59
|
+
to pass down when you initialize the JSONRefs. If you don't pass the following, both references will be resolved.
|
60
|
+
```ruby
|
61
|
+
JsonRefs.(json, { resolve_local_ref: false, resolve_file_ref: true })
|
62
|
+
```
|
63
|
+
|
64
|
+
JSONRef supports recursive reference resolving. If one the files that you reference have another reference in it, JSONRef will try to automatically resolve that.
|
65
|
+
|
44
66
|
## Development
|
45
67
|
|
46
68
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/json_refs.gemspec
CHANGED
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
|
|
23
23
|
|
24
24
|
spec.add_dependency "hana"
|
25
25
|
|
26
|
-
spec.add_development_dependency "bundler", "~>
|
26
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
27
27
|
spec.add_development_dependency "rake", "~> 10.0"
|
28
28
|
spec.add_development_dependency "rspec", "~> 3.0"
|
29
29
|
end
|
data/lib/json_refs.rb
CHANGED
@@ -2,13 +2,14 @@ require 'json_refs/version'
|
|
2
2
|
require 'json_refs/dereference_handler'
|
3
3
|
|
4
4
|
module JsonRefs
|
5
|
-
def self.call(doc)
|
6
|
-
Dereferencer.new(doc).call
|
5
|
+
def self.call(doc, options = {})
|
6
|
+
Dereferencer.new(doc, options).call
|
7
7
|
end
|
8
8
|
|
9
9
|
class Dereferencer
|
10
|
-
def initialize(doc)
|
10
|
+
def initialize(doc, options = {})
|
11
11
|
@doc = doc
|
12
|
+
@options = options
|
12
13
|
end
|
13
14
|
|
14
15
|
def call(doc = @doc, keys = [])
|
@@ -39,8 +40,53 @@ module JsonRefs
|
|
39
40
|
end
|
40
41
|
|
41
42
|
def referenced_value(referenced_path)
|
42
|
-
|
43
|
+
if @options[:logging] == true
|
44
|
+
puts "De-referencing #{referenced_path}"
|
45
|
+
end
|
46
|
+
|
47
|
+
if referenced_path =~ /^#/
|
48
|
+
dereference_local(referenced_path)
|
49
|
+
else
|
50
|
+
dereference_file(referenced_path)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def dereference_local(referenced_path)
|
55
|
+
if @options[:resolve_local_ref] === false
|
56
|
+
return { '$ref': referenced_path }
|
57
|
+
end
|
58
|
+
|
59
|
+
klass = JsonRefs::DereferenceHandler::Local
|
43
60
|
klass.new(path: referenced_path, doc: @doc).call
|
44
61
|
end
|
62
|
+
|
63
|
+
def dereference_file(referenced_path)
|
64
|
+
if @options[:resolve_file_ref] === false
|
65
|
+
return { '$ref': referenced_path }
|
66
|
+
end
|
67
|
+
|
68
|
+
klass = JsonRefs::DereferenceHandler::File
|
69
|
+
|
70
|
+
# Checking for "://" in a URL like http://something.com so as to determine if it's a remote URL
|
71
|
+
remote_uri = referenced_path =~ /:\/\//
|
72
|
+
|
73
|
+
if remote_uri
|
74
|
+
klass.new(path: referenced_path, doc: @doc).call
|
75
|
+
else
|
76
|
+
recursive_dereference(referenced_path, klass)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def recursive_dereference(referenced_path, klass)
|
81
|
+
directory = File.dirname(referenced_path)
|
82
|
+
filename = File.basename(referenced_path)
|
83
|
+
|
84
|
+
dereferenced_doc = {}
|
85
|
+
Dir.chdir(directory) do
|
86
|
+
referenced_doc = klass.new(path: filename, doc: @doc).call
|
87
|
+
dereferenced_doc = Dereferencer.new(referenced_doc, @options).call
|
88
|
+
end
|
89
|
+
dereferenced_doc
|
90
|
+
end
|
45
91
|
end
|
46
92
|
end
|
data/lib/json_refs/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: json_refs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Makoto Tajitsu
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-02-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: hana
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '2.0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '2.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -106,8 +106,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
106
106
|
- !ruby/object:Gem::Version
|
107
107
|
version: '0'
|
108
108
|
requirements: []
|
109
|
-
|
110
|
-
rubygems_version: 2.6.11
|
109
|
+
rubygems_version: 3.0.3
|
111
110
|
signing_key:
|
112
111
|
specification_version: 4
|
113
112
|
summary: Dereference JSON Pointer
|