apiql 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/README.md +1 -1
- data/apiql.gemspec +1 -1
- data/lib/apiql.rb +17 -13
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 606ec19046f5d0a10b8717fad7801ee405cf7bf08eff0860a807f068d5bbd43c
|
4
|
+
data.tar.gz: 5a9575433ba303af1ef9abdb224e307c46e0768e20b44b46d060000dc498219d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0ac0ce3e33ef86f3c80c9a12c5548d6939e37c2e16463a48f24f19aea07d45f2eb0d60ad6a615a300020a6e31304ecd3d34a7309fe4ac8b5b2370d6d943e738b
|
7
|
+
data.tar.gz: fadc9d88e7ec1662c1b676f4d21e410edd7ec4d530ae020dbc91eedcfca180510bb137ec5cc604062a6a7ed734b652ea5ab042883f6b564c395d950ab1195224
|
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
*.gem
|
data/README.md
CHANGED
data/apiql.gemspec
CHANGED
data/lib/apiql.rb
CHANGED
@@ -10,8 +10,6 @@ class APIQL
|
|
10
10
|
class Error < StandardError; end
|
11
11
|
class CacheMissed < StandardError; end
|
12
12
|
|
13
|
-
attr_reader :context
|
14
|
-
|
15
13
|
class << self
|
16
14
|
@@cache = {}
|
17
15
|
|
@@ -54,11 +52,7 @@ class APIQL
|
|
54
52
|
|
55
53
|
def initialize(binder, *fields)
|
56
54
|
@context = ::APIQL::Context.new(binder, *fields)
|
57
|
-
|
58
|
-
class_eval do
|
59
|
-
delegate field, to: :context
|
60
|
-
end
|
61
|
-
end
|
55
|
+
@context.inject_delegators(self)
|
62
56
|
end
|
63
57
|
|
64
58
|
def render(schema)
|
@@ -85,7 +79,7 @@ class APIQL
|
|
85
79
|
keys, last_key = pool.pop
|
86
80
|
|
87
81
|
if pool.empty?
|
88
|
-
result[function] = context.render_value(data, last_keys)
|
82
|
+
result[function] = @context.render_value(data, last_keys)
|
89
83
|
function = nil
|
90
84
|
else
|
91
85
|
keys.delete(last_key)
|
@@ -105,7 +99,7 @@ class APIQL
|
|
105
99
|
schema = reg[:rest]
|
106
100
|
|
107
101
|
function = reg[:name]
|
108
|
-
params = context.parse_params(reg[:params])
|
102
|
+
params = @context.parse_params(reg[:params])
|
109
103
|
|
110
104
|
data = public_send(function, *params)
|
111
105
|
|
@@ -120,7 +114,7 @@ class APIQL
|
|
120
114
|
schema = reg[:rest]
|
121
115
|
|
122
116
|
function = reg[:name]
|
123
|
-
params = context.parse_params(reg[:params])
|
117
|
+
params = @context.parse_params(reg[:params])
|
124
118
|
|
125
119
|
data = public_send(function, *params)
|
126
120
|
if data.is_a? Array
|
@@ -164,11 +158,12 @@ class APIQL
|
|
164
158
|
end
|
165
159
|
end
|
166
160
|
|
167
|
-
attr_reader :object
|
161
|
+
attr_reader :object
|
168
162
|
|
169
163
|
def initialize(object, context)
|
170
164
|
@object = object
|
171
165
|
@context = context
|
166
|
+
@context.inject_delegators(self)
|
172
167
|
end
|
173
168
|
|
174
169
|
def render(schema = nil)
|
@@ -196,7 +191,7 @@ class APIQL
|
|
196
191
|
def get_field(field)
|
197
192
|
if field.is_a? Array
|
198
193
|
field, params = field
|
199
|
-
params = context.parse_params(params)
|
194
|
+
params = @context.parse_params(params)
|
200
195
|
end
|
201
196
|
return unless field.to_sym.in? self.class.apiql_attributes
|
202
197
|
|
@@ -231,7 +226,7 @@ class APIQL
|
|
231
226
|
|
232
227
|
def render_value(value, schema = nil)
|
233
228
|
if schema.present?
|
234
|
-
context.render_value(value, schema)
|
229
|
+
@context.render_value(value, schema)
|
235
230
|
else
|
236
231
|
value
|
237
232
|
end
|
@@ -246,6 +241,7 @@ class APIQL
|
|
246
241
|
|
247
242
|
class Context
|
248
243
|
def initialize(binder, *fields)
|
244
|
+
@fields = fields
|
249
245
|
fields.each do |field|
|
250
246
|
instance_variable_set("@#{field}", binder.send(field))
|
251
247
|
class_eval do
|
@@ -254,6 +250,14 @@ class APIQL
|
|
254
250
|
end
|
255
251
|
end
|
256
252
|
|
253
|
+
def inject_delegators(target)
|
254
|
+
@fields.each do |field|
|
255
|
+
target.class_eval do
|
256
|
+
delegate field, to: :@context
|
257
|
+
end
|
258
|
+
end
|
259
|
+
end
|
260
|
+
|
257
261
|
def parse_params(list)
|
258
262
|
list&.split(',')&.map(&:strip)&.map do |name|
|
259
263
|
if reg = name.match(/\A[a-zA-Z]\w*\z/)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: apiql
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dmitry Silchenko
|
@@ -59,6 +59,7 @@ executables: []
|
|
59
59
|
extensions: []
|
60
60
|
extra_rdoc_files: []
|
61
61
|
files:
|
62
|
+
- ".gitignore"
|
62
63
|
- LICENSE
|
63
64
|
- README.md
|
64
65
|
- apiql.gemspec
|