widget_list 1.3.4 → 1.3.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. data/.gitignore +35 -35
  2. data/Gemfile +3 -3
  3. data/LICENSE.txt +21 -21
  4. data/README.md +736 -728
  5. data/Rakefile +1 -1
  6. data/app/views/widget_list/_condition_fields.html.erb +0 -0
  7. data/app/views/widget_list/_ransack_fields.html.erb +0 -0
  8. data/app/views/widget_list/_ransack_widget_list_advanced_search.html.erb +0 -0
  9. data/app/views/widget_list/administration/_button_row.html.erb +13 -13
  10. data/app/views/widget_list/administration/_checkbox_row.html.erb +18 -18
  11. data/app/views/widget_list/administration/_field_row.html.erb +11 -11
  12. data/app/views/widget_list/administration/_output.html.erb +1100 -1100
  13. data/app/views/widget_list/administration/_output_save.html.erb +1 -1
  14. data/app/views/widget_list/list_partials/_col.html.erb +0 -0
  15. data/app/views/widget_list/list_partials/_list_description.html.erb +2 -2
  16. data/app/views/widget_list/list_partials/_no_sort_column.html.erb +0 -0
  17. data/app/views/widget_list/list_partials/_outer_shell.html.erb +0 -0
  18. data/app/views/widget_list/list_partials/_pagination_jump_active.html.erb +0 -0
  19. data/app/views/widget_list/list_partials/_pagination_jump_unactive.html.erb +0 -0
  20. data/app/views/widget_list/list_partials/_pagination_next_active.html.erb +0 -0
  21. data/app/views/widget_list/list_partials/_pagination_next_disabled.html.erb +0 -0
  22. data/app/views/widget_list/list_partials/_pagination_previous_active.html.erb +0 -0
  23. data/app/views/widget_list/list_partials/_pagination_previous_disabled.html.erb +0 -0
  24. data/app/views/widget_list/list_partials/_pagination_wrapper.html.erb +0 -0
  25. data/app/views/widget_list/list_partials/_row.html.erb +0 -0
  26. data/app/views/widget_list/list_partials/_sequence.html.erb +0 -0
  27. data/app/views/widget_list/list_partials/_sort_column.html.erb +0 -0
  28. data/checkin_gem.sh +0 -0
  29. data/lib/extensions/action_controller_base.rb +33 -33
  30. data/lib/widget_list.rb +4685 -4389
  31. data/lib/widget_list/engine.rb +8 -8
  32. data/lib/widget_list/hash.rb +113 -113
  33. data/lib/widget_list/md5.rb +18 -18
  34. data/lib/widget_list/railtie.rb +42 -42
  35. data/lib/widget_list/sequel.rb +287 -218
  36. data/lib/widget_list/string.rb +41 -41
  37. data/lib/widget_list/tpl.rb +185 -185
  38. data/lib/widget_list/utils.rb +92 -92
  39. data/lib/widget_list/version.rb +3 -3
  40. data/lib/widget_list/widgets.rb +756 -756
  41. data/publish_gem.sh +37 -37
  42. data/vendor/assets/images/gobblecons/README.rtf +127 -127
  43. data/vendor/assets/javascripts/widget_list.js +795 -795
  44. data/vendor/assets/stylesheets/widget_list.css +813 -813
  45. data/vendor/assets/stylesheets/widgets.css +116 -116
  46. data/widget_list.gemspec +38 -38
  47. metadata +63 -54
@@ -1,8 +1,8 @@
1
- module WidgetList
2
- class Engine < Rails::Engine
3
- # auto wire
4
- initializer 'widget_list.load_static_assets' do |app|
5
- app.middleware.use ::ActionDispatch::Static, "#{root}/vendor"
6
- end
7
- end
8
- end
1
+ module WidgetList
2
+ class Engine < Rails::Engine
3
+ # auto wire
4
+ initializer 'widget_list.load_static_assets' do |app|
5
+ app.middleware.use ::ActionDispatch::Static, "#{root}/vendor"
6
+ end
7
+ end
8
+ end
@@ -1,114 +1,114 @@
1
- class Hash
2
-
3
- def to_params
4
- params = ''
5
- stack = []
6
-
7
- each do |k, v|
8
- if v.is_a?(Hash)
9
- stack << [k,v]
10
- elsif v.is_a?(Array)
11
- stack << [k,Hash.from_array(v)]
12
- else
13
- params << "#{k}=#{v}&"
14
- end
15
- end
16
-
17
- stack.each do |parent, hash|
18
- hash.each do |k, v|
19
- if v.is_a?(Hash)
20
- stack << ["#{parent}[#{k}]", v]
21
- else
22
- params << "#{parent}[#{k}]=#{v}&"
23
- end
24
- end
25
- end
26
-
27
- params.chop!
28
- params
29
- end
30
-
31
- def self.from_array(array = [])
32
- h = Hash.new
33
- array.size.times do |t|
34
- h[t] = array[t]
35
- end
36
- h
37
- end
38
-
39
- # Merges self with another hash, recursively.
40
- #
41
- # This code was lovingly stolen from some random gem:
42
- # http://gemjack.com/gems/tartan-0.1.1/classes/Hash.html
43
- #
44
- # Thanks to whoever made it.
45
-
46
- def deep_merge(hash)
47
- target = dup
48
-
49
- hash.keys.each do |key|
50
- if hash[key].is_a? Hash and self[key].is_a? Hash
51
- target[key] = target[key].deep_merge(hash[key])
52
- next
53
- end
54
-
55
- target[key] = hash[key]
56
- end
57
-
58
- target
59
- end
60
-
61
-
62
- # From: http://www.gemtacular.com/gemdocs/cerberus-0.2.2/doc/classes/Hash.html
63
- # File lib/cerberus/utils.rb, line 42
64
-
65
- def deep_merge!(second)
66
- second.each_pair do |k,v|
67
- if self[k].is_a?(Hash) and second[k].is_a?(Hash)
68
- self[k].deep_merge!(second[k])
69
- else
70
- self[k] = second[k]
71
- end
72
- end
73
- end
74
-
75
-
76
- #-----------------
77
-
78
- # cf. http://subtech.g.hatena.ne.jp/cho45/20061122
79
- def deep_merge2(other)
80
- deep_proc = Proc.new { |k, s, o|
81
- if s.kind_of?(Hash) && o.kind_of?(Hash)
82
- next s.merge(o, &deep_proc)
83
- end
84
- next o
85
- }
86
- merge(other, &deep_proc)
87
- end
88
-
89
-
90
- def deep_merge3(second)
91
-
92
- # From: http://www.ruby-forum.com/topic/142809
93
- # Author: Stefan Rusterholz
94
-
95
- merger = proc { |key,v1,v2| Hash === v1 && Hash === v2 ? v1.merge(v2, &merger) : v2 }
96
- self.merge(second, &merger)
97
-
98
- end
99
-
100
-
101
- def keep_merge(hash)
102
- target = dup
103
- hash.keys.each do |key|
104
- if hash[key].is_a? Hash and self[key].is_a? Hash
105
- target[key] = target[key].keep_merge(hash[key])
106
- next
107
- end
108
- #target[key] = hash[key]
109
- target.update(hash) { |key, *values| values.flatten.uniq }
110
- end
111
- target
112
- end
113
-
1
+ class Hash
2
+
3
+ def to_params
4
+ params = ''
5
+ stack = []
6
+
7
+ each do |k, v|
8
+ if v.is_a?(Hash)
9
+ stack << [k,v]
10
+ elsif v.is_a?(Array)
11
+ stack << [k,Hash.from_array(v)]
12
+ else
13
+ params << "#{k}=#{v}&"
14
+ end
15
+ end
16
+
17
+ stack.each do |parent, hash|
18
+ hash.each do |k, v|
19
+ if v.is_a?(Hash)
20
+ stack << ["#{parent}[#{k}]", v]
21
+ else
22
+ params << "#{parent}[#{k}]=#{v}&"
23
+ end
24
+ end
25
+ end
26
+
27
+ params.chop!
28
+ params
29
+ end
30
+
31
+ def self.from_array(array = [])
32
+ h = Hash.new
33
+ array.size.times do |t|
34
+ h[t] = array[t]
35
+ end
36
+ h
37
+ end
38
+
39
+ # Merges self with another hash, recursively.
40
+ #
41
+ # This code was lovingly stolen from some random gem:
42
+ # http://gemjack.com/gems/tartan-0.1.1/classes/Hash.html
43
+ #
44
+ # Thanks to whoever made it.
45
+
46
+ def deep_merge(hash)
47
+ target = dup
48
+
49
+ hash.keys.each do |key|
50
+ if hash[key].is_a? Hash and self[key].is_a? Hash
51
+ target[key] = target[key].deep_merge(hash[key])
52
+ next
53
+ end
54
+
55
+ target[key] = hash[key]
56
+ end
57
+
58
+ target
59
+ end
60
+
61
+
62
+ # From: http://www.gemtacular.com/gemdocs/cerberus-0.2.2/doc/classes/Hash.html
63
+ # File lib/cerberus/utils.rb, line 42
64
+
65
+ def deep_merge!(second)
66
+ second.each_pair do |k,v|
67
+ if self[k].is_a?(Hash) and second[k].is_a?(Hash)
68
+ self[k].deep_merge!(second[k])
69
+ else
70
+ self[k] = second[k]
71
+ end
72
+ end
73
+ end
74
+
75
+
76
+ #-----------------
77
+
78
+ # cf. http://subtech.g.hatena.ne.jp/cho45/20061122
79
+ def deep_merge2(other)
80
+ deep_proc = Proc.new { |k, s, o|
81
+ if s.kind_of?(Hash) && o.kind_of?(Hash)
82
+ next s.merge(o, &deep_proc)
83
+ end
84
+ next o
85
+ }
86
+ merge(other, &deep_proc)
87
+ end
88
+
89
+
90
+ def deep_merge3(second)
91
+
92
+ # From: http://www.ruby-forum.com/topic/142809
93
+ # Author: Stefan Rusterholz
94
+
95
+ merger = proc { |key,v1,v2| Hash === v1 && Hash === v2 ? v1.merge(v2, &merger) : v2 }
96
+ self.merge(second, &merger)
97
+
98
+ end
99
+
100
+
101
+ def keep_merge(hash)
102
+ target = dup
103
+ hash.keys.each do |key|
104
+ if hash[key].is_a? Hash and self[key].is_a? Hash
105
+ target[key] = target[key].keep_merge(hash[key])
106
+ next
107
+ end
108
+ #target[key] = hash[key]
109
+ target.update(hash) { |key, *values| values.flatten.uniq }
110
+ end
111
+ target
112
+ end
113
+
114
114
  end
@@ -1,19 +1,19 @@
1
- require 'digest/md5'
2
-
3
- class Object
4
- def md5key
5
- to_s
6
- end
7
- end
8
-
9
- class Array
10
- def md5key
11
- map(&:md5key).join
12
- end
13
- end
14
-
15
- class Hash
16
- def md5key
17
- sort.map(&:md5key).join
18
- end
1
+ require 'digest/md5'
2
+
3
+ class Object
4
+ def md5key
5
+ to_s
6
+ end
7
+ end
8
+
9
+ class Array
10
+ def md5key
11
+ map(&:md5key).join
12
+ end
13
+ end
14
+
15
+ class Hash
16
+ def md5key
17
+ sort.map(&:md5key).join
18
+ end
19
19
  end
@@ -1,42 +1,42 @@
1
- module WidgetList
2
- class Railtie < Rails::Railtie
3
-
4
- config.before_configuration do
5
- config_file = Rails.root.join("config", "widget-list.yml")
6
- if config_file.file?
7
- # WidgetList::List::connect
8
- else
9
- puts "\nWidget List config not found. Creating config/widget-list.yml. \n\nPlease configure it with the appropriate connections"
10
- File.open(Rails.root.join("config", "widget-list.yml"), 'w') { |file|
11
- file.write("#For connection examples see: http://sequel.rubyforge.org/rdoc/files/doc/opening_databases_rdoc.html\n\n")
12
- file.write("development:\n")
13
- file.write(" :primary: sqlite:/\n")
14
- file.write(" :secondary: sqlite:/\n")
15
- file.write("\n")
16
- file.write("test:\n")
17
- file.write(" :primary: sqlite:/\n")
18
- file.write(" :secondary: sqlite:/\n")
19
- file.write("\n")
20
- file.write("release:\n")
21
- file.write(" :primary: sqlite:/\n")
22
- file.write(" :secondary: sqlite:/\n")
23
- file.write("\n")
24
- file.write("production:\n")
25
- file.write(" :primary: sqlite:/\n")
26
- file.write(" :secondary: sqlite:/\n")
27
- }
28
- end
29
- end
30
-
31
- initializer "Include widget_list" do
32
- ActiveSupport.on_load(:action_controller) do
33
- if WidgetList::List::is_sequel(true) || WidgetList::List::is_sequel(false)
34
- require 'sequel'
35
- end
36
- require 'widget_list/sequel'
37
- end
38
- end
39
-
40
-
41
- end
42
- end
1
+ module WidgetList
2
+ class Railtie < Rails::Railtie
3
+
4
+ config.before_configuration do
5
+ config_file = Rails.root.join("config", "widget-list.yml")
6
+ if config_file.file?
7
+ # WidgetList::List::connect
8
+ else
9
+ puts "\nWidget List config not found. Creating config/widget-list.yml. \n\nPlease configure it with the appropriate connections"
10
+ File.open(Rails.root.join("config", "widget-list.yml"), 'w') { |file|
11
+ file.write("#For connection examples see: http://sequel.rubyforge.org/rdoc/files/doc/opening_databases_rdoc.html\n\n")
12
+ file.write("development:\n")
13
+ file.write(" :primary: sqlite:/\n")
14
+ file.write(" :secondary: sqlite:/\n")
15
+ file.write("\n")
16
+ file.write("test:\n")
17
+ file.write(" :primary: sqlite:/\n")
18
+ file.write(" :secondary: sqlite:/\n")
19
+ file.write("\n")
20
+ file.write("release:\n")
21
+ file.write(" :primary: sqlite:/\n")
22
+ file.write(" :secondary: sqlite:/\n")
23
+ file.write("\n")
24
+ file.write("production:\n")
25
+ file.write(" :primary: sqlite:/\n")
26
+ file.write(" :secondary: sqlite:/\n")
27
+ }
28
+ end
29
+ end
30
+
31
+ initializer "Include widget_list" do
32
+ ActiveSupport.on_load(:action_controller) do
33
+ if WidgetList::List::is_sequel(true) || WidgetList::List::is_sequel(false)
34
+ require 'sequel'
35
+ end
36
+ require 'widget_list/sequel'
37
+ end
38
+ end
39
+
40
+
41
+ end
42
+ end
@@ -1,219 +1,288 @@
1
- module Sequel
2
- class Database
3
- @final_results = {}
4
- attr_accessor :final_results
5
-
6
- @errors = false
7
- attr_accessor :errors
8
-
9
- @last_error = ''
10
- attr_accessor :last_error
11
-
12
- @db_type = ''
13
- attr_accessor :db_type
14
-
15
- @final_count = 0
16
- attr_accessor :final_count
17
-
18
- @last_sql = ''
19
- attr_accessor :last_sql
20
-
21
- def _convert_bind(bind=[])
22
- parameters = ''
23
- unless bind.empty?
24
- all = []
25
- (bind||{}).each { |v|
26
- if v.class.name.downcase == 'string'
27
- all << "'" + v.gsub(/'/,"\\\\'") + "'"
28
- else
29
- all << v
30
- end
31
- }
32
- parameters = "," + all.join(' ,')
33
- end
34
- parameters
35
- end
36
-
37
- def _convert_active_record_bind(sql='',bind=[])
38
- unless bind.empty?
39
- (bind||{}).each { |v|
40
- sql.sub!(/\?/,v.to_s)
41
- }
42
- end
43
- end
44
-
45
- # _exec, pass a block and iterate the total rows
46
- #
47
- # example
48
- #
49
- =begin
50
- $DATABASE._exec {|i|
51
- asdf = "#{@final_results['NAME'][i]}"
52
- }
53
- =end
54
- #
55
- # Alternatively you could
56
- =begin
57
- @final_results['ID'].each_with_index { |id,k|
58
- name = @final_results['NAME'][k]
59
- price = @final_results['PRICE'][k]
60
- }
61
- =end
62
-
63
- def _exec
64
- if block_given?
65
- @final_count.times {|i|
66
- yield i
67
- }
68
- end
69
- end
70
-
71
- def _determine_type(sql_or_obj)
72
- if sql_or_obj.class.name.downcase != 'string' && sql_or_obj.class.name.to_s.split('::').last.downcase == 'dataset'
73
- sql = sql_or_obj.get_sql()
74
- elsif sql_or_obj.class.name.downcase == 'string'
75
- sql = sql_or_obj
76
- end
77
- end
78
-
79
- # probably not needed really
80
- def _update(sql_or_obj,bind={})
81
-
82
- end
83
-
84
- # @param [Object] replace_in_query
85
- def _bind(sql='',replace_in_query={})
86
- if !replace_in_query.empty? && replace_in_query.class.name == 'Hash'
87
- tmp = {}
88
- replace_in_query.each { |k, v|
89
- new_key = ':' + k.to_s
90
- tmp[ new_key ] = v
91
- }
92
- sql = WidgetList::Utils::fill(tmp, sql)
93
- end
94
- sql
95
- end
96
-
97
- def _get_row_value(row,fieldName)
98
- row.send(fieldName).to_s
99
- end
100
-
101
- # @param [Object or String] sql_or_obj
102
- # will either take raw SQL or a Sequel object
103
- # @param [Array] bind
104
- # will be replacements for ? ? in your query. Must be in sequence
105
- # @param [Hash] replace_in_query
106
- # will be a traditional php bind hash {'BIND'=>'value'}. which will replace :BIND in the query. thanks mwild
107
-
108
- def _select(sql_or_obj, bind=[], replace_in_query={}, active_record_model=false)
109
- # supporting either
110
- # if get_database._select('select * from items where name = ? AND price > ?', ['abc', 37]) > 0
111
- # or
112
- # if get_database._select(get_database[:items].filter(:name => 'abc')) > 0
113
- #
114
- sql = ''
115
- sql = _determine_type(sql_or_obj)
116
-
117
- if self.class.name != 'WidgetListActiveRecord'
118
-
119
- # build csv of bind to eval below (arguments need to be like this for raw SQL passed with bind in Sequel)
120
- #
121
- parameters = _convert_bind(bind)
122
-
123
- # escape anything incoming in raw SQL such as bound items to create the ruby string to pass
124
- #
125
- sql.gsub!(/'/,"\\\\'")
126
- else
127
-
128
- _convert_active_record_bind(sql, bind)
129
-
130
- end
131
-
132
- sql = _bind(sql,replace_in_query)
133
-
134
- # build rows array['COLUMN'][0] = 1234;
135
- #
136
- first = 1
137
- cnt = 0
138
- @final_results = {}
139
- if Rails.env == 'development'
140
- Rails.logger.info(sql)
141
- end
142
-
143
- if self.class.name == 'WidgetListActiveRecord'
144
- begin
145
- results = active_record_model.find_by_sql(sql)
146
- (results||[]).each { |row|
147
- cnt += 1
148
- row.attributes.keys.each { |fieldName|
149
- if first == 1
150
- @final_results[fieldName.to_s.upcase] = []
151
- end
152
- @final_results[fieldName.to_s.upcase] << ((row.send(fieldName).nil? && row.attributes[fieldName].nil?) ? '' : _get_row_value(row,fieldName))
153
- }
154
- first = 0
155
- }
156
- @last_sql = sql_or_obj
157
-
158
- rescue Exception => e
159
- cnt = 0
160
- Rails.logger.info(e)
161
- @errors = true
162
- @last_error = e.to_s
163
- @last_sql = sql_or_obj
164
- end
165
- else
166
- eval("
167
- begin
168
- @errors = false
169
- self['" + sql + "' " + parameters + "].each { |row|
170
- cnt += 1
171
- row.each { |k,v|
172
- if first == 1
173
- @final_results[k.to_s.upcase] = []
174
- end
175
- @final_results[k.to_s.upcase] << v
176
- }
177
- first = 0
178
- }
179
- @last_sql = self['" + sql + "' " + parameters + "].get_sql
180
- rescue Exception => e
181
- Rails.logger.info(e)
182
- @errors = true
183
- @last_error = e.to_s
184
- @last_sql = '" + sql + "' + \"\n\n\n\" + ' With Bind => ' + bind.inspect + ' And BindLegacy => ' + replace_in_query.inspect
185
- end
186
- ")
187
- end
188
- @final_count = cnt
189
- return cnt
190
- end
191
- end
192
-
193
- class Dataset
194
- def get_sql
195
- select_sql()
196
- end
197
- end
198
- end
199
-
200
-
201
- class WidgetListActiveRecord < Sequel::Database
202
- @final_results = {}
203
- attr_accessor :final_results
204
-
205
- @errors = false
206
- attr_accessor :errors
207
-
208
- @last_error = ''
209
- attr_accessor :last_error
210
-
211
- @db_type = ''
212
- attr_accessor :db_type
213
-
214
- @final_count = 0
215
- attr_accessor :final_count
216
-
217
- @last_sql = ''
218
- attr_accessor :last_sql
1
+ module Sequel
2
+ class Database
3
+ @final_results = {}
4
+ attr_accessor :final_results
5
+
6
+ @errors = false
7
+ attr_accessor :errors
8
+
9
+ @last_error = ''
10
+ attr_accessor :last_error
11
+
12
+ @db_type = ''
13
+ attr_accessor :db_type
14
+
15
+ @final_count = 0
16
+ attr_accessor :final_count
17
+
18
+ @last_sql = ''
19
+ attr_accessor :last_sql
20
+
21
+ def _convert_bind(bind=[])
22
+ parameters = ''
23
+ unless bind.empty?
24
+ all = []
25
+ (bind||{}).each { |v|
26
+ if v.class.name.downcase == 'string'
27
+ all << "'" + v.gsub(/'/,"\\\\'") + "'"
28
+ else
29
+ all << v
30
+ end
31
+ }
32
+ parameters = "," + all.join(' ,')
33
+ end
34
+ parameters
35
+ end
36
+
37
+ def _convert_active_record_bind(sql='',bind=[])
38
+ unless bind.empty?
39
+ (bind||{}).each { |v|
40
+ sql.sub!(/\?/,v.to_s)
41
+ }
42
+ end
43
+ end
44
+
45
+ # _exec, pass a block and iterate the total rows
46
+ #
47
+ # example
48
+ #
49
+ =begin
50
+ $DATABASE._exec {|i|
51
+ asdf = "#{@final_results['NAME'][i]}"
52
+ }
53
+ =end
54
+ #
55
+ # Alternatively you could
56
+ =begin
57
+ @final_results['ID'].each_with_index { |id,k|
58
+ name = @final_results['NAME'][k]
59
+ price = @final_results['PRICE'][k]
60
+ }
61
+ =end
62
+
63
+ def _exec
64
+ if block_given?
65
+ @final_count.times {|i|
66
+ yield i
67
+ }
68
+ end
69
+ end
70
+
71
+ def _determine_type(sql_or_obj)
72
+ if sql_or_obj.class.name.downcase != 'string' && sql_or_obj.class.name.to_s.split('::').last.downcase == 'dataset'
73
+ sql = sql_or_obj.get_sql()
74
+ elsif sql_or_obj.class.name.downcase == 'string'
75
+ sql = sql_or_obj
76
+ end
77
+ end
78
+
79
+ # probably not needed really
80
+ def _update(sql_or_obj,bind={})
81
+
82
+ end
83
+
84
+ # @param [Object] replace_in_query
85
+ def _bind(sql='',replace_in_query={})
86
+ if !replace_in_query.empty? && replace_in_query.class.name == 'Hash'
87
+ tmp = {}
88
+ replace_in_query.each { |k, v|
89
+ new_key = ':' + k.to_s
90
+ tmp[ new_key ] = v
91
+ }
92
+ sql = WidgetList::Utils::fill(tmp, sql)
93
+ end
94
+ sql
95
+ end
96
+
97
+ def _get_row_value(row,fieldName)
98
+ row.send(fieldName).to_s
99
+ end
100
+
101
+ # @param [Object or String] sql_or_obj
102
+ # will either take raw SQL or a Sequel object
103
+ # @param [Array] bind
104
+ # will be replacements for ? ? in your query. Must be in sequence
105
+ # @param [Hash] replace_in_query
106
+ # will be a traditional php bind hash {'BIND'=>'value'}. which will replace :BIND in the query. thanks mwild
107
+
108
+ def _select(sql_or_obj, bind=[], replace_in_query={}, active_record_model=false, group_match=false)
109
+ # supporting either
110
+ # if get_database._select('select * from items where name = ? AND price > ?', ['abc', 37]) > 0
111
+ # or
112
+ # if get_database._select(get_database[:items].filter(:name => 'abc')) > 0
113
+ #
114
+ sql = ''
115
+ sql = _determine_type(sql_or_obj)
116
+
117
+ if self.class.name != 'WidgetListActiveRecord'
118
+
119
+ # build csv of bind to eval below (arguments need to be like this for raw SQL passed with bind in Sequel)
120
+ #
121
+ parameters = _convert_bind(bind)
122
+
123
+ # escape anything incoming in raw SQL such as bound items to create the ruby string to pass
124
+ #
125
+ sql.gsub!(/'/,"\\\\'")
126
+ else
127
+
128
+ _convert_active_record_bind(sql, bind)
129
+
130
+ end
131
+
132
+ sql = _bind(sql,replace_in_query)
133
+
134
+ # build rows array['COLUMN'][0] = 1234;
135
+ #
136
+ first = 1
137
+ cnt = 0
138
+ tmp = nil
139
+ @final_results = {}
140
+ if Rails.env == 'development'
141
+ Rails.logger.info(sql)
142
+ end
143
+
144
+ if self.class.name == 'WidgetListActiveRecord'
145
+ begin
146
+
147
+ if $is_mongo
148
+ if !group_match.nil?
149
+ params = []
150
+
151
+ if group_match.key?('match') && !group_match['match'].empty?
152
+ group_match['match'].each { |match|
153
+ field = match.keys.first
154
+ if active_record_model.respond_to?(:serializers) && active_record_model.serializers[field].type.to_s == 'Integer'
155
+ if match[match.keys.first].class.name == 'Hash'
156
+ predicate = match[field].keys.first
157
+ value_original = match[field][predicate]
158
+ match_final = {
159
+ field => { predicate =>
160
+ WidgetList::List.parse_inputs_for_mongo_predicates(active_record_model, field, predicate, value_original)
161
+ }
162
+ }
163
+ else
164
+ match_final = { field => WidgetList::List.parse_inputs_for_mongo_predicates(active_record_model, field, predicate, value_original) }
165
+ end
166
+
167
+ else
168
+ match_final = { field => WidgetList::List.parse_inputs_for_mongo_predicates(active_record_model, field, predicate, match[field]) }
169
+ end
170
+ params << {
171
+ '$match' => match_final
172
+ }
173
+ }
174
+ end
175
+
176
+ params << group_match['group'] if group_match.key?('group')
177
+ params << group_match['sort'] if group_match.key?('sort')
178
+ params << group_match['skip'] if group_match.key?('skip')
179
+ params << group_match['limit'] if group_match.key?('limit')
180
+
181
+ active_record_model = active_record_model.collection.aggregate(params)
182
+ end
183
+ end
184
+
185
+ if $is_mongo && sql == 'count'
186
+
187
+ cnt = active_record_model.count
188
+ @final_results['TOTAL'] = []
189
+ @final_results['TOTAL'][0] = cnt
190
+
191
+ else
192
+
193
+ if $is_mongo
194
+ results = active_record_model.all.to_a if active_record_model.respond_to?('all')
195
+ results = active_record_model.to_a if active_record_model.respond_to?('to_a') && !group_match.nil?
196
+ else
197
+ results = active_record_model.find_by_sql(sql)
198
+ end
199
+
200
+ (results||[]).each { |row|
201
+ cnt += 1
202
+ row.attributes.keys.each { |fieldName|
203
+ @final_results[fieldName.to_s.upcase] = [] unless @final_results.key?(fieldName.to_s.upcase)
204
+ @final_results[fieldName.to_s.upcase] << ((row.send(fieldName).nil? && row.attributes[fieldName].nil?) ? '' : _get_row_value(row,fieldName))
205
+ } if group_match.nil?
206
+
207
+ row.each { |key,value|
208
+ @final_results['CNT'] = [] unless @final_results.key?('CNT')
209
+ if key == '_id' && !value.empty?
210
+ value.each { |k,v|
211
+ @final_results[k.to_s.upcase] = [] unless @final_results.key?(k.to_s.upcase)
212
+ }
213
+ end
214
+ if key == 'cnt'
215
+ @final_results['CNT'] << value
216
+ elsif key == '_id'
217
+ value.each { |k,v|
218
+ @final_results[k.to_s.upcase] << v
219
+ }
220
+ end
221
+
222
+ } if !group_match.nil?
223
+ }
224
+ @last_sql = sql_or_obj
225
+ end
226
+
227
+ rescue Exception => e
228
+ cnt = 0
229
+ Rails.logger.info(e)
230
+ @errors = true
231
+ @last_error = e.to_s
232
+ @last_sql = sql_or_obj
233
+ end
234
+ else
235
+ eval("
236
+ begin
237
+ @errors = false
238
+ self['" + sql + "' " + parameters + "].each { |row|
239
+ cnt += 1
240
+ row.each { |k,v|
241
+ if first == 1
242
+ @final_results[k.to_s.upcase] = []
243
+ end
244
+ @final_results[k.to_s.upcase] << v
245
+ }
246
+ first = 0
247
+ }
248
+ @last_sql = self['" + sql + "' " + parameters + "].get_sql
249
+ rescue Exception => e
250
+ Rails.logger.info(e)
251
+ @errors = true
252
+ @last_error = e.to_s
253
+ @last_sql = '" + sql + "' + \"\n\n\n\" + ' With Bind => ' + bind.inspect + ' And BindLegacy => ' + replace_in_query.inspect
254
+ end
255
+ ")
256
+ end
257
+ @final_count = cnt
258
+ return cnt
259
+ end
260
+ end
261
+
262
+ class Dataset
263
+ def get_sql
264
+ select_sql()
265
+ end
266
+ end
267
+ end
268
+
269
+
270
+ class WidgetListActiveRecord < Sequel::Database
271
+ @final_results = {}
272
+ attr_accessor :final_results
273
+
274
+ @errors = false
275
+ attr_accessor :errors
276
+
277
+ @last_error = ''
278
+ attr_accessor :last_error
279
+
280
+ @db_type = ''
281
+ attr_accessor :db_type
282
+
283
+ @final_count = 0
284
+ attr_accessor :final_count
285
+
286
+ @last_sql = ''
287
+ attr_accessor :last_sql
219
288
  end