delorean_lang 0.3.16 → 0.3.17

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b9e807e4b0e258dcb0a059957acd6f03b9056b80
4
- data.tar.gz: 7b847737484ec32546b6e54d75a553e8ace2129b
3
+ metadata.gz: 986e58894d0d75b1d83fddd707448410456abd41
4
+ data.tar.gz: d35e57733be58f268bd57866bbb1fa46968cbc31
5
5
  SHA512:
6
- metadata.gz: bbebebdd4c9bfb82345d1c0c9e618652e5b02d7c0e62bd1783460aebe4ee298eb3a4cd8b1e841cd34b1e540703cf94d577cd7607534e3c263177b9d2496708bd
7
- data.tar.gz: 3477a50fb9f760f313b0d49ae2f869f924d25bf1837362704d4f14bc4fff5d1b8566f0057493e87096f3f73fade3aa9d8562be472c4ceaf5df26a7a00400a327
6
+ metadata.gz: d7e482343719b38cf5722bd3004cc9435f88240dcbabcf629348042da929ef80ae6ec85e1842d9d79bf4ec6ba1a19aba580a5c6543606608323b82d4e4b37839
7
+ data.tar.gz: 5391356394c6831cbc95f44de56f7739b2be879c1cb3fb8b376d48cf40f2e8df4a4a4ebe136e49718e808482dd4a9c14f5742fbc6180c67c7a678542527fd933
data/lib/delorean/base.rb CHANGED
@@ -15,8 +15,11 @@ module Delorean
15
15
  max: [Array],
16
16
  member: "member?",
17
17
  member?: [Enumerable, [Object]],
18
+ empty: "empty?",
19
+ empty?: [Enumerable],
18
20
  reverse: [Array],
19
21
  slice: [Array, Fixnum, Fixnum],
22
+ each_slice: [Array, Fixnum],
20
23
  sort: [Array],
21
24
  split: [String, String],
22
25
  uniq: [Array],
@@ -69,6 +72,8 @@ module Delorean
69
72
  to_f: [[Numeric, String]],
70
73
  to_d: [[Numeric, String]],
71
74
  to_s: [Object],
75
+ to_a: [Object],
76
+ to_json: [Object],
72
77
  abs: [Numeric],
73
78
  round: [Numeric, [nil, Integer]],
74
79
  ceil: [Numeric],
@@ -84,8 +89,25 @@ module Delorean
84
89
  engine.evaluate(node, attr, params.clone)
85
90
  end
86
91
 
92
+ def /(args)
93
+ raise "non-array/string arg to /" unless
94
+ args.is_a?(Array) || args.is_a?(String)
95
+
96
+ begin
97
+ case args
98
+ when Array
99
+ engine.eval_to_hash(node, args, params.clone)
100
+ when String
101
+ engine.evaluate(node, args, params.clone)
102
+ end
103
+ rescue => exc
104
+ Delorean::Engine.grok_runtime_exception(exc)
105
+ end
106
+ end
107
+
108
+ # FIXME: % should also support string as args
87
109
  def %(args)
88
- raise "bad arg to %" unless args.is_a?(Array)
110
+ raise "non-array arg to %" unless args.is_a?(Array)
89
111
 
90
112
  # FIXME: params.clone!!!!
91
113
  engine.eval_to_hash(node, args, params.clone)
@@ -133,9 +155,9 @@ module Delorean
133
155
 
134
156
  begin
135
157
  return _instance_call(obj, attr, [], _e)
136
- rescue
158
+ rescue => exc
137
159
  raise InvalidGetAttribute,
138
- "bad attribute lookup '#{attr}' on <#{obj.class}> #{obj}"
160
+ "attr lookup failed: '#{attr}' on <#{obj.class}> #{obj} - #{exc}"
139
161
  end
140
162
  end
141
163
 
@@ -1,3 +1,3 @@
1
1
  module Delorean
2
- VERSION = "0.3.16"
2
+ VERSION = "0.3.17"
3
3
  end
data/spec/eval_spec.rb CHANGED
@@ -277,7 +277,7 @@ describe "Delorean" do
277
277
  it "should be able to get attr on ActiveRecord objects using a.b syntax" do
278
278
  engine.parse defn("A:",
279
279
  ' b = Dummy.i_just_met_you("this is crazy", 0.404)',
280
- " c = b.number",
280
+ " c = b.number.to_f",
281
281
  " d = b.name",
282
282
  " e = b.foo",
283
283
  )
@@ -887,6 +887,27 @@ eof
887
887
  [1, {"x"=>123, "y"=>456}, {"a"=>1, "b"=>{"x"=>123, "y"=>456}}, -333]
888
888
  end
889
889
 
890
+ it "can handle exceptions with / syntax" do
891
+ engine.parse defn("A:",
892
+ " a = 1",
893
+ " b = {'x' : 123, 'y': 456}",
894
+ " e = ERR('hello')",
895
+ " c = A() / ['a', 'b']",
896
+ " d = A() / ['a', 'e']",
897
+ " f = A() / 'a'",
898
+ )
899
+ r = engine.evaluate_attrs("A", ["a", "b", "c"])
900
+ r.should ==
901
+ [1, {"x"=>123, "y"=>456}, {"a"=>1, "b"=>{"x"=>123, "y"=>456}}]
902
+
903
+ r = engine.evaluate_attrs("A", ["a", "d"])
904
+ r.should ==
905
+ [1, {"error"=>"hello", "backtrace"=>[["XXX", 4, "e"], ["XXX", 6, "d"]]}]
906
+
907
+ r = engine.evaluate_attrs("A", ["f"])
908
+ r.should == [1]
909
+ end
910
+
890
911
  it "should properly eval overridden attrs" do
891
912
  engine.parse defn("A:",
892
913
  " a = 5",
@@ -940,4 +961,12 @@ eof
940
961
  engine.evaluate_attrs("A", ["a", "z", "y"], {0 => 123, 1 => 456}).should ==
941
962
  [123-456, 40, ["x", "y", nil]]
942
963
  end
964
+
965
+ it "can call 0-arity functions in list comprehension" do
966
+ engine.parse defn("A:",
967
+ ' b = [x.name for x in Dummy.all_of_me]',
968
+ )
969
+ r = engine.evaluate("A", "b")
970
+ expect(r).to eq ["hello"]
971
+ end
943
972
  end
data/spec/func_spec.rb CHANGED
@@ -183,4 +183,18 @@ describe "Delorean" do
183
183
  )
184
184
  engine.evaluate("A", "b").should == x.slice(0,4)
185
185
  end
186
+
187
+ it "should handle RUBY empty? function" do
188
+ engine.parse defn("A:",
189
+ " a0 = []",
190
+ " b0 = {}",
191
+ " c0 = {-}",
192
+ " a1 = [1,2,3]",
193
+ " b1 = {'a': 1, 'b':2}",
194
+ " c1 = {1,2,3}",
195
+ " res = [a0.empty, b0.empty(), c0.empty, a1.empty, b1.empty(), c1.empty]",
196
+ )
197
+ engine.evaluate("A", "res").should == [true, true, true, false, false, false]
198
+ end
199
+
186
200
  end
data/spec/parse_spec.rb CHANGED
@@ -314,6 +314,16 @@ describe "Delorean" do
314
314
 
315
315
  engine.reset
316
316
 
317
+ lambda {
318
+ engine.parse defn("D:",
319
+ " true_1 = false",
320
+ " false_1 = true_1",
321
+ " nil_1 = false_1",
322
+ )
323
+ }.should_not raise_error
324
+
325
+ engine.reset
326
+
317
327
  lambda {
318
328
  engine.parse defn("E:",
319
329
  " a = 1",
data/spec/spec_helper.rb CHANGED
@@ -56,6 +56,10 @@ class Dummy < ActiveRecord::Base
56
56
 
57
57
  MISS_YOU_SO_BAD_SIG = [0, 0]
58
58
 
59
+ delorean_fn :all_of_me, sig: 0 do
60
+ self.all
61
+ end
62
+
59
63
  def self.i_threw_a_hash_in_the_well
60
64
  {a: 123, "a" => 456, b: 789}
61
65
  end
@@ -63,7 +67,7 @@ class Dummy < ActiveRecord::Base
63
67
  I_THREW_A_HASH_IN_THE_WELL_SIG = [0, 0]
64
68
 
65
69
  def name2
66
- "#{name}-#{number}"
70
+ "#{name}-#{number.round(4)}"
67
71
  end
68
72
 
69
73
  delorean_fn :one_or_two, sig: [1, 2] do
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.3.16
4
+ version: 0.3.17
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-11-11 00:00:00.000000000 Z
11
+ date: 2015-02-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: treetop