lorj 1.0.17 → 1.0.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 +4 -4
- data/lib/core/lorj_basecontroller.rb +99 -51
- data/lib/lorj/version.rb +2 -2
- data/lib/lorj.rb +2 -0
- data/spec/40_lorj_ctrl_spec.rb +295 -0
- data/spec/spec_helper.rb +11 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ae29eb4daeb919aafeedcc2312d5f56c48f55384
|
4
|
+
data.tar.gz: b29b195d80a8c1e0cfd5435db8f405fa8f850a59
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 561aaad92e549e7ed3a1384c2c4d2e7848c1293011b9f8feee3f1e248c54f0bd281fa449abcde5e04c6e4016a3ee85bb32f7fe49f78cdcd8ada3183a5ede6960
|
7
|
+
data.tar.gz: a4b9d1916b46303d56bcc1dbb1272db560054d5012997c6794017b361ae5ea39f1ec07b2fb5c6d2305cbc94cc6ea17e0107e236566d63c14f786e7de3fd16dad
|
@@ -138,26 +138,46 @@ module Lorj
|
|
138
138
|
controller_error "'%s' do not have 'each' function.", objects.class
|
139
139
|
end
|
140
140
|
objects.each do |o|
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
end
|
141
|
+
trig_ret = _run_trigger(triggers, :before, [TrueClass, FalseClass],
|
142
|
+
true, o, query)
|
143
|
+
next unless trig_ret
|
145
144
|
if [Proc, Method].include?(triggers[:extract].class)
|
146
145
|
code = triggers[:extract]
|
147
146
|
selected = ctrl_do_query_match(o, query) { |d, k| code.call d, k }
|
148
147
|
else
|
149
148
|
selected = ctrl_do_query_match(o, query)
|
150
149
|
end
|
151
|
-
|
152
|
-
|
153
|
-
selected = code.call o, query, selected
|
154
|
-
end
|
150
|
+
selected = _run_trigger(triggers, :after, [TrueClass, FalseClass],
|
151
|
+
selected, o, query, selected)
|
155
152
|
results.push o if selected
|
156
153
|
end
|
157
154
|
Lorj.debug(4, '%d records selected', results.length)
|
158
155
|
results
|
159
156
|
end
|
160
157
|
|
158
|
+
# Internal functions used by #ctrl_query_each to give control
|
159
|
+
# on the query feature.
|
160
|
+
def _run_trigger(triggers, name, expect, default, *p)
|
161
|
+
return default if triggers[name].nil?
|
162
|
+
|
163
|
+
code = triggers[name]
|
164
|
+
begin
|
165
|
+
trig_ret = code.call(*p)
|
166
|
+
rescue
|
167
|
+
Lorj.error("trigger '%s' '%s' is in error: \n%s",
|
168
|
+
name, method_name, e)
|
169
|
+
end
|
170
|
+
method_name = "Unamed #{code.class}"
|
171
|
+
method_name = code.name if code.is_a?(Method)
|
172
|
+
if expect.length > 0 && !expect.include?(trig_ret.class)
|
173
|
+
PrcLib.warning("trigger '%s': Method '%s' should return one of '%s' ."\
|
174
|
+
" It returns '%s'. Ignored.",
|
175
|
+
name, method_name, expect, trig_ret.class)
|
176
|
+
return default
|
177
|
+
end
|
178
|
+
trig_ret
|
179
|
+
end
|
180
|
+
|
161
181
|
# controller helper function:
|
162
182
|
# Function to return match status
|
163
183
|
# from a list of attributes regarding a query attribute list
|
@@ -193,8 +213,12 @@ module Lorj
|
|
193
213
|
# - Any object exception during data extraction.
|
194
214
|
#
|
195
215
|
def ctrl_do_query_match(object, query)
|
216
|
+
return true unless query.is_a?(Hash)
|
217
|
+
|
218
|
+
Lorj.debug(3, "'%s' selected by '%s'?", object.class, query)
|
196
219
|
selected = true
|
197
220
|
query.each do |key, match_value|
|
221
|
+
Lorj.debug(4, "'%s' match '%s'?", key, match_value)
|
198
222
|
key_path = KeyPath.new(key)
|
199
223
|
if block_given?
|
200
224
|
found, v = _get_from(object, key_path.tree) { |d, k| yield d, k }
|
@@ -202,12 +226,17 @@ module Lorj
|
|
202
226
|
found, v = _get_from(object, key_path.tree)
|
203
227
|
end
|
204
228
|
|
205
|
-
|
229
|
+
controller_error("'%s': '%s' not found", object.class, key) unless found
|
206
230
|
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
231
|
+
Lorj.debug(4, "'%s.%s' = '%s'", object.class, key, v)
|
232
|
+
|
233
|
+
%w(regexp hash array default).each do |f|
|
234
|
+
t, s = method("lorj_filter_#{f}".to_sym).call v, match_value
|
235
|
+
next unless t
|
236
|
+
selected &= s
|
237
|
+
Lorj.debug(5, "Filter used '%s' returned '%s'", f, s)
|
238
|
+
break
|
239
|
+
end
|
211
240
|
break unless selected
|
212
241
|
end
|
213
242
|
Lorj.debug(4, 'object selected.') if selected
|
@@ -221,7 +250,7 @@ module Lorj
|
|
221
250
|
|
222
251
|
def _get_from(data, *key)
|
223
252
|
ret = nil
|
224
|
-
found =
|
253
|
+
found = false
|
225
254
|
key.flatten!
|
226
255
|
|
227
256
|
if data.is_a?(Hash)
|
@@ -230,26 +259,29 @@ module Lorj
|
|
230
259
|
return [found, ret]
|
231
260
|
end
|
232
261
|
|
262
|
+
if block_given?
|
263
|
+
begin
|
264
|
+
Lorj.debug(4, "yield extract '%s' from '%s'", key, data.class)
|
265
|
+
return [true, yield(data, *key)]
|
266
|
+
rescue => e
|
267
|
+
PrcLib.error("yield extract '%s' from '%s' error \n%s",
|
268
|
+
key, object.class, e)
|
269
|
+
end
|
270
|
+
return [found, ret]
|
271
|
+
end
|
272
|
+
|
233
273
|
[:[], key[0]].each do |f|
|
234
274
|
found, ret = _get_from_func(data, key[0], f)
|
235
275
|
return _get_from(ret, key[1..-1]) if found && key.length > 1
|
236
276
|
break if found
|
237
277
|
end
|
238
|
-
|
239
|
-
|
240
|
-
begin
|
241
|
-
Lorj.debug(4, "yield extract '%s' from '%s'", key, object.class)
|
242
|
-
return [true, yield(data, key)]
|
243
|
-
rescue
|
244
|
-
PrcLib.error("yield extract '%s' from '%s' error \n%s",
|
245
|
-
key, object.class, e)
|
246
|
-
end
|
247
|
-
[false, nil]
|
278
|
+
[found, ret]
|
248
279
|
end
|
249
280
|
|
250
281
|
def _get_from_func(data, key, func = nil)
|
251
|
-
func = key
|
282
|
+
func = key if func.nil?
|
252
283
|
v = nil
|
284
|
+
found = false
|
253
285
|
if data.class.method_defined?(func)
|
254
286
|
begin
|
255
287
|
found = true
|
@@ -269,50 +301,63 @@ module Lorj
|
|
269
301
|
end
|
270
302
|
[found, v]
|
271
303
|
end
|
304
|
+
|
272
305
|
# Function to check if a value match a regexp
|
273
306
|
#
|
307
|
+
# * *args*:
|
308
|
+
# - value : The controller value to test matching.
|
309
|
+
# - match_value: RegExp object to match against value.
|
310
|
+
#
|
274
311
|
# * *returns*:
|
275
|
-
# - true if
|
276
|
-
#
|
277
|
-
# - false otherwise
|
312
|
+
# - treated: true if match_value is RegExp
|
313
|
+
# - status : true if match. false otherwise
|
278
314
|
#
|
279
|
-
def lorj_filter_regexp(value, match_value)
|
280
|
-
return false unless match_value.is_a?(Regexp)
|
315
|
+
def lorj_filter_regexp(value, match_value) # :doc:
|
316
|
+
return [false, false] unless match_value.is_a?(Regexp)
|
281
317
|
|
282
|
-
return true if match_value.match(value)
|
283
|
-
false
|
318
|
+
return [true, true] if match_value.match(value)
|
319
|
+
[true, false]
|
284
320
|
end
|
285
321
|
|
286
|
-
# Function to check if
|
322
|
+
# Function to check if match_value is found in an Array.
|
323
|
+
#
|
324
|
+
# * *args*:
|
325
|
+
# - value : The controller value to test matching.
|
326
|
+
# - match_value: The matching subhash match.
|
327
|
+
# It can be an Array of match_value or just match_value
|
287
328
|
#
|
288
329
|
# * *returns*:
|
289
|
-
# - true if
|
290
|
-
#
|
291
|
-
# - false otherwise
|
330
|
+
# - treated: true if match_value is Array
|
331
|
+
# - status : true if match. false otherwise
|
292
332
|
#
|
293
|
-
def lorj_filter_array(value, match_value)
|
294
|
-
return false unless value.is_a?(Array) ||
|
333
|
+
def lorj_filter_array(value, match_value) # :doc:
|
334
|
+
return [false, false] unless value.is_a?(Array) ||
|
335
|
+
match_value.is_a?(Array)
|
295
336
|
|
296
337
|
if value.is_a?(Array) && match_value.is_a?(Array)
|
297
|
-
return (
|
338
|
+
return [true, (match_value - value).empty?]
|
298
339
|
end
|
299
340
|
|
300
|
-
value.include?(match_value)
|
341
|
+
[true, value.include?(match_value)]
|
301
342
|
end
|
302
343
|
|
303
344
|
# Function to check if a value match a filter value.
|
304
345
|
#
|
346
|
+
# * *args*:
|
347
|
+
# - value : The controller value to test matching
|
348
|
+
# - structure: The matching subhash match.
|
349
|
+
# It will be interpreted by #Lorj::KeyPath.
|
350
|
+
#
|
305
351
|
# * *returns*:
|
306
|
-
# - true if
|
307
|
-
#
|
308
|
-
# - false otherwise
|
352
|
+
# - treated: true if match_value is Hash
|
353
|
+
# - status : true if match. false otherwise
|
309
354
|
#
|
310
|
-
def lorj_filter_hash(value, structure)
|
311
|
-
return false unless value.is_a?(Hash)
|
355
|
+
def lorj_filter_hash(value, structure) # :doc:
|
356
|
+
return [false, false] unless value.is_a?(Hash)
|
312
357
|
|
313
358
|
key_path = KeyPath.new(structure)
|
314
359
|
tree = key_path.tree[0..-2]
|
315
|
-
return false unless value.rh_exist?(tree)
|
360
|
+
return [true, false] unless value.rh_exist?(tree)
|
316
361
|
match_value = key_path.key
|
317
362
|
res = value.rh_get(tree)
|
318
363
|
return lorj_filter_array(res.flatten, match_value) if res.is_a?(Array)
|
@@ -321,13 +366,16 @@ module Lorj
|
|
321
366
|
|
322
367
|
# Function to check if a value match a filter value.
|
323
368
|
#
|
369
|
+
# * *args*:
|
370
|
+
# - value : The controller value to test matching
|
371
|
+
# - structure: The matching subhash match.
|
372
|
+
#
|
324
373
|
# * *returns*:
|
325
|
-
# - true if
|
326
|
-
#
|
327
|
-
# - false otherwise
|
374
|
+
# - treated: true if match_value is Hash
|
375
|
+
# - status : true if match. false otherwise
|
328
376
|
#
|
329
|
-
def lorj_filter_default(value, match_value)
|
330
|
-
(value == match_value)
|
377
|
+
def lorj_filter_default(value, match_value) # :doc:
|
378
|
+
[true, (value == match_value)]
|
331
379
|
end
|
332
380
|
end
|
333
381
|
end
|
data/lib/lorj/version.rb
CHANGED
data/lib/lorj.rb
CHANGED
@@ -0,0 +1,295 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: UTF-8
|
3
|
+
|
4
|
+
# (c) Copyright 2014 Hewlett-Packard Development Company, L.P.
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
|
18
|
+
# To debug spec, depending on Ruby version, you may need to install
|
19
|
+
# 1.8 => ruby-debug
|
20
|
+
# 1.9 => debugger
|
21
|
+
# 2.0+ => byebug
|
22
|
+
# The right debugger should be installed by default by bundle
|
23
|
+
# So, just call:
|
24
|
+
#
|
25
|
+
# bundle
|
26
|
+
#
|
27
|
+
# Then set RSPEC_DEBUG=true, put a 'stop' where you want in the spec code
|
28
|
+
# and start rspec or even rake spec.
|
29
|
+
#
|
30
|
+
# RSPEC_DEBUG=true rake spec_local (or spec which includes docker spec)
|
31
|
+
# OR
|
32
|
+
# RSPEC_DEBUG=true rspec -f doc --color spec/<file>_spec.rb
|
33
|
+
#
|
34
|
+
|
35
|
+
app_path = File.dirname(__FILE__)
|
36
|
+
$LOAD_PATH << app_path unless $LOAD_PATH.include?(app_path)
|
37
|
+
require 'spec_helper'
|
38
|
+
|
39
|
+
describe 'Controller features' do
|
40
|
+
context 'internal filters' do
|
41
|
+
before(:all) do
|
42
|
+
# BaseControllerSpec
|
43
|
+
class BaseControllerSpec < Lorj::BaseController
|
44
|
+
def self.def_internal(name)
|
45
|
+
spec_name = 'spec_' + name
|
46
|
+
|
47
|
+
# To call the function identified internally with 'spec' prefix
|
48
|
+
define_method(spec_name) do |*p|
|
49
|
+
send(name, *p)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
# Internal function to test.
|
54
|
+
def_internal 'lorj_filter_regexp'
|
55
|
+
def_internal 'lorj_filter_array'
|
56
|
+
def_internal 'lorj_filter_hash'
|
57
|
+
def_internal 'lorj_filter_default'
|
58
|
+
end
|
59
|
+
PrcLib.spec_cleanup
|
60
|
+
PrcLib.data_path = File.join(app_path, '..', 'lorj-spec', 'data')
|
61
|
+
@o = BaseControllerSpec.new
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'lorj_filter_default(..., ...) is accepted'\
|
65
|
+
' (treated = false)' do
|
66
|
+
expect(@o.spec_lorj_filter_default('', '')[0]).to equal(true)
|
67
|
+
expect(@o.spec_lorj_filter_default('', //)[0]).to equal(true)
|
68
|
+
expect(@o.spec_lorj_filter_default([], '')[0]).to equal(true)
|
69
|
+
expect(@o.spec_lorj_filter_default({}, '')[0]).to equal(true)
|
70
|
+
end
|
71
|
+
|
72
|
+
it "lorj_filter_default('test2', 'test') return [true, false]" do
|
73
|
+
expect(@o.spec_lorj_filter_default('test2',
|
74
|
+
'test')[1]).to equal(false)
|
75
|
+
end
|
76
|
+
|
77
|
+
it "lorj_filter_default('test', 'test') return [true, true]" do
|
78
|
+
expect(@o.spec_lorj_filter_default('test', 'test')[1]).to equal(true)
|
79
|
+
end
|
80
|
+
|
81
|
+
it "lorj_filter_regexp('test2', ... except Regexp) is not recognized"\
|
82
|
+
' (treated = false)' do
|
83
|
+
expect(@o.spec_lorj_filter_regexp('', '')[0]).to equal(false)
|
84
|
+
expect(@o.spec_lorj_filter_regexp('', //)[0]).to equal(true)
|
85
|
+
expect(@o.spec_lorj_filter_regexp([], '')[0]).to equal(false)
|
86
|
+
expect(@o.spec_lorj_filter_regexp({}, '')[0]).to equal(false)
|
87
|
+
end
|
88
|
+
|
89
|
+
it "lorj_filter_regexp('test2', /toto/) not match" do
|
90
|
+
expect(@o.spec_lorj_filter_regexp('test2', /toto/)[1]).to equal(false)
|
91
|
+
end
|
92
|
+
|
93
|
+
it "lorj_filter_regexp('test2', /test/) match" do
|
94
|
+
expect(@o.spec_lorj_filter_regexp('test2', /test/)[1]).to equal(true)
|
95
|
+
end
|
96
|
+
|
97
|
+
it "lorj_filter_array(... except Array, '') is not recognized"\
|
98
|
+
' (treated = false)' do
|
99
|
+
expect(@o.spec_lorj_filter_array('', '')[0]).to equal(false)
|
100
|
+
expect(@o.spec_lorj_filter_array('', //)[0]).to equal(false)
|
101
|
+
expect(@o.spec_lorj_filter_array([], '')[0]).to equal(true)
|
102
|
+
expect(@o.spec_lorj_filter_array({}, '')[0]).to equal(false)
|
103
|
+
end
|
104
|
+
|
105
|
+
it "lorj_filter_array(['test2', :toto], 'test') not match" do
|
106
|
+
expect(@o.spec_lorj_filter_array(['test2', :toto],
|
107
|
+
'test')[1]).to equal(false)
|
108
|
+
end
|
109
|
+
|
110
|
+
it "lorj_filter_array(['test2', :toto], 'test2') match" do
|
111
|
+
expect(@o.spec_lorj_filter_array(['test2', :toto],
|
112
|
+
'test2')[1]).to equal(true)
|
113
|
+
end
|
114
|
+
|
115
|
+
it "lorj_filter_array(['test2', :toto], []) match" do
|
116
|
+
expect(@o.spec_lorj_filter_array(['test2', :toto],
|
117
|
+
[])[1]).to eq(true)
|
118
|
+
end
|
119
|
+
|
120
|
+
it "lorj_filter_array(['test2', :toto], [:test]) not match" do
|
121
|
+
expect(@o.spec_lorj_filter_array(['test2', :toto],
|
122
|
+
[:test])[1]).to equal(false)
|
123
|
+
end
|
124
|
+
|
125
|
+
it "lorj_filter_array(['test2', :toto], [:test]) match" do
|
126
|
+
expect(@o.spec_lorj_filter_array(['test2', :toto],
|
127
|
+
[:toto])[1]).to equal(true)
|
128
|
+
end
|
129
|
+
|
130
|
+
it "lorj_filter_array(['test2', :toto], [:toto, 'test2']) match" do
|
131
|
+
expect(@o.spec_lorj_filter_array(['test2', :toto],
|
132
|
+
[:toto, 'test2'])[1]).to equal(true)
|
133
|
+
end
|
134
|
+
|
135
|
+
it "lorj_filter_hash(... except Hash, '') is not recognized "\
|
136
|
+
'(treated = false)' do
|
137
|
+
expect(@o.spec_lorj_filter_hash('', '')[0]).to equal(false)
|
138
|
+
expect(@o.spec_lorj_filter_hash('', //)[0]).to equal(false)
|
139
|
+
expect(@o.spec_lorj_filter_hash([], '')[0]).to equal(false)
|
140
|
+
expect(@o.spec_lorj_filter_hash({}, '')[0]).to equal(true)
|
141
|
+
end
|
142
|
+
|
143
|
+
it "lorj_filter_hash({:test => 'value'}, :test2) not match" do
|
144
|
+
data = { :test => 'value' }
|
145
|
+
expect(@o.spec_lorj_filter_hash(data, :test2)[1]).to equal(false)
|
146
|
+
end
|
147
|
+
|
148
|
+
it "lorj_filter_hash({:test => 'value'}, :test) not match" do
|
149
|
+
data = { :test => 'value' }
|
150
|
+
expect(@o.spec_lorj_filter_hash(data, :test)[1]).to equal(false)
|
151
|
+
end
|
152
|
+
|
153
|
+
it "lorj_filter_hash({:test => 'value'}, ':test/:toto') not match" do
|
154
|
+
data = { :test => 'value' }
|
155
|
+
expect(@o.spec_lorj_filter_hash(data, ':test/:toto')[1]).to equal(false)
|
156
|
+
end
|
157
|
+
|
158
|
+
it "lorj_filter_hash({:test => 'value'}, [:test, 'value']) not match" do
|
159
|
+
data = { :test => 'value' }
|
160
|
+
expect(@o.spec_lorj_filter_hash(data, [:test, 'value'])[1]).to equal(true)
|
161
|
+
expect(@o.spec_lorj_filter_hash(data, ':test/value')[1]).to equal(true)
|
162
|
+
end
|
163
|
+
|
164
|
+
it "lorj_filter_hash({:test => {:toto => 'value'}}, "\
|
165
|
+
"':test/:toto/value') match" do
|
166
|
+
data = { :test => { :toto => 'value' } }
|
167
|
+
expect(@o.spec_lorj_filter_hash(data,
|
168
|
+
':test/:toto/value')[1]).to equal(true)
|
169
|
+
expect(@o.spec_lorj_filter_hash(data,
|
170
|
+
[:test, :toto,
|
171
|
+
'value'])[1]).to equal(true)
|
172
|
+
end
|
173
|
+
end
|
174
|
+
context 'Data extract' do
|
175
|
+
before(:all) do
|
176
|
+
# BaseControllerSpec
|
177
|
+
class BaseControllerSpec < Lorj::BaseController
|
178
|
+
def self.def_internal(name)
|
179
|
+
spec_name = 'spec_' + name
|
180
|
+
|
181
|
+
# To call the function identified internally with 'spec' prefix
|
182
|
+
define_method(spec_name) do |*p|
|
183
|
+
if p[-1].is_a?(Proc)
|
184
|
+
proc = p.pop
|
185
|
+
send(name, *p) { |*a| proc.call(*a) }
|
186
|
+
else
|
187
|
+
send(name, *p)
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
# Internal function to test.
|
193
|
+
def_internal 'ctrl_query_each'
|
194
|
+
def_internal '_run_trigger'
|
195
|
+
def_internal 'ctrl_do_query_match'
|
196
|
+
def_internal '_get_from'
|
197
|
+
def_internal '_get_from_func'
|
198
|
+
end
|
199
|
+
|
200
|
+
# TestData
|
201
|
+
class TestData
|
202
|
+
attr_accessor :attr1, :attr2
|
203
|
+
|
204
|
+
def initialize(attr1, attr2)
|
205
|
+
@attr1 = attr1
|
206
|
+
@attr2 = attr2
|
207
|
+
end
|
208
|
+
|
209
|
+
def all
|
210
|
+
{ :attr1 => @attr1, :attr2 => @attr2 }
|
211
|
+
end
|
212
|
+
end
|
213
|
+
@o = BaseControllerSpec.new
|
214
|
+
@data = TestData.new('value1', 'value2')
|
215
|
+
@list = [@data, TestData.new('value3', 'value4'),
|
216
|
+
{ :attr1 => 'value5', :attr2 => 'value6' },
|
217
|
+
{ :attr1 => 'value7', :attr2 => 'value6' }]
|
218
|
+
end
|
219
|
+
|
220
|
+
it '_get_from_func(data) works' do
|
221
|
+
expect(@o.spec__get_from_func(@data, 'attr1')).to eq([true, 'value1'])
|
222
|
+
expect(@o.spec__get_from_func(@data, :attr1)).to eq([true, 'value1'])
|
223
|
+
expect(@o.spec__get_from_func(@data, :attr3)).to eq([false, nil])
|
224
|
+
expect(@o.spec__get_from_func(@data, :attr2)).to eq([true, 'value2'])
|
225
|
+
expect(@o.spec__get_from_func(@data, :'@attr2',
|
226
|
+
:instance_variable_get)
|
227
|
+
).to eq([true, 'value2'])
|
228
|
+
end
|
229
|
+
|
230
|
+
it '_get_from(data, *key) works' do
|
231
|
+
expect(@o.spec__get_from(@data, :attr1)).to eq([true, 'value1'])
|
232
|
+
expect(@o.spec__get_from(@list[1], :attr1)).to eq([true, 'value3'])
|
233
|
+
# Uses [] internally
|
234
|
+
expect(@o.spec__get_from(@list[2], :attr1)).to eq([true, 'value5'])
|
235
|
+
expect(@o.spec__get_from(@data, :all, :attr1)).to eq([true, 'value1'])
|
236
|
+
expect(@o.spec__get_from(@data, :diff, lambda do |o, *k|
|
237
|
+
o.attr1 if k[0] == :diff
|
238
|
+
end)).to eq([true, 'value1'])
|
239
|
+
end
|
240
|
+
|
241
|
+
it 'ctrl_do_query_match works' do
|
242
|
+
expect(@o.spec_ctrl_do_query_match(@data,
|
243
|
+
{})).to equal(true)
|
244
|
+
expect do
|
245
|
+
@o.spec_ctrl_do_query_match(@data, :attr3 => '')
|
246
|
+
end.to raise_error(Lorj::PrcError)
|
247
|
+
|
248
|
+
expect(@o.spec_ctrl_do_query_match(@data,
|
249
|
+
:attr1 => 'value1')).to equal(true)
|
250
|
+
expect(@o.spec_ctrl_do_query_match(@data,
|
251
|
+
:attr1 => 'value1',
|
252
|
+
:attr2 => 'value3')).to equal(false)
|
253
|
+
expect(@o.spec_ctrl_do_query_match(@data,
|
254
|
+
:attr1 => 'value1',
|
255
|
+
:attr2 => /value$/)).to equal(false)
|
256
|
+
expect(@o.spec_ctrl_do_query_match(@data,
|
257
|
+
:attr1 => 'value1',
|
258
|
+
:attr2 => /value/)).to equal(true)
|
259
|
+
expect(@o.spec_ctrl_do_query_match(@data,
|
260
|
+
:attr1 => 'value1',
|
261
|
+
:attr2 => 'value2')).to equal(true)
|
262
|
+
end
|
263
|
+
|
264
|
+
it '_run_trigger works' do
|
265
|
+
def trigger1(*p)
|
266
|
+
p
|
267
|
+
end
|
268
|
+
|
269
|
+
def trigger2(*_p)
|
270
|
+
true
|
271
|
+
end
|
272
|
+
triggers = { :trig1 => method(:trigger1), :trig2 => method(:trigger2) }
|
273
|
+
|
274
|
+
expect(@o.spec__run_trigger({}, :blabla, [], nil)).to equal(nil)
|
275
|
+
expect(@o.spec__run_trigger({}, :blabla, [], true)).to equal(true)
|
276
|
+
expect(@o.spec__run_trigger(triggers, :blabla, [], nil)).to equal(nil)
|
277
|
+
|
278
|
+
expect(@o.spec__run_trigger(triggers, :trig1, [], nil,
|
279
|
+
'value1')).to eq(%w(value1))
|
280
|
+
expect(@o.spec__run_trigger(triggers, :trig1, [FalseClass], nil,
|
281
|
+
'value1')).to eq(nil)
|
282
|
+
expect(@o.spec__run_trigger(triggers, :trig2, [FalseClass, TrueClass],
|
283
|
+
nil, 'value1')).to eq(true)
|
284
|
+
end
|
285
|
+
|
286
|
+
it 'ctrl_query_each works' do
|
287
|
+
expect(@o.spec_ctrl_query_each(@list,
|
288
|
+
:attr1 => /value/,
|
289
|
+
:attr2 => 'value6').length).to eq(2)
|
290
|
+
expect(@o.spec_ctrl_query_each(@list,
|
291
|
+
:attr1 => 'value',
|
292
|
+
:attr2 => 'value6').length).to eq(0)
|
293
|
+
end
|
294
|
+
end
|
295
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -78,6 +78,17 @@ module Lorj
|
|
78
78
|
end
|
79
79
|
end
|
80
80
|
|
81
|
+
def show_log(lorj_debug = nil)
|
82
|
+
return unless ENV['RSPEC_DEBUG'] == 'true'
|
83
|
+
|
84
|
+
env_lorj_debug = ENV['LORJ_DEBUG']
|
85
|
+
if lorj_debug.nil? && env_lorj_debug && /[0-9]/ =~ env_lorj_debug
|
86
|
+
lorj_debug = ENV['LORJ_DEBUG'].to_i
|
87
|
+
end
|
88
|
+
PrcLib.core_level = lorj_debug unless lorj_debug.nil?
|
89
|
+
PrcLib.level = Logger::DEBUG
|
90
|
+
end
|
91
|
+
|
81
92
|
def to_s
|
82
93
|
a = {}
|
83
94
|
instance_variables.each do |v|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lorj
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.18
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- forj team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-06-
|
11
|
+
date: 2015-06-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -286,6 +286,7 @@ files:
|
|
286
286
|
- spec/22_lorj_core_spec.rb
|
287
287
|
- spec/30_lorj_basedefinition_spec.rb
|
288
288
|
- spec/31_lorj_importexport_spec.rb
|
289
|
+
- spec/40_lorj_ctrl_spec.rb
|
289
290
|
- spec/spec_helper.rb
|
290
291
|
homepage: https://github.com/forj-oss/lorj
|
291
292
|
licenses:
|
@@ -326,4 +327,5 @@ test_files:
|
|
326
327
|
- spec/22_lorj_core_spec.rb
|
327
328
|
- spec/30_lorj_basedefinition_spec.rb
|
328
329
|
- spec/31_lorj_importexport_spec.rb
|
330
|
+
- spec/40_lorj_ctrl_spec.rb
|
329
331
|
- spec/spec_helper.rb
|