rubel 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,15 +1,14 @@
1
1
  module Rubel
2
2
  module Core
3
- # query - The String or Proc to be executed
4
- def execute(query = nil)
5
-
6
- if query.is_a?(::String)
7
- query = sanitized_proc(query)
3
+ # q - The String or Proc to be executed
4
+ def execute(q = nil)
5
+ if q.is_a?(::String)
6
+ q = sanitized_proc(q)
8
7
  end
9
8
 
10
- instance_exec(&query)
11
- #rescue => e
12
- # ::Rubel::ErrorReporter.new(e, query)
9
+ instance_exec(&q)
10
+ rescue => e
11
+ ::Rubel::ErrorReporter.new(e, q)
13
12
  end
14
13
  alias query execute
15
14
 
@@ -18,20 +17,22 @@ module Rubel
18
17
  # It removes "::" from the string to prevent people to access
19
18
  # classes outside Runtime::Sandbox
20
19
  #
21
- #
22
20
  def sanitize!(string)
23
21
  string.gsub!('::', '')
24
22
  end
25
23
 
26
- # Sanitize a string from Ruby injection.
27
- #
28
- # It removes "::" from the string to prevent people to access
29
- # classes outside Runtime::Sandbox
30
- #
24
+ # Sanitizes a string from Ruby injection and *instance_eval*s it into a lambda.
25
+ # This is used internally by #execute
26
+ #
27
+ # If you execute lots of queries it is recommended to memoize the
28
+ # results somewhere in your application.
29
+ #
30
+ # The sanitation removes "::" from the string to prevent people to access
31
+ # classes outside Runtime::Sandbox. This has no effect in other runtimes.
31
32
  #
32
33
  def sanitized_proc(string)
33
34
  sanitize!(string)
34
- eval("lambda { #{string} }")
35
+ instance_eval("lambda { #{string} }")
35
36
  end
36
37
 
37
38
  # Returns method name as a Symbol if args are empty
@@ -1,3 +1,3 @@
1
1
  module Rubel
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -54,18 +54,19 @@ describe do
54
54
  execute("MAP([5.124], round(SUM(1)))").should == 5.1
55
55
  end
56
56
 
57
- # Disabled block support. looks cool, but does not work
58
- # with method_missing, etc. So rather confusing.
59
- #
60
- # it "should execute as do SUM(1,2,3) end" do
61
- # execute do
62
- # SUM(1,2,3)
63
- # end.should == 6
64
- # end
65
- #
66
- # it "should execute as { SUM(1,2,3) }" do
67
- # execute{SUM(1,2,3)}.should == 6
68
- # end
57
+ pending do
58
+ # Disabled block support. looks cool, but does not work
59
+ # with method_missing, etc. So rather confusing.
60
+ it "should execute as do SUM(1,2,3) end" do
61
+ execute do
62
+ SUM(1,2,3)
63
+ end.should == 6
64
+ end
65
+
66
+ it "should execute as { SUM(1,2,3) }" do
67
+ execute{SUM(1,2,3)}.should == 6
68
+ end
69
+ end
69
70
  end
70
71
 
71
72
  context "sandbox" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-28 00:00:00.000000000 Z
12
+ date: 2012-04-30 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: ruby enterprise language. Run excel-like formulas ruby code. E.g. SUM(MAP(KEY_ACCOUNTS(),
15
15
  revenue))
@@ -65,3 +65,4 @@ summary: A dsl for excel-like formulas to run as regular rubycode. E.g. SUM(MAP(
65
65
  test_files:
66
66
  - spec/integration/rubel_spec.rb
67
67
  - spec/spec_helper.rb
68
+ has_rdoc: