delorean_lang 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/delorean/base.rb +9 -2
- data/lib/delorean/version.rb +1 -1
- data/spec/eval_spec.rb +8 -0
- data/spec/spec_helper.rb +9 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MThkOGViN2U0NDc5MjEyMmVhM2Y0NGIyN2QwNTRhZjFhY2M1NTMyMA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ODhlNDc3ODRkZGI4OWMwNzRiNzM1ODA4ZWI3MzY2OWYzNTdhZGRiOA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NjY0MzZiZTZmNDUzMmM2YmYyYjAxZjNiY2QxODY1OTQzNmZiNjJkOWM3NTMz
|
10
|
+
ZDhjYTFjZWRjYzE4ZmFmYWYyMmQ5NzY3OTFiODg5MDdlZGM5YWMwZjRiZWFh
|
11
|
+
MGNkYTczZGJmOTY1Zjg2MTM0ZjlhNDcyZTQzNjUzYzdmMDBiODM=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YjFiN2E5YjdiYmE1NjA3OTY5OTYyZDE5N2MzZGUyMjk1YjdmMTYzNmExNjRm
|
14
|
+
ZDhmMWE2OTFlMGYyZGRmNzMxZTIwMTliNjAyNDljNWRiN2MxYTdkMjg0OTcz
|
15
|
+
NGUwYjhmYTIzNDE3MDgzODE0YTdhMGNmNzM3NWEzN2VhYmRiNzk=
|
data/lib/delorean/base.rb
CHANGED
@@ -91,6 +91,8 @@ module Delorean
|
|
91
91
|
|
92
92
|
class BaseClass
|
93
93
|
def self._get_attr(obj, attr, _e)
|
94
|
+
# FIXME: even Javascript which is superpermissive raises an
|
95
|
+
# exception on null getattr.
|
94
96
|
return nil if obj.nil?
|
95
97
|
|
96
98
|
# NOTE: should keep this function consistent with _index
|
@@ -104,7 +106,13 @@ module Delorean
|
|
104
106
|
return obj.send(attr.to_sym) if
|
105
107
|
klass.reflect_on_all_associations.map(&:name).member? attr.to_sym
|
106
108
|
|
107
|
-
|
109
|
+
# FIXME: should call _instance_call for other types as well.
|
110
|
+
# Too lazy to implement this now.
|
111
|
+
begin
|
112
|
+
return _instance_call(obj, attr, [])
|
113
|
+
rescue
|
114
|
+
raise InvalidGetAttribute, "ActiveRecord lookup '#{attr}' on #{obj}"
|
115
|
+
end
|
108
116
|
elsif obj.instance_of?(NodeCall)
|
109
117
|
return obj.evaluate(attr)
|
110
118
|
elsif obj.instance_of?(Hash)
|
@@ -113,7 +121,6 @@ module Delorean
|
|
113
121
|
elsif obj.instance_of?(Class) && (obj < BaseClass)
|
114
122
|
return obj.send((attr + POST).to_sym, _e)
|
115
123
|
end
|
116
|
-
|
117
124
|
raise InvalidGetAttribute,
|
118
125
|
"bad attribute lookup '#{attr}' on <#{obj.class}> #{obj}"
|
119
126
|
end
|
data/lib/delorean/version.rb
CHANGED
data/spec/eval_spec.rb
CHANGED
@@ -252,6 +252,14 @@ describe "Delorean" do
|
|
252
252
|
r.should == "CRJ"
|
253
253
|
end
|
254
254
|
|
255
|
+
it "should be able to access ActiveRecord whitelisted fns using .attr syntax" do
|
256
|
+
engine.parse defn("A:",
|
257
|
+
' b = Dummy.i_just_met_you("CRJ", 1.234).name2',
|
258
|
+
)
|
259
|
+
r = engine.evaluate("A", "b")
|
260
|
+
r.should == "CRJ-1.234"
|
261
|
+
end
|
262
|
+
|
255
263
|
it "should be able to get attr on Hash objects using a.b syntax" do
|
256
264
|
engine.parse defn("A:",
|
257
265
|
' b = Dummy.i_threw_a_hash_in_the_well()',
|
data/spec/spec_helper.rb
CHANGED
@@ -60,6 +60,10 @@ class Dummy < ActiveRecord::Base
|
|
60
60
|
end
|
61
61
|
|
62
62
|
I_THREW_A_HASH_IN_THE_WELL_SIG = [0, 0]
|
63
|
+
|
64
|
+
def name2
|
65
|
+
"#{name}-#{number}"
|
66
|
+
end
|
63
67
|
end
|
64
68
|
|
65
69
|
module M
|
@@ -73,6 +77,11 @@ module M
|
|
73
77
|
end
|
74
78
|
end
|
75
79
|
|
80
|
+
Delorean::RUBY_WHITELIST.
|
81
|
+
merge!({
|
82
|
+
name2: [Dummy],
|
83
|
+
})
|
84
|
+
|
76
85
|
######################################################################
|
77
86
|
|
78
87
|
class TestContainer < Delorean::AbstractContainer
|
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.2.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Arman Bostani
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-04-
|
11
|
+
date: 2014-04-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: treetop
|