scorpio 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: fef9d45f74d30432978fa58501add04b3fc60226
4
- data.tar.gz: 2e8c5c985076afe3da550d1a8e1fe4c19a6f3b5d
2
+ SHA256:
3
+ metadata.gz: 4c02ae6ac0aa557b45883e8b1261ed89cf7f98d65a4c3a1224144aefba1abe0e
4
+ data.tar.gz: 4961d26ac46421417cb40ca6929c7fca53007d773457860cb18006a1c38dbf49
5
5
  SHA512:
6
- metadata.gz: 8f1b1ff00e8c06761980421abb2c15b7bfc6584ab8db1e4fe4dc8159817d3a2ac827eca12e374c6851817b72d4b40e02b5577f164dc6e36a8514f4e5d69a86c3
7
- data.tar.gz: c23470636bd6456a1d8bd23c469e4b6595c070b317fda0579a439b591077319471aa57daf12390bf81336a1a4068bb90c8f5ba09cc2f3ac3830c7f97ca6a1de2
6
+ metadata.gz: e7c669c5820372b7abc5d8a881b37c73d681f051a70309b68f61574be58f5b1eac4d3928a4419aecb59a2c415c29eeb329cdd4327b60cb31604a9a5ad63ef855
7
+ data.tar.gz: a435561553f6ab3c9fff2e122fbfed6d56126688f23ea7a7579a0999a281e66b046c224ff2ae398ffeb827e68f2a080867d364b0b8a3b6c586a4a8f01f41b854
@@ -1,3 +1,7 @@
1
+ # v0.2.1
2
+ - SchemaInstanceBase#parent, #parents
3
+ - compatibility fix #as_json
4
+
1
5
  # v0.2.0
2
6
 
3
7
  # v0.1.0
@@ -114,8 +114,8 @@ module Scorpio
114
114
  pointer.fragment
115
115
  end
116
116
 
117
- def as_json
118
- Typelike.as_json(content)
117
+ def as_json(*opt)
118
+ Typelike.as_json(content, *opt)
119
119
  end
120
120
 
121
121
  # takes a block. the block is yielded the content of this node. the block MUST return a modified
@@ -205,8 +205,8 @@ module Scorpio
205
205
 
206
206
  include Arraylike
207
207
 
208
- def as_json # needs redefined after including Enumerable
209
- Typelike.as_json(content)
208
+ def as_json(*opt) # needs redefined after including Enumerable
209
+ Typelike.as_json(content, *opt)
210
210
  end
211
211
 
212
212
  # methods that don't look at the value; can skip the overhead of #[] (invoked by #to_a).
@@ -233,8 +233,8 @@ module Scorpio
233
233
 
234
234
  include Hashlike
235
235
 
236
- def as_json # needs redefined after including Enumerable
237
- Typelike.as_json(content)
236
+ def as_json(*opt) # needs redefined after including Enumerable
237
+ Typelike.as_json(content, *opt)
238
238
  end
239
239
 
240
240
  # methods that don't look at the value; can skip the overhead of #[] (invoked by #to_hash)
@@ -138,8 +138,18 @@ module Scorpio
138
138
  JsonReference = openapi_class.call('definitions', 'jsonReference')
139
139
 
140
140
  class Operation
141
- attr_accessor :path
142
- attr_accessor :http_method
141
+ attr_writer :path
142
+ attr_writer :http_method
143
+ def path
144
+ @path ||= if parent.is_a?(Scorpio::OpenAPI::V2::PathItem) && parent.parent.is_a?(Scorpio::OpenAPI::V2::Paths)
145
+ parent.instance.path.last
146
+ end
147
+ end
148
+ def http_method
149
+ @http_method ||= if parent.is_a?(Scorpio::OpenAPI::V2::PathItem)
150
+ instance.path.last
151
+ end
152
+ end
143
153
 
144
154
  # there should only be one body parameter; this returns it
145
155
  def body_parameter
@@ -128,8 +128,6 @@ module Scorpio
128
128
  unless operation.is_a?(Scorpio::OpenAPI::V2::Operation)
129
129
  raise("bad operation at #{operation.fragment}: #{operation.pretty_inspect}")
130
130
  end
131
- operation.path = path
132
- operation.http_method = http_method
133
131
  end
134
132
  end
135
133
 
@@ -217,8 +215,6 @@ module Scorpio
217
215
  openapi_document.paths.each do |path, path_item|
218
216
  path_item.each do |http_method, operation|
219
217
  next if http_method == 'parameters' # parameters is not an operation. TOOD maybe just select the keys that are http methods?
220
- operation.path = path
221
- operation.http_method = http_method
222
218
  method_name = method_names_by_operation[operation]
223
219
  # class method
224
220
  if operation_for_resource_class?(operation) && !respond_to?(method_name)
@@ -534,8 +530,8 @@ module Scorpio
534
530
  response
535
531
  end
536
532
 
537
- def as_json
538
- Typelike.as_json(@attributes)
533
+ def as_json(*opt)
534
+ Typelike.as_json(@attributes, *opt)
539
535
  end
540
536
 
541
537
  def inspect
@@ -45,11 +45,12 @@ module Scorpio
45
45
  end
46
46
  end
47
47
 
48
- def initialize(instance)
48
+ def initialize(instance, origin: nil)
49
49
  unless respond_to?(:schema)
50
50
  raise(TypeError, "cannot instantiate #{self.class.inspect} which has no method #schema. please use Scorpio.class_for_schema")
51
51
  end
52
52
 
53
+ @origin = origin || self
53
54
  self.instance = instance
54
55
 
55
56
  if @instance.is_a?(Scorpio::JSON::HashNode)
@@ -62,25 +63,37 @@ module Scorpio
62
63
  end
63
64
 
64
65
  module OverrideFromExtensions
65
- def as_json
66
- Typelike.as_json(instance)
66
+ def as_json(*opt)
67
+ Typelike.as_json(instance, *opt)
67
68
  end
68
69
  end
69
70
 
70
71
  attr_reader :instance
71
72
 
73
+ def parents
74
+ parent = @origin
75
+ (@origin.instance.path.size...self.instance.path.size).map do |i|
76
+ parent.tap do
77
+ parent = parent[self.instance.path[i]]
78
+ end
79
+ end.reverse
80
+ end
81
+ def parent
82
+ parents.first
83
+ end
84
+
72
85
  def deref
73
86
  derefed = instance.deref
74
87
  if derefed.object_id == instance.object_id
75
88
  self
76
89
  else
77
- self.class.new(derefed)
90
+ self.class.new(derefed, origin: @origin)
78
91
  end
79
92
  end
80
93
 
81
94
  def modified_copy(&block)
82
95
  modified_instance = instance.modified_copy(&block)
83
- self.class.new(modified_instance)
96
+ self.class.new(modified_instance, origin: @origin)
84
97
  end
85
98
 
86
99
  def fragment
@@ -250,7 +263,7 @@ module Scorpio
250
263
  property_schema = property_schema && property_schema.match_to_instance(instance[property_name])
251
264
 
252
265
  if property_schema && instance[property_name].is_a?(JSON::Node)
253
- Scorpio.class_for_schema(property_schema).new(instance[property_name])
266
+ Scorpio.class_for_schema(property_schema).new(instance[property_name], origin: @origin)
254
267
  else
255
268
  instance[property_name]
256
269
  end
@@ -291,7 +304,7 @@ module Scorpio
291
304
  index_schema = index_schema && index_schema.match_to_instance(instance[i])
292
305
 
293
306
  if index_schema && instance[i].is_a?(JSON::Node)
294
- Scorpio.class_for_schema(index_schema).new(instance[i])
307
+ Scorpio.class_for_schema(index_schema).new(instance[i], origin: @origin)
295
308
  else
296
309
  instance[i]
297
310
  end
@@ -9,24 +9,24 @@ module Scorpio
9
9
  end
10
10
 
11
11
  # I could require 'json/add/core' and use #as_json but I like this better.
12
- def self.as_json(object)
12
+ def self.as_json(object, *opt)
13
13
  if object.respond_to?(:to_hash)
14
14
  object.map do |k, v|
15
15
  unless k.is_a?(Symbol) || k.respond_to?(:to_str)
16
16
  raise(TypeError, "json object (hash) cannot be keyed with: #{k.pretty_inspect.chomp}")
17
17
  end
18
- {k.to_s => as_json(v)}
18
+ {k.to_s => as_json(v, *opt)}
19
19
  end.inject({}, &:update)
20
20
  elsif object.respond_to?(:to_ary)
21
- object.map { |e| as_json(e) }
21
+ object.map { |e| as_json(e, *opt) }
22
22
  elsif [String, TrueClass, FalseClass, NilClass, Numeric].any? { |c| object.is_a?(c) }
23
23
  object
24
24
  elsif object.is_a?(Symbol)
25
25
  object.to_s
26
26
  elsif object.is_a?(Set)
27
- as_json(object.to_a)
27
+ as_json(object.to_a, *opt)
28
28
  elsif object.respond_to?(:as_json)
29
- as_json(object.as_json)
29
+ as_json(object.as_json(*opt), *opt)
30
30
  else
31
31
  raise(TypeError, "cannot express object as json: #{object.pretty_inspect.chomp}")
32
32
  end
@@ -1,3 +1,3 @@
1
1
  module Scorpio
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scorpio
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ethan
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-07-25 00:00:00.000000000 Z
11
+ date: 2018-08-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -289,7 +289,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
289
289
  version: '0'
290
290
  requirements: []
291
291
  rubyforge_project:
292
- rubygems_version: 2.4.5.5
292
+ rubygems_version: 2.7.7
293
293
  signing_key:
294
294
  specification_version: 4
295
295
  summary: Scorpio REST client