json_refs 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -2
- data/README.md +9 -4
- data/lib/json_refs.rb +15 -1
- data/lib/json_refs/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e623d13bcd51a7a1e254203e15c508065467469b
|
4
|
+
data.tar.gz: 3a3ad67d1afd4df069fa1f4810a0a8ed20a03232
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 582f64c455143f262e407f97aabf3e4223ff7d59dab9c0d5a0ff6fa2ff874b287a063a583845e3cf77749565412dc881dbfd57e0a24346dcdc6cef39023fa48d
|
7
|
+
data.tar.gz: d23cc3d915cadca4a3b1b70c25cd2d63fc80ddd043e4e27d66eb73d676916805f57b86f9cc8eaeec707b9dfd47569ebc1992851f1c509c86b0921d9e2e333100
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,10 @@
|
|
1
|
+
[![Build Status](https://travis-ci.org/tzmfreedom/json_refs.svg?branch=master)](https://travis-ci.org/tzmfreedom/json_refs)
|
2
|
+
|
1
3
|
# JsonRefs
|
2
4
|
|
3
|
-
|
5
|
+
Dereference JSON reference with JSON Pointer.
|
4
6
|
|
5
|
-
|
7
|
+
'$refs' value is replaced with referenced value.
|
6
8
|
|
7
9
|
## Installation
|
8
10
|
|
@@ -22,7 +24,10 @@ Or install it yourself as:
|
|
22
24
|
|
23
25
|
## Usage
|
24
26
|
|
25
|
-
|
27
|
+
```ruby
|
28
|
+
json = { 'a' => 'foo', 'b' => { '$ref' => '#/a' } }
|
29
|
+
JsonRefs.(json) # {"a"=>"foo", "b"=>"foo"}
|
30
|
+
```
|
26
31
|
|
27
32
|
## Development
|
28
33
|
|
@@ -32,7 +37,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
32
37
|
|
33
38
|
## Contributing
|
34
39
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
40
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/tzmfreedom/json_refs.
|
36
41
|
|
37
42
|
## License
|
38
43
|
|
data/lib/json_refs.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
require "json_refs/version"
|
2
2
|
require 'hana'
|
3
|
+
require 'net/http'
|
4
|
+
require 'json'
|
3
5
|
|
4
6
|
module JsonRefs
|
5
7
|
def self.call(doc)
|
@@ -35,7 +37,19 @@ module JsonRefs
|
|
35
37
|
target = paths.inject(@doc) do |obj, key|
|
36
38
|
obj[key]
|
37
39
|
end
|
38
|
-
target[key] =
|
40
|
+
target[key] = referenced_value(referenced_path)
|
41
|
+
end
|
42
|
+
|
43
|
+
def referenced_value(referenced_path)
|
44
|
+
if referenced_path =~ /^#/
|
45
|
+
Hana::Pointer.new(referenced_path[1..-1]).eval(@doc)
|
46
|
+
elsif referenced_path =~ /^(http:\/\/|https:\/\/)/
|
47
|
+
json = Net::HTTP.get(URI.parse(referenced_path))
|
48
|
+
JSON.load(json)
|
49
|
+
else
|
50
|
+
f = File.open(referenced_path)
|
51
|
+
JSON.load(f)
|
52
|
+
end
|
39
53
|
end
|
40
54
|
end
|
41
55
|
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.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Makoto Tajitsu
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-11-
|
11
|
+
date: 2017-11-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: hana
|