delorean_lang 0.3.38 → 0.4.00
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/delorean/base.rb +3 -5
- data/lib/delorean/engine.rb +2 -2
- data/lib/delorean/version.rb +1 -1
- data/spec/eval_spec.rb +1 -36
- data/spec/parse_spec.rb +7 -0
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: bb9bc757d323ed7d4388c688b739e9db16b4bf5c
|
|
4
|
+
data.tar.gz: 00d96513a6ad9a715b6b10e049bab9d3c7bb810e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: '068413a5efef120c6351a8cfeb8cdda51c671cde3bb7b0fb5cde0303b7dbb989d33d214505d31b47557a32a60e6ceff0e33c526c9d68d51b51d150109c0a96ff'
|
|
7
|
+
data.tar.gz: 46cdcda1e1c2af6019f33b498fd3acd7f9257b79969f2e74706283cfa93b560d54c520194ad8a888c10e844379e9d6c63f02037c3b0e3abd4dbe8171166d8577
|
data/lib/delorean/base.rb
CHANGED
|
@@ -14,7 +14,8 @@ module Delorean
|
|
|
14
14
|
# hash. The whole whitelist mechanism should be eventually
|
|
15
15
|
# rethought.
|
|
16
16
|
RUBY_WHITELIST = {
|
|
17
|
-
attributes
|
|
17
|
+
# FIXME: hack -- Relation.attributes currently implemented in marty
|
|
18
|
+
attributes: [[ActiveRecord::Base, ActiveRecord::Relation]],
|
|
18
19
|
between?: [NUM_OR_STR, NUM_OR_STR, NUM_OR_STR],
|
|
19
20
|
between: "between?",
|
|
20
21
|
compact: [[Array, Hash]],
|
|
@@ -151,9 +152,6 @@ module Delorean
|
|
|
151
152
|
# FIXME: even Javascript which is superpermissive raises an
|
|
152
153
|
# exception on null getattr.
|
|
153
154
|
return nil
|
|
154
|
-
when ActiveRecord::Base
|
|
155
|
-
return obj.read_attribute(attr) if obj.has_attribute?(attr)
|
|
156
|
-
return obj.send(attr.to_sym) if obj.class.reflections[attr]
|
|
157
155
|
when NodeCall
|
|
158
156
|
return obj.evaluate(attr)
|
|
159
157
|
when OpenStruct
|
|
@@ -179,7 +177,7 @@ module Delorean
|
|
|
179
177
|
# FIXME: even Javascript which is superpermissive raises an
|
|
180
178
|
# exception on null getattr.
|
|
181
179
|
return nil
|
|
182
|
-
when Hash,
|
|
180
|
+
when Hash, NodeCall, Class, OpenStruct
|
|
183
181
|
raise InvalidIndex unless args.length == 1
|
|
184
182
|
_get_attr(obj, args[0], _e)
|
|
185
183
|
when Array, String, MatchData
|
data/lib/delorean/engine.rb
CHANGED
|
@@ -348,7 +348,7 @@ module Delorean
|
|
|
348
348
|
|
|
349
349
|
def evaluate(node, attrs, params={})
|
|
350
350
|
raise "bad params" unless params.is_a?(Hash)
|
|
351
|
-
|
|
351
|
+
|
|
352
352
|
if node.is_a?(Class)
|
|
353
353
|
klass = node
|
|
354
354
|
else
|
|
@@ -365,7 +365,7 @@ module Delorean
|
|
|
365
365
|
|
|
366
366
|
type_arr = attrs.is_a?(Array)
|
|
367
367
|
attrs = [attrs] unless type_arr
|
|
368
|
-
|
|
368
|
+
|
|
369
369
|
res = attrs.map { |attr|
|
|
370
370
|
raise "bad attribute '#{attr}'" unless attr =~ /^[a-z][A-Za-z0-9_]*$/
|
|
371
371
|
klass.send("#{attr}#{POST}".to_sym, params)
|
data/lib/delorean/version.rb
CHANGED
data/spec/eval_spec.rb
CHANGED
|
@@ -276,32 +276,6 @@ describe "Delorean" do
|
|
|
276
276
|
r.should == [10, 0, 15]
|
|
277
277
|
end
|
|
278
278
|
|
|
279
|
-
it "should be able to get attr on ActiveRecord objects using a.b syntax" do
|
|
280
|
-
engine.parse defn("A:",
|
|
281
|
-
' b = Dummy.i_just_met_you("this is crazy", 0.404)',
|
|
282
|
-
" c = b.number.to_f",
|
|
283
|
-
" d = b.name",
|
|
284
|
-
" e = b.foo",
|
|
285
|
-
)
|
|
286
|
-
r = engine.evaluate("A", "c")
|
|
287
|
-
r.should == 0.404
|
|
288
|
-
|
|
289
|
-
r = engine.evaluate("A", "d")
|
|
290
|
-
r.should == "this is crazy"
|
|
291
|
-
|
|
292
|
-
lambda {
|
|
293
|
-
r = engine.evaluate("A", "e")
|
|
294
|
-
}.should raise_error(Delorean::InvalidGetAttribute)
|
|
295
|
-
end
|
|
296
|
-
|
|
297
|
-
it "should be able to get attr on AR objs using Class.method().attr syntax" do
|
|
298
|
-
engine.parse defn("A:",
|
|
299
|
-
' b = Dummy.i_just_met_you("CRJ", 1.234).name',
|
|
300
|
-
)
|
|
301
|
-
r = engine.evaluate("A", "b")
|
|
302
|
-
r.should == "CRJ"
|
|
303
|
-
end
|
|
304
|
-
|
|
305
279
|
it "should be able to access ActiveRecord whitelisted fns using .x syntax" do
|
|
306
280
|
engine.parse defn("A:",
|
|
307
281
|
' b = Dummy.i_just_met_you("CRJ", 1.234).name2',
|
|
@@ -361,7 +335,7 @@ describe "Delorean" do
|
|
|
361
335
|
|
|
362
336
|
it "get attr on nil should return nil" do
|
|
363
337
|
engine.parse defn("A:",
|
|
364
|
-
' b =
|
|
338
|
+
' b = nil',
|
|
365
339
|
' c = b.gaga',
|
|
366
340
|
' d = b.gaga || 55',
|
|
367
341
|
)
|
|
@@ -369,15 +343,6 @@ describe "Delorean" do
|
|
|
369
343
|
r.should == [nil, nil, 55]
|
|
370
344
|
end
|
|
371
345
|
|
|
372
|
-
it "should be able to get assoc attr on ActiveRecord objects" do
|
|
373
|
-
engine.parse defn("A:",
|
|
374
|
-
' b = Dummy.miss_you_so_bad()',
|
|
375
|
-
' c = b.dummy',
|
|
376
|
-
)
|
|
377
|
-
r = engine.evaluate("A", "c")
|
|
378
|
-
r.name.should == "hello"
|
|
379
|
-
end
|
|
380
|
-
|
|
381
346
|
it "should be able to get attr on node" do
|
|
382
347
|
engine.parse defn("A:",
|
|
383
348
|
" a = 123",
|
data/spec/parse_spec.rb
CHANGED
|
@@ -663,6 +663,13 @@ describe "Delorean" do
|
|
|
663
663
|
|
|
664
664
|
end
|
|
665
665
|
|
|
666
|
+
xit "should parse cross list comprehension" do
|
|
667
|
+
engine.parse defn("A:",
|
|
668
|
+
" b = [a+c for c in [4,5] for a in [1,2,3]]",
|
|
669
|
+
)
|
|
670
|
+
|
|
671
|
+
end
|
|
672
|
+
|
|
666
673
|
it "should accept list comprehension variable override" do
|
|
667
674
|
engine.parse defn("A:",
|
|
668
675
|
" b = [b+1 for b in [1,2,3]]",
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: delorean_lang
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.4.00
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Arman Bostani
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2018-
|
|
11
|
+
date: 2018-08-14 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: treetop
|