dato 0.7.17 → 0.7.18

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
2
  SHA256:
3
- metadata.gz: fe8a9078fb6f9d6b37f6d9e371dbfcd417b2be9d2108395ad742a37b1f361262
4
- data.tar.gz: 3466ff70f311f4c7208ff37ce20c2b2753cfd9eac05ac912cc42412748be3244
3
+ metadata.gz: 43d5a65257051385168de064d1b162bbd0bc5d0ef8523a2079d2f9051dc6b509
4
+ data.tar.gz: 23a9293ed05685fd635de711d3b98084dcb9efc92735d0e379b7640798e8a959
5
5
  SHA512:
6
- metadata.gz: 23adcec27891f974552ee201cddc28b982579f849ffbaaaf88c4fad678460ce10effec7a52a65a4cd548253f79bfbe22c98b6f78caf8c95fb6dba3005b4eab3d
7
- data.tar.gz: 32aea1391ce6f54ab64af0de2ec95619b7a3ece9644dfa98ed0b6bcefa819de797ea3b6b87741235b561a73aab952643cb9ecf47e7fae97cc9d323700f60360e
6
+ metadata.gz: cd30a74fe816ab8d4a3683d62ddfecd1ce350f94c94a4f4bbbcaaabaf88a94677f939c8d7cfaf0c9769040d03adc7da829229d5e8762610491ca7d199244e082
7
+ data.tar.gz: 47ebdc307a2c8ae71cd28f0b7ce60c4e2f14802951bbed9b90bd93ff359bd41c240dc3dc4c834febafd32ebe81b4f735f05f9d01a2f7ea245ad9df4324938501
@@ -33,27 +33,54 @@ module Dato
33
33
  @extra_headers = options[:extra_headers] || {}
34
34
  end
35
35
 
36
- # FOR DEV
37
- # "http://#{subdomain}.lvh.me:3001/docs/#{subdomain}-hyperschema.json"
36
+ define_singleton_method(:subdomain) do
37
+ subdomain
38
+ end
39
+ end
40
+ end
41
+
42
+ def respond_to_missing?(method, include_private = false)
43
+ json_schema.definitions.each do |type, obj|
44
+ is_collection = obj.links.select { |x| x.rel == 'instances' }.any?
45
+ namespace = is_collection ? type.pluralize : type
46
+ if method.to_s === namespace
47
+ return true
48
+ end
49
+ end
50
+
51
+ super
52
+ end
53
+
54
+ def method_missing(method, *args, &block)
55
+ json_schema.definitions.each do |type, obj|
56
+ is_collection = obj.links.select { |x| x.rel == 'instances' }.any?
57
+ namespace = is_collection ? type.pluralize : type
58
+
59
+ if method.to_s === namespace
60
+ instance_variable_set(
61
+ "@#{namespace}",
62
+ instance_variable_get("@#{namespace}") ||
63
+ Dato::Repo.new(self, type, obj)
64
+ )
65
+
66
+ return instance_variable_get("@#{namespace}")
67
+ end
68
+ end
69
+
70
+ super
71
+ end
72
+
73
+ def json_schema
74
+ @json_schema ||= begin
38
75
  response = Faraday.get(
39
- "https://#{subdomain}.datocms.com/docs/#{subdomain}-hyperschema.json"
76
+ # "http://#{subdomain}.lvh.me:3001/docs/#{subdomain}-hyperschema.json"
77
+ "#{base_url}/docs/#{self.class.subdomain}-hyperschema.json"
40
78
  )
41
79
 
42
80
  schema = JsonSchema.parse!(JSON.parse(response.body))
43
81
  schema.expand_references!
44
82
 
45
- schema.definitions.each do |type, obj|
46
- is_collection = obj.links.select { |x| x.rel == 'instances' }.any?
47
- namespace = is_collection ? type.pluralize : type
48
-
49
- define_method(namespace) do
50
- instance_variable_set(
51
- "@#{namespace}",
52
- instance_variable_get("@#{namespace}") ||
53
- Dato::Repo.new(self, type, obj)
54
- )
55
- end
56
- end
83
+ schema
57
84
  end
58
85
  end
59
86
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Dato
4
- VERSION = '0.7.17'
4
+ VERSION = '0.7.18'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dato
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.17
4
+ version: 0.7.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stefano Verna
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-10-07 00:00:00.000000000 Z
11
+ date: 2020-10-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler