apiql 0.1.5 → 0.1.6

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.
Files changed (6) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/README.md +1 -1
  4. data/apiql.gemspec +1 -1
  5. data/lib/apiql.rb +17 -13
  6. metadata +2 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fb1ebabe8ada909b6d81d7f175c34dfacac5eb97c75af10e29a1ee2f2dd9f4fd
4
- data.tar.gz: 19980e934f637e0fc87b74f014c0ec4edb8f0730be5b8eb2c3562c06aa2b8144
3
+ metadata.gz: 606ec19046f5d0a10b8717fad7801ee405cf7bf08eff0860a807f068d5bbd43c
4
+ data.tar.gz: 5a9575433ba303af1ef9abdb224e307c46e0768e20b44b46d060000dc498219d
5
5
  SHA512:
6
- metadata.gz: b258efa6ec0fbfc2841295ce888503023f41b1e9f85d7a4e76ffff73b569eba8d2d39d6aa30d04f8dcd7f68abaf0df63824d6953d8193a38837f330a67bf1070
7
- data.tar.gz: 3a5ecde6e15da9c3fa6f9f3e3296b6d25fab6686dc318c1e1d0fee9a7bc6759dfb1c589121a2eeaade595649ac0a5fde0266682d24c9e600fac603d1221cc110
6
+ metadata.gz: 0ac0ce3e33ef86f3c80c9a12c5548d6939e37c2e16463a48f24f19aea07d45f2eb0d60ad6a615a300020a6e31304ecd3d34a7309fe4ac8b5b2370d6d943e738b
7
+ data.tar.gz: fadc9d88e7ec1662c1b676f4d21e410edd7ec4d530ae020dbc91eedcfca180510bb137ec5cc604062a6a7ed734b652ea5ab042883f6b564c395d950ab1195224
@@ -0,0 +1 @@
1
+ *.gem
data/README.md CHANGED
@@ -102,7 +102,7 @@ config/initializers/apiql.rb:
102
102
 
103
103
  ```ruby
104
104
  class APIQL
105
- delegate :authorize!, to: :context
105
+ delegate :authorize!, to: :@context
106
106
 
107
107
  class Context
108
108
  def authorize!(*args)
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = 'apiql'
7
- spec.version = '0.1.5'
7
+ spec.version = '0.1.6'
8
8
  spec.authors = ['Dmitry Silchenko']
9
9
  spec.email = ['dmitry@desofto.com']
10
10
 
@@ -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
- fields.each do |field|
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, :context
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.5
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