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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f0bcdbaa895884700d53a32dcc4422c0e6618f17
4
- data.tar.gz: 9f8f74e7311da94f83fc899bcff9fc92c173d4a2
3
+ metadata.gz: e623d13bcd51a7a1e254203e15c508065467469b
4
+ data.tar.gz: 3a3ad67d1afd4df069fa1f4810a0a8ed20a03232
5
5
  SHA512:
6
- metadata.gz: 6c3efed79a7b6a767270220a648fb98f36f112453f0d6c1c134ceb2d0c40a1b5ade83c5bd1cf0a8063e8f87dd879eef181bdfa662131791e7bcc78b7cf59cca8
7
- data.tar.gz: 4001d016043bd9dee2c4c299ac5c7578a1efa84b101d91ff86e578aed7cabc6722f192803b13e29fab0cf3fe12ecbda3ed81a3200620fde8a1b3d34b2646af2c
6
+ metadata.gz: 582f64c455143f262e407f97aabf3e4223ff7d59dab9c0d5a0ff6fa2ff874b287a063a583845e3cf77749565412dc881dbfd57e0a24346dcdc6cef39023fa48d
7
+ data.tar.gz: d23cc3d915cadca4a3b1b70c25cd2d63fc80ddd043e4e27d66eb73d676916805f57b86f9cc8eaeec707b9dfd47569ebc1992851f1c509c86b0921d9e2e333100
@@ -1,5 +1,5 @@
1
1
  sudo: false
2
2
  language: ruby
3
3
  rvm:
4
- - 2.4.1
5
- before_install: gem install bundler -v 1.15.4
4
+ - jruby-head
5
+ - 2.4.2
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
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/json_refs`. To experiment with that code, run `bin/console` for an interactive prompt.
5
+ Dereference JSON reference with JSON Pointer.
4
6
 
5
- TODO: Delete this and the text above, and describe your gem
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
- TODO: Write usage instructions here
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/[USERNAME]/json_refs.
40
+ Bug reports and pull requests are welcome on GitHub at https://github.com/tzmfreedom/json_refs.
36
41
 
37
42
  ## License
38
43
 
@@ -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] = Hana::Pointer.new(referenced_path[1..-1]).eval(@doc)
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
@@ -1,3 +1,3 @@
1
1
  module JsonRefs
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
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.0
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-15 00:00:00.000000000 Z
11
+ date: 2017-11-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hana