rgviz-rails 0.6 → 0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/rails/init.rb +27 -6
  2. metadata +3 -3
data/rails/init.rb CHANGED
@@ -9,12 +9,33 @@ config.after_initialize do
9
9
  else
10
10
  model = hash[:rgviz]
11
11
  query = params[:tq]
12
- version = hash[:version]
13
- reqId = hash[:reqId]
14
- sig = hash[:sig]
15
- executor = Rgviz::Executor.new model, Rgviz::Parser.new(query).parse
16
- table = executor.execute
17
- original_render :text => "google.visualization.Query.setResponse({version:'#{version}',reqId:'#{reqId}',status:'ok',sig:'#{sig}',table:#{table.to_json}});"
12
+ tqx = params[:tqx] || ''
13
+ pieces = tqx.split ';'
14
+ reqId = '0'
15
+ version = '0.6'
16
+ responseHandler = 'google.visualization.Query.setResponse'
17
+ pieces.each do |p|
18
+ key_value = p.split ':'
19
+ if key_value.length == 2
20
+ case key_value[0]
21
+ when 'reqId'
22
+ reqId = key_value[1]
23
+ when 'version'
24
+ version = key_value[1]
25
+ when 'responseHandler'
26
+ responseHandler = key_value[1]
27
+ end
28
+ end
29
+ end
30
+
31
+ begin
32
+ executor = Rgviz::Executor.new model, Rgviz::Parser.new(query).parse
33
+ table = executor.execute
34
+ original_render :text => "#{responseHandler}({reqId:'#{reqId}',status:'ok',version:'#{version}',table:#{table.to_json}});"
35
+ rescue ParseException => e
36
+ msg = e.message.gsub("'", "\\'")
37
+ original_render :text => "#{responseHandler}({reqId:'#{reqId}',status:'error',version:'#{version}',errors:[{reason:'invalid_query', message:'#{msg}'}]});"
38
+ end
18
39
  end
19
40
  else
20
41
  original_render *args, &block
metadata CHANGED
@@ -1,12 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rgviz-rails
3
3
  version: !ruby/object:Gem::Version
4
- hash: 7
4
+ hash: 5
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 6
9
- version: "0.6"
8
+ - 7
9
+ version: "0.7"
10
10
  platform: ruby
11
11
  authors:
12
12
  - Ary Borenszweig