json_refs 0.1.7 → 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: 1189625a84d998e3d9a6f249368c187bf0144393271aec06398830ba0ddc66a1
4
- data.tar.gz: c079bf4dbf63782819d5d1081396c7f9e8ad9f155e5ef701ca337a6a21f3a176
3
+ metadata.gz: ac8b41fb0b17e6fd994f10e4300d37be8e32c96a45f86a565d79a72315f858e3
4
+ data.tar.gz: cdc3180ec3c492f86ac4250e2a716953d0c70523ade7aa749411998761d16174
5
5
  SHA512:
6
- metadata.gz: b18e096f64d639506cc39728e426af5ff276bee765c69331ba9a32d401299439367a851142717ab51214755ef2934eb34793a582e3cda73782fd8f5394eef3ce
7
- data.tar.gz: afab208bf473c6f575761b0e51a83a99e8abefe625e185f13ebb93caed688e9e882eba9bdec49925a53e646eb22d61f59b6d4d8aec3db219ef2f28e09964c1fa
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
  ```
@@ -12,7 +12,7 @@ module JsonRefs
12
12
 
13
13
  class Yaml
14
14
  def call(file)
15
- YAML.load(file)
15
+ RUBY_VERSION >= '3.1.0' ? YAML.unsafe_load(file) : YAML.load(file)
16
16
  end
17
17
  end
18
18
 
@@ -1,3 +1,3 @@
1
1
  module JsonRefs
2
- VERSION = "0.1.7"
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.7
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: 2021-11-18 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
@@ -106,7 +106,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
106
106
  - !ruby/object:Gem::Version
107
107
  version: '0'
108
108
  requirements: []
109
- rubygems_version: 3.2.22
109
+ rubygems_version: 3.2.31
110
110
  signing_key:
111
111
  specification_version: 4
112
112
  summary: Dereference JSON Pointer