delorean_lang 2.0.0 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/lib/delorean/base.rb +3 -2
- data/lib/delorean/ruby.rb +13 -0
- data/lib/delorean/version.rb +1 -1
- data/spec/ruby/error_handling_spec.rb +43 -0
- data/spec/spec_helper.rb +11 -11
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4c38ab0abe7bac9f36adbc22664d1efc5a01216d032fa8b8a079ecc640a560b7
|
4
|
+
data.tar.gz: c990d13bfae100045288a5139614ff72e3af2a0a9e89ff87790e8b717b19f39c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 64ff3320a7722c5017eb2f0a366d21a1fa5b20173e4675cd1316dae14790676442787e164ea4e01c4ce2ae7f91a06eb9716e3ddecf8c0801e5e33801d105919a
|
7
|
+
data.tar.gz: a020a58b04d8d067b44c977fce93927c2fed8e5bb6454c18cb01c72edbeb58321a00395d1bb258fd556023b309d0b8aedcfaeded789c43cda1cd72ea1b541138
|
data/README.md
CHANGED
@@ -199,7 +199,7 @@ Use `extend Delorean::Functions` or `include Delorean::Model` in your module or
|
|
199
199
|
class Dummy < ActiveRecord::Base
|
200
200
|
include Delorean::Model
|
201
201
|
|
202
|
-
delorean_fn(:heres_my_number
|
202
|
+
delorean_fn(:heres_my_number) do |*a|
|
203
203
|
a.inject(0, :+)
|
204
204
|
end
|
205
205
|
|
@@ -211,7 +211,7 @@ end
|
|
211
211
|
module DummyModule
|
212
212
|
extend Delorean::Functions
|
213
213
|
|
214
|
-
delorean_fn(:heres_my_number
|
214
|
+
delorean_fn(:heres_my_number) do |*a|
|
215
215
|
a.inject(0, :+)
|
216
216
|
end
|
217
217
|
end
|
data/lib/delorean/base.rb
CHANGED
@@ -14,6 +14,8 @@ module Delorean
|
|
14
14
|
size_per_class: 1000
|
15
15
|
)
|
16
16
|
|
17
|
+
::Delorean::Ruby.error_handler = ::Delorean::Ruby::DEFAULT_ERROR_HANDLER
|
18
|
+
|
17
19
|
module BaseModule
|
18
20
|
# _e is used by Marty promise_jobs to pass promise-related
|
19
21
|
# information
|
@@ -154,8 +156,7 @@ module Delorean
|
|
154
156
|
######################################################################
|
155
157
|
|
156
158
|
def self._err(*args)
|
157
|
-
|
158
|
-
raise str
|
159
|
+
::Delorean::Ruby.error_handler.call(*args)
|
159
160
|
end
|
160
161
|
|
161
162
|
def self._node_call(node, _e, params)
|
data/lib/delorean/ruby.rb
CHANGED
@@ -4,6 +4,11 @@ require 'delorean/ruby/whitelists'
|
|
4
4
|
|
5
5
|
module Delorean
|
6
6
|
module Ruby
|
7
|
+
DEFAULT_ERROR_HANDLER = lambda do |*args|
|
8
|
+
str = args.map(&:to_s).join(', ')
|
9
|
+
raise str
|
10
|
+
end
|
11
|
+
|
7
12
|
def self.whitelist=(new_whitelist)
|
8
13
|
@whitelist = new_whitelist
|
9
14
|
end
|
@@ -11,5 +16,13 @@ module Delorean
|
|
11
16
|
def self.whitelist
|
12
17
|
@whitelist
|
13
18
|
end
|
19
|
+
|
20
|
+
def self.error_handler=(new_handler)
|
21
|
+
@error_handler = new_handler
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.error_handler
|
25
|
+
@error_handler
|
26
|
+
end
|
14
27
|
end
|
15
28
|
end
|
data/lib/delorean/version.rb
CHANGED
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../spec_helper'
|
4
|
+
|
5
|
+
describe 'Delorean Ruby error handling' do
|
6
|
+
after do
|
7
|
+
::Delorean::Ruby.error_handler = ::Delorean::Ruby::DEFAULT_ERROR_HANDLER
|
8
|
+
end
|
9
|
+
|
10
|
+
let(:sset) do
|
11
|
+
TestContainer.new(
|
12
|
+
'AAA' =>
|
13
|
+
defn('X:',
|
14
|
+
' a =? 123',
|
15
|
+
' b = a*2',
|
16
|
+
)
|
17
|
+
)
|
18
|
+
end
|
19
|
+
|
20
|
+
let(:engine) do
|
21
|
+
Delorean::Engine.new('XXX', sset).tap do |eng|
|
22
|
+
eng.parse defn('A:',
|
23
|
+
' b = ERR("test", 1, 2, 3)'
|
24
|
+
)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'raises error' do
|
29
|
+
expect { engine.evaluate('A', 'b') }.to raise_error(
|
30
|
+
RuntimeError, 'test, 1, 2, 3'
|
31
|
+
)
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'allows to override handler' do
|
35
|
+
::Delorean::Ruby.error_handler = lambda do |*_args|
|
36
|
+
raise StandardError, 'Overriden Error'
|
37
|
+
end
|
38
|
+
|
39
|
+
expect { engine.evaluate('A', 'b') }.to raise_error(
|
40
|
+
StandardError, 'Overriden Error'
|
41
|
+
)
|
42
|
+
end
|
43
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -51,7 +51,7 @@ class Dummy < ActiveRecord::Base
|
|
51
51
|
Dummy.new(name: 'jello', number: 456, dummy: d)
|
52
52
|
end
|
53
53
|
|
54
|
-
delorean_fn :all_of_me
|
54
|
+
delorean_fn :all_of_me do
|
55
55
|
[{ 'name' => 'hello', 'foo' => 'bar' }]
|
56
56
|
end
|
57
57
|
|
@@ -63,20 +63,20 @@ class Dummy < ActiveRecord::Base
|
|
63
63
|
"#{name}-#{number.round(4)}"
|
64
64
|
end
|
65
65
|
|
66
|
-
delorean_fn :one_or_two
|
66
|
+
delorean_fn :one_or_two do |a, b = nil|
|
67
67
|
[a, b]
|
68
68
|
end
|
69
69
|
|
70
70
|
@@foo = 0
|
71
|
-
delorean_fn :side_effect
|
71
|
+
delorean_fn :side_effect do
|
72
72
|
@@foo += 1
|
73
73
|
end
|
74
74
|
|
75
|
-
delorean_fn :returns_openstruct
|
75
|
+
delorean_fn :returns_openstruct do
|
76
76
|
OpenStruct.new('abc' => 'def')
|
77
77
|
end
|
78
78
|
|
79
|
-
delorean_fn :returns_cached_openstruct, cache: true
|
79
|
+
delorean_fn :returns_cached_openstruct, cache: true do |first, last|
|
80
80
|
OpenStruct.new(first.to_s => last)
|
81
81
|
end
|
82
82
|
end
|
@@ -91,7 +91,7 @@ module M
|
|
91
91
|
class LittleDummy
|
92
92
|
include Delorean::Model
|
93
93
|
|
94
|
-
delorean_fn(:heres_my_number
|
94
|
+
delorean_fn(:heres_my_number) do |*a|
|
95
95
|
a.inject(0, :+)
|
96
96
|
end
|
97
97
|
|
@@ -113,7 +113,7 @@ end
|
|
113
113
|
module DummyModule
|
114
114
|
extend Delorean::Functions
|
115
115
|
|
116
|
-
delorean_fn(:heres_my_number
|
116
|
+
delorean_fn(:heres_my_number) do |*a|
|
117
117
|
a.inject(0, :+)
|
118
118
|
end
|
119
119
|
end
|
@@ -125,7 +125,7 @@ end
|
|
125
125
|
class DeloreanFunctionsClass
|
126
126
|
extend Delorean::Functions
|
127
127
|
|
128
|
-
delorean_fn :test_fn
|
128
|
+
delorean_fn :test_fn do
|
129
129
|
:test_fn_result
|
130
130
|
end
|
131
131
|
|
@@ -134,7 +134,7 @@ class DeloreanFunctionsClass
|
|
134
134
|
end
|
135
135
|
|
136
136
|
class DeloreanFunctionsChildClass < DeloreanFunctionsClass
|
137
|
-
delorean_fn :test_fn2
|
137
|
+
delorean_fn :test_fn2 do
|
138
138
|
:test_fn2_result
|
139
139
|
end
|
140
140
|
|
@@ -144,11 +144,11 @@ end
|
|
144
144
|
class DifferentClassSameMethod
|
145
145
|
extend Delorean::Functions
|
146
146
|
|
147
|
-
delorean_fn :test_fn2
|
147
|
+
delorean_fn :test_fn2 do
|
148
148
|
:test_fn2_result_different
|
149
149
|
end
|
150
150
|
|
151
|
-
delorean_fn :test_fn3
|
151
|
+
delorean_fn :test_fn3 do |a, b, c, d = :default, e = nil, *args|
|
152
152
|
{
|
153
153
|
a: a,
|
154
154
|
b: b,
|
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: 2.
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Arman Bostani
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-10-
|
11
|
+
date: 2019-10-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -172,6 +172,7 @@ files:
|
|
172
172
|
- spec/func_spec.rb
|
173
173
|
- spec/parse_spec.rb
|
174
174
|
- spec/perf_spec.rb
|
175
|
+
- spec/ruby/error_handling_spec.rb
|
175
176
|
- spec/ruby/whitelist_spec.rb
|
176
177
|
- spec/spec_helper.rb
|
177
178
|
homepage: https://github.com/arman000/delorean_lang
|
@@ -204,5 +205,6 @@ test_files:
|
|
204
205
|
- spec/func_spec.rb
|
205
206
|
- spec/parse_spec.rb
|
206
207
|
- spec/perf_spec.rb
|
208
|
+
- spec/ruby/error_handling_spec.rb
|
207
209
|
- spec/ruby/whitelist_spec.rb
|
208
210
|
- spec/spec_helper.rb
|