json_refs 0.1.8 → 0.1.9

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
  SHA256:
3
- metadata.gz: 3192dc90d1f03c619968c9a04fb9dce1ed954c7edf9d25b5d2ec3ce2fb28e3ef
4
- data.tar.gz: 854faad63c25ac8140bef79411850c4bc1d83078b613fac740a1d678e37f0d24
3
+ metadata.gz: ac8b41fb0b17e6fd994f10e4300d37be8e32c96a45f86a565d79a72315f858e3
4
+ data.tar.gz: cdc3180ec3c492f86ac4250e2a716953d0c70523ade7aa749411998761d16174
5
5
  SHA512:
6
- metadata.gz: 56a13e01d8bda8d1f082cf0b60803fd9f84cfcb519818beaafe7e6b20f181e591f0b3a01842c6fd8a88a2711372c3980217072386ae7fe2c4fee786470752665
7
- data.tar.gz: defa91538c2a50339efbb1155382bf04ac7eadeea27a0f8202e4c3847c5b87138fe06bdf6e0125eee74038a1979a58d162b1bb8d40a400edca6dbdf426d8e11d
6
+ metadata.gz: 4f01c5505778ec33889fb382607eedd229b35d6d5ee5f209c79bc64ce0d6dca516f8deba10ecda62021d4def351dcc6acdf9a8d7097c571899b8b894cb229af5
7
+ data.tar.gz: f6fc1d89b79506dba84759e5d88e09b0909d6e4f593614c74cabdeb2095a22e7ca97361774b73aeed83e2ce8c9c50117c79e1c54b72dbf2b38b57473a576e7af
data/README.md CHANGED
@@ -25,6 +25,8 @@ Or install it yourself as:
25
25
  ## Usage
26
26
 
27
27
  ```ruby
28
+ JsonRefs.load('my/file.yaml') # or .yml, .json
29
+
28
30
  json = { 'a' => 'foo', 'b' => { '$ref' => '#/a' } }
29
31
  JsonRefs.(json) # {"a"=>"foo", "b"=>"foo"}
30
32
  ```
@@ -1,3 +1,3 @@
1
1
  module JsonRefs
2
- VERSION = "0.1.8"
2
+ VERSION = "0.1.9"
3
3
  end
data/lib/json_refs.rb CHANGED
@@ -4,16 +4,23 @@ require 'json_refs/dereference_handler'
4
4
  module JsonRefs
5
5
  class << self
6
6
  def call(doc, options = {})
7
- Dereferencer.new(doc, options).call
7
+ Dereferencer.new(Dir.pwd, doc, options).call
8
8
  end
9
9
 
10
10
  alias_method :dereference, :call
11
+
12
+ def load(filename, options = {})
13
+ doc_dir = File.dirname(filename)
14
+ doc = Loader.handle(filename)
15
+ Dereferencer.new(doc_dir, doc, options).call
16
+ end
11
17
  end
12
18
 
13
19
  class Dereferencer
14
- def initialize(doc, options = {})
20
+ def initialize(doc_dir, doc, options = {})
15
21
  @doc = doc
16
22
  @options = options
23
+ @doc_dir = doc_dir
17
24
  end
18
25
 
19
26
  def call(doc = @doc, keys = [])
@@ -35,6 +42,8 @@ module JsonRefs
35
42
 
36
43
  private
37
44
 
45
+ attr_reader :doc_dir
46
+
38
47
  def dereference(paths, referenced_path)
39
48
  key = paths.pop
40
49
  target = paths.inject(@doc) do |obj, key|
@@ -95,15 +104,13 @@ module JsonRefs
95
104
  end
96
105
 
97
106
  def recursive_dereference(referenced_path, klass)
107
+ unless File.absolute_path?(referenced_path)
108
+ referenced_path = "#{doc_dir}/#{referenced_path}"
109
+ end
98
110
  directory = File.dirname(referenced_path)
99
- filename = File.basename(referenced_path)
100
111
 
101
- dereferenced_doc = {}
102
- Dir.chdir(directory) do
103
- referenced_doc = klass.new(path: filename, doc: @doc).call
104
- dereferenced_doc = Dereferencer.new(referenced_doc, @options).call
105
- end
106
- dereferenced_doc
112
+ referenced_doc = klass.new(path: referenced_path, doc: @doc).call
113
+ Dereferencer.new(directory, referenced_doc, @options).call
107
114
  end
108
115
  end
109
116
  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.8
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Makoto Tajitsu
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-04-28 00:00:00.000000000 Z
11
+ date: 2024-05-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hana