wice_grid 3.5.0 → 3.6.0.pre1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. checksums.yaml +4 -4
  2. data/.inch.yml +3 -0
  3. data/.rspec +3 -0
  4. data/.rubocop.yml +181 -0
  5. data/.travis.yml +22 -0
  6. data/{CHANGELOG → CHANGELOG.md} +95 -31
  7. data/Gemfile +4 -1
  8. data/README.md +1517 -0
  9. data/Rakefile +51 -7
  10. data/{SAVED_QUERIES_HOWTO.rdoc → SAVED_QUERIES_HOWTO.md} +34 -31
  11. data/TODO.md +16 -0
  12. data/lib/generators/wice_grid/add_migration_for_serialized_queries_generator.rb +4 -6
  13. data/lib/generators/wice_grid/install_generator.rb +2 -5
  14. data/lib/generators/wice_grid/templates/create_wice_grid_serialized_queries.rb +1 -0
  15. data/lib/generators/wice_grid/templates/wice_grid_config.rb +29 -34
  16. data/lib/wice/active_record_column_wrapper.rb +36 -17
  17. data/lib/wice/columns.rb +53 -52
  18. data/lib/wice/columns/column_action.rb +11 -13
  19. data/lib/wice/columns/column_boolean.rb +9 -11
  20. data/lib/wice/columns/column_bootstrap_datepicker.rb +48 -0
  21. data/lib/wice/columns/column_custom_dropdown.rb +22 -23
  22. data/lib/wice/columns/column_float.rb +2 -6
  23. data/lib/wice/columns/column_html5_datepicker.rb +31 -0
  24. data/lib/wice/columns/column_integer.rb +9 -13
  25. data/lib/wice/columns/column_jquery_datepicker.rb +49 -0
  26. data/lib/wice/columns/column_processor_index.rb +18 -13
  27. data/lib/wice/columns/column_rails_date_helper.rb +41 -0
  28. data/lib/wice/columns/column_rails_datetime_helper.rb +40 -0
  29. data/lib/wice/columns/column_range.rb +7 -11
  30. data/lib/wice/columns/column_string.rb +24 -20
  31. data/lib/wice/columns/common_date_datetime_mixin.rb +20 -0
  32. data/lib/wice/columns/common_js_date_datetime_conditions_generator_mixin.rb +39 -0
  33. data/lib/wice/columns/common_js_date_datetime_mixin.rb +15 -0
  34. data/lib/wice/columns/{column_date.rb → common_rails_date_datetime_conditions_generator_mixin.rb} +4 -22
  35. data/lib/wice/columns/common_standard_helper_date_datetime_mixin.rb +22 -0
  36. data/lib/wice/grid_output_buffer.rb +19 -10
  37. data/lib/wice/grid_renderer.rb +146 -85
  38. data/lib/wice/helpers/bs_calendar_helpers.rb +6 -7
  39. data/lib/wice/helpers/js_calendar_helpers.rb +19 -17
  40. data/lib/wice/helpers/wice_grid_misc_view_helpers.rb +18 -18
  41. data/lib/wice/helpers/wice_grid_serialized_queries_view_helpers.rb +44 -49
  42. data/lib/wice/helpers/wice_grid_view_helpers.rb +131 -134
  43. data/lib/wice/kaminari_monkey_patching.rb +3 -1
  44. data/lib/wice/table_column_matrix.rb +23 -8
  45. data/lib/wice/wice_grid_controller.rb +12 -16
  46. data/lib/wice/wice_grid_core_ext.rb +12 -20
  47. data/lib/wice/wice_grid_misc.rb +131 -53
  48. data/lib/wice/wice_grid_serialized_queries_controller.rb +10 -11
  49. data/lib/wice/wice_grid_serialized_query.rb +4 -3
  50. data/lib/wice/wice_grid_spreadsheet.rb +19 -18
  51. data/lib/wice_grid.rb +144 -135
  52. data/spec/schema.rb +9 -0
  53. data/spec/spec_helper.rb +75 -0
  54. data/spec/support/active_record.rb +11 -0
  55. data/spec/support/wice_grid_test_config.rb +172 -0
  56. data/spec/wice/grid_output_buffer_spec.rb +41 -0
  57. data/spec/wice/table_column_matrix_spec.rb +38 -0
  58. data/spec/wice/wice_grid_misc_spec.rb +159 -0
  59. data/spec/wice/wice_grid_spreadsheet_spec.rb +14 -0
  60. data/test/readme.txt +1 -1
  61. data/vendor/assets/javascripts/wice_grid_init.js.coffee +14 -8
  62. data/vendor/assets/stylesheets/wice_grid.scss +84 -0
  63. data/wice_grid.gemspec +32 -16
  64. metadata +217 -25
  65. data/README.rdoc +0 -1325
  66. data/lib/generators/wice_grid/templates/wice_grid.scss +0 -140
  67. data/lib/wice/columns/column_datetime.rb +0 -171
  68. data/vendor/assets/images/icons/grid/arrow_down.gif +0 -0
  69. data/vendor/assets/images/icons/grid/arrow_up.gif +0 -0
  70. data/vendor/assets/images/icons/grid/calendar_view_month.png +0 -0
  71. data/vendor/assets/images/icons/grid/collapse.gif +0 -0
  72. data/vendor/assets/images/icons/grid/delete.png +0 -0
  73. data/vendor/assets/images/icons/grid/expand.gif +0 -0
  74. data/vendor/assets/images/icons/grid/page_white_excel.png +0 -0
  75. data/vendor/assets/images/icons/grid/page_white_find.png +0 -0
  76. data/vendor/assets/images/icons/grid/table.png +0 -0
  77. data/vendor/assets/images/icons/grid/table_refresh.png +0 -0
  78. data/vendor/assets/images/icons/grid/tick_all.png +0 -0
  79. data/vendor/assets/images/icons/grid/untick_all.png +0 -0
@@ -1,4 +1,6 @@
1
- # It is here only until this pull request is pulled: https://github.com/amatsuda/kaminari/pull/267
1
+ # encoding: utf-8
2
+
3
+ # Ugly monkey-patching Kaminari (https://github.com/amatsuda/kaminari/pull/267)
2
4
  module Kaminari #:nodoc:
3
5
  module Helpers #:nodoc:
4
6
  class Tag #:nodoc:
@@ -1,32 +1,44 @@
1
+ # encoding: utf-8
1
2
  module Wice
3
+
4
+ # a matrix for all declared columns
2
5
  class TableColumnMatrix < Hash #:nodoc:
3
6
 
7
+ # a structure to hold generates Arels for all column filters
4
8
  attr_reader :generated_conditions
5
9
 
6
- def initialize() #:nodoc:
10
+ # init a matrix of all columns
11
+ def initialize #:nodoc:
7
12
  super
8
13
  @generated_conditions = []
9
14
  @by_table_names = HashWithIndifferentAccess.new
10
15
  end
11
16
 
17
+ # add an Arel for a column
12
18
  def add_condition(column, conditions)
13
19
  @generated_conditions << [column, conditions] unless conditions.blank?
14
20
  end
15
21
 
22
+ # returns a list of all Arels
16
23
  def conditions
17
- @generated_conditions.collect{|_, cond| cond}
24
+ @generated_conditions.collect { |_, cond| cond }
18
25
  end
19
26
 
27
+ # returns Arels for one model
20
28
  alias_method :get, :[]
21
29
 
30
+ # returns the main ActiveRecord model class
22
31
  attr_reader :default_model_class
32
+
33
+ # sets the main ActiveRecord model class
23
34
  def default_model_class=(model) #:nodoc:
24
- init_columns_of_table(model) unless has_key?(model)
35
+ init_columns_of_table(model) unless key?(model)
25
36
  @default_model_class = model
26
37
  end
27
38
 
39
+ # returns Arels for one model
28
40
  def [](model) #:nodoc:
29
- init_columns_of_table(model) unless has_key?(model)
41
+ init_columns_of_table(model) unless key?(model)
30
42
  get(model)
31
43
  end
32
44
 
@@ -35,16 +47,19 @@ module Wice
35
47
  end
36
48
 
37
49
  def get_column_in_default_model_class_by_column_name(column_name) #:nodoc:
38
- raise WiceGridException.new("Cannot search for a column in a default model as the default model is not set") if @default_model_class.nil?
50
+ if @default_model_class.nil?
51
+ fail WiceGridException.new("Cannot search for this column(#{column_name}) in a default model(#{@default_model_class}) as the default model is not set")
52
+ end
53
+
39
54
  self[@default_model_class][column_name]
40
55
  end
41
56
 
42
57
  def init_columns_of_table(model) #:nodoc:
43
58
  self[model] = HashWithIndifferentAccess.new(model.columns.index_by(&:name))
44
59
  @by_table_names[model.table_name] = self[model]
45
- self[model].each_value{|c| c.model = model}
60
+ self[model].each_value { |c| c.model = model }
46
61
  end
47
- alias_method :<< , :init_columns_of_table
48
62
 
63
+ alias_method :<<, :init_columns_of_table
49
64
  end
50
- end
65
+ end
@@ -1,12 +1,11 @@
1
+ # encoding: utf-8
1
2
  module Wice
2
- module Controller
3
-
3
+ module Controller #:nodoc:
4
4
  def self.included(base) #:nodoc:
5
5
  base.extend(ClassMethods)
6
6
  end
7
7
 
8
- module ClassMethods
9
-
8
+ module ClassMethods #:nodoc:
10
9
  # Used to add query processing action methods into a controller.
11
10
  # Read section "Saving Queries How-To" in README for more details.
12
11
  def save_wice_grid_queries
@@ -28,6 +27,8 @@ module Wice
28
27
  # The second parameters is a hash of parameters:
29
28
  # * <tt>:joins</tt> - ActiveRecord <tt>:joins</tt> option.
30
29
  # * <tt>:include</tt> - ActiveRecord <tt>:include</tt> option.
30
+ # The value of `:include` can be an array of association names `include: [:category, :users, :status]`,
31
+ # If you need to join tables to joined tables, use hashes: `include: [:category, {users: :group}, :status]`
31
32
  # * <tt>:conditions</tt> - ActiveRecord <tt>:conditions</tt> option.
32
33
  # * <tt>:per_page</tt> - Number of rows per one page. The default is 10.
33
34
  # * <tt>:page</tt> - The page to show when rendering the grid for the first time. The default is one, naturally.
@@ -63,7 +64,6 @@ module Wice
63
64
  # can be changed in <tt>lib/wice_grid_config.rb</tt>, this is convenient if you want to set a project wide setting
64
65
  # without having to repeat it for every grid instance.
65
66
 
66
-
67
67
  def initialize_grid(klass, opts = {})
68
68
  wg = WiceGrid.new(klass, self, opts)
69
69
  self.wice_grid_instances = [] if self.wice_grid_instances.nil?
@@ -112,7 +112,7 @@ module Wice
112
112
  template_name ||= grid.name + '_grid'
113
113
  temp_filename = render_to_string(partial: template_name)
114
114
  temp_filename = temp_filename.strip
115
- filename = (grid.csv_file_name || grid.name ) + '.csv'
115
+ filename = (grid.csv_file_name || grid.name) + '.csv'
116
116
  grid.csv_tempfile.close
117
117
  send_file_rails2 temp_filename, filename: filename, type: 'text/csv; charset=utf-8'
118
118
  grid.csv_tempfile = nil
@@ -144,29 +144,28 @@ module Wice
144
144
  options.merge!(opts)
145
145
 
146
146
  [:attribute, :value].each do |key|
147
- raise ::Wice::WiceGridArgumentError.new("wice_grid_custom_filter_params: :#{key} is a mandatory argument") unless options[key]
147
+ fail ::Wice::WiceGridArgumentError.new("wice_grid_custom_filter_params: :#{key} is a mandatory argument") unless options[key]
148
148
  end
149
149
 
150
150
  attr_name = if options[:model]
151
151
  unless options[:model].nil?
152
152
  options[:model] = options[:model].constantize if options[:model].is_a? String
153
- raise Wice::WiceGridArgumentError.new("Option :model can be either a class or a string instance") unless options[:model].is_a? Class
153
+ fail Wice::WiceGridArgumentError.new('Option :model can be either a class or a string instance') unless options[:model].is_a? Class
154
154
  end
155
155
  options[:model].table_name + '.' + options[:attribute]
156
156
  else
157
157
  options[:attribute]
158
158
  end
159
159
 
160
- {"#{options[:grid_name]}[f][#{attr_name}][]" => options[:value]}
160
+ { "#{options[:grid_name]}[f][#{attr_name}][]" => options[:value] }
161
161
  end
162
162
 
163
163
  private
164
164
 
165
-
166
165
  def send_file_rails2(path, options = {}) #:nodoc:
167
- raise "Cannot read file #{path}" unless File.file?(path) and File.readable?(path)
166
+ fail "Cannot read file #{path}" unless File.file?(path) && File.readable?(path)
168
167
 
169
- options[:length] ||= File.size(path)
168
+ options[:length] ||= File.size(path)
170
169
  options[:filename] ||= File.basename(path) unless options[:url_based_filename]
171
170
  send_file_headers_rails2! options
172
171
 
@@ -176,7 +175,6 @@ module Wice
176
175
  File.open(path, 'rb') { |file| render status: options[:status], text: file.read }
177
176
  end
178
177
 
179
-
180
178
  DEFAULT_SEND_FILE_OPTIONS_RAILS2 = { #:nodoc:
181
179
  type: 'application/octet-stream'.freeze,
182
180
  disposition: 'attachment'.freeze,
@@ -186,10 +184,9 @@ module Wice
186
184
  }.freeze
187
185
 
188
186
  def send_file_headers_rails2!(options) #:nodoc:
189
-
190
187
  options.update(DEFAULT_SEND_FILE_OPTIONS_RAILS2.merge(options))
191
188
  [:length, :type, :disposition].each do |arg|
192
- raise ArgumentError, ":#{arg} option required" if options[arg].nil?
189
+ fail ArgumentError, ":#{arg} option required" if options[arg].nil?
193
190
  end
194
191
 
195
192
  disposition = options[:disposition].dup || 'attachment'
@@ -214,6 +211,5 @@ module Wice
214
211
  # is called for handling the download is run, so let's workaround that
215
212
  headers['Cache-Control'] = 'private' if headers['Cache-Control'] == 'no-cache'
216
213
  end
217
-
218
214
  end
219
215
  end
@@ -1,13 +1,13 @@
1
+ # encoding: utf-8
1
2
  module Wice
2
3
  module WgHash #:nodoc:
3
4
  class << self #:nodoc:
4
-
5
5
  # if there's a hash of hashes, the original structure and the
6
6
  # returned structure should not contain any shared deep hashes
7
7
  def deep_clone(hash) #:nodoc:
8
8
  cloned = hash.clone
9
9
  cloned.keys.each do |k|
10
- if cloned[k].kind_of?(Hash)
10
+ if cloned[k].is_a?(Hash)
11
11
  cloned[k] = Wice::WgHash.deep_clone cloned[k]
12
12
  end
13
13
  end
@@ -18,12 +18,12 @@ module Wice
18
18
  # it will be added, if there is, the css class name will be appended to the existing
19
19
  # class name(s)
20
20
  def add_or_append_class_value!(hash, klass_value, prepend = false) #:nodoc:
21
- if hash.has_key?('class')
21
+ if hash.key?('class')
22
22
  hash[:class] = hash['class']
23
23
  hash.delete('class')
24
24
  end
25
25
 
26
- hash[:class] = if hash.has_key?(:class)
26
+ hash[:class] = if hash.key?(:class)
27
27
  if prepend
28
28
  "#{klass_value} #{hash[:class]}"
29
29
  else
@@ -41,10 +41,9 @@ module Wice
41
41
  # In some it is important that if the value is empty, no option
42
42
  # is submitted at all. Thus, there's a check for an empty value
43
43
  def make_hash(key, value) #:nodoc:
44
- value.blank? ? {} : {key => value}
44
+ value.blank? ? {} : { key => value }
45
45
  end
46
46
 
47
-
48
47
  # A deep merge of two hashes.
49
48
  # That is, if both hashes have the same key and the values are hashes, these two hashes should also be merged.
50
49
  # Used for merging two sets of params.
@@ -81,53 +80,47 @@ module Wice
81
80
 
82
81
  def recursively_gather_finite_non_hash_values_with_key_path(hash, res, stack = []) #:nodoc:
83
82
  hash.each do |key, value|
84
- if value.kind_of?(Hash)
83
+ if value.is_a?(Hash)
85
84
  recursively_gather_finite_non_hash_values_with_key_path(value, res, stack + [key])
86
85
  else
87
86
  res << [stack + [key], value]
88
87
  end
89
88
  end
90
89
  end
91
-
92
90
  end
93
91
  end
94
92
 
95
-
96
93
  module WgEnumerable #:nodoc:
97
-
98
94
  # Used to check the validity of :custom_filter parameter of column
99
95
  def self.all_items_are_of_class(enumerable, klass) #:nodoc:
100
96
  return false if enumerable.empty?
101
- enumerable.inject(true){|memo, o| (o.is_a? klass) && memo}
97
+ enumerable.inject(true) { |memo, o| (o.is_a? klass) && memo }
102
98
  end
103
-
104
99
  end
105
100
 
106
101
  module WgArray #:nodoc:
107
102
  # Only used by Hash#parameter_names_and_values
108
103
  # Transforms ['foo', 'bar', 'baz'] to 'foo[bar][baz]'
109
104
  def self.to_parameter_name(array) #:nodoc:
110
- array[0].to_s + (array[1..-1] || []).collect{|k| '[' + k.to_s + ']'}.join('')
105
+ array[0].to_s + (array[1..-1] || []).collect { |k| '[' + k.to_s + ']' }.join('')
111
106
  end
112
107
  end
113
-
114
108
  end
115
109
 
116
-
117
110
  # tag_options is a Rails views private method that takes a hash op options for
118
111
  # an HTM hash and produces a string ready to be added to the tag.
119
112
  # Here we are changing its visibility in order to be able to use it.
120
113
  module ActionView #:nodoc:
121
114
  module Helpers #:nodoc:
122
115
  module TagHelper #:nodoc:
123
- public :tag_options
116
+ def public_tag_options(options, escape = true) #:nodoc:
117
+ tag_options(options, escape)
118
+ end
124
119
  end
125
120
  end
126
121
  end
127
122
 
128
-
129
123
  module WGObjectExtensions #:nodoc:
130
-
131
124
  # takes a list of messages, sends message 1 to self, then message 2 is sent to the result of the first message, ans so on
132
125
  # returns nil as soon as the current receiver does not respond to such a message
133
126
  def deep_send(*messages) #:nodoc:
@@ -140,11 +133,10 @@ module WGObjectExtensions #:nodoc:
140
133
  end
141
134
  # return obj if obj.nil?
142
135
  end
143
- return obj
136
+ obj
144
137
  end
145
138
  end
146
139
 
147
140
  class Object #:nodoc:
148
141
  include WGObjectExtensions
149
142
  end
150
-
@@ -1,34 +1,150 @@
1
+ # encoding: utf-8
1
2
  module Wice
2
-
3
3
  class << self
4
4
 
5
+ # a flag storing whether the saved query class is a valid storage for saved queries
5
6
  @@model_validated = false
6
7
 
8
+ def assoc_list_to_hash(assocs) #:nodoc:
9
+ head = assocs[0]
10
+ tail = assocs[1..-1]
11
+
12
+ if tail.blank?
13
+ head
14
+ elsif tail.size == 1
15
+ {head => tail[0]}
16
+ else
17
+ {head => assoc_list_to_hash(tail)}
18
+ end
19
+ end
20
+
21
+ def build_includes(existing_includes, new_assocs) #:nodoc:
22
+ new_includes = if new_assocs.blank?
23
+ existing_includes
24
+ else
25
+ existing_includes = if existing_includes.is_a?(Symbol)
26
+ [existing_includes]
27
+ elsif existing_includes.nil?
28
+ []
29
+ else
30
+ existing_includes
31
+ end
32
+
33
+ assocs_as_hash = assoc_list_to_hash(new_assocs)
34
+ build_includes_int(existing_includes, assocs_as_hash)
35
+ end
36
+
37
+ if new_includes.is_a?(Array) && new_includes.size == 1
38
+ new_includes[0]
39
+ else
40
+ new_includes
41
+ end
42
+ end
43
+
44
+ def build_includes_int(includes, assocs) #:nodoc:
45
+ if includes.is_a?(Array)
46
+ build_includes_includes_is_array(includes, assocs)
47
+ elsif includes.is_a?(Hash)
48
+ build_includes_includes_is_hash(includes, assocs)
49
+ end
50
+ end
51
+
52
+ # TODO: refactor
53
+ def build_includes_includes_is_hash(includes, assocs) #:nodoc:
54
+
55
+ includes_key = includes.keys[0]
56
+ includes_value = includes.values[0]
57
+
58
+ if assocs.is_a?(Hash)
59
+ assocs_key = assocs.keys[0]
60
+ assocs_value = assocs.values[0]
61
+
62
+ if includes_value.is_a?(Symbol) && includes_value == assocs_key
63
+ {includes_key => assocs}
64
+ elsif includes_value.is_a?(Hash)
65
+ if includes_value.keys[0] == assocs_key
66
+ if includes_value.values[0] == assocs_value
67
+ {includes_key => assocs}
68
+ else
69
+ {includes_key => [includes_value.values[0], assocs_value]}
70
+ end
71
+ end
72
+ end
73
+ elsif includes_value == assocs
74
+ {includes_key => assocs}
75
+ else
76
+ includes
77
+ end
78
+ end
79
+
80
+ def build_includes_includes_is_array(includes, assocs) #:nodoc:
81
+
82
+ hash_keys = Hash[
83
+ *(
84
+ includes
85
+ .each_with_index
86
+ .to_a
87
+ .select{ |e, _idx| e.is_a?(Hash)}
88
+ .map{ |hash, idx| [ hash.keys[0], idx ] }
89
+ .flatten
90
+ )
91
+ ]
92
+
93
+ key_to_search, finished = if assocs.is_a?(Hash)
94
+ [assocs.keys[0], false]
95
+ else
96
+ [assocs, true]
97
+ end
98
+
99
+ if idx = includes.index(key_to_search)
100
+ if finished # [:a, :b, :c] vs :a
101
+ includes
102
+ else # [:a, :b, :c] vs {:a => x}
103
+ includes[idx] = assocs
104
+ includes
105
+ end
106
+
107
+ elsif hash_keys.key?(key_to_search)
108
+ if finished # [{a: :x}, :b, :c, :d, :e] vs :a
109
+ includes
110
+ else
111
+ hash_idx = hash_keys[key_to_search]
112
+ assocs_value = assocs[key_to_search]
113
+ includes[hash_idx] = build_includes_int(includes[hash_idx], assocs_value)
114
+ includes
115
+ end
116
+
117
+ else # [:a, :b, :c] vs :x
118
+ # [:a, :b, :c] vs {:x => y}
119
+ includes + [assocs]
120
+ end
121
+
122
+ end
123
+
7
124
  # checks whether the class is a valid storage for saved queries
8
125
  def validate_query_model(query_store_model) #:nodoc:
9
126
  unless query_store_model.respond_to?(:list)
10
- raise ::Wice::WiceGridArgumentError.new("Model for saving queries #{query_store_model.class.name} is invalid - there is no class method #list defined")
127
+ fail ::Wice::WiceGridArgumentError.new("Model for saving queries #{query_store_model.class.name} is invalid - there is no class method #list defined")
11
128
  end
12
129
  arit = query_store_model.method(:list).arity
13
130
  unless arit == 2
14
- raise ::Wice::WiceGridArgumentError.new("Method list in the model for saving queries #{query_store_model.class.name} has wrong arity - it should be 2 instead of #{arit}")
131
+ fail ::Wice::WiceGridArgumentError.new("Method list in the model for saving queries #{query_store_model.class.name} has wrong arity - it should be 2 instead of #{arit}")
15
132
  end
16
133
  @@model_validated = true
17
134
  end
18
135
 
19
136
  # Retrieves and constantizes (if needed ) the Query Store model
20
137
  def get_query_store_model #:nodoc:
21
-
22
138
  query_store_model = Wice::ConfigurationProvider.value_for(:QUERY_STORE_MODEL)
23
139
  query_store_model = query_store_model.constantize if query_store_model.is_a? String
24
- raise ::Wice::WiceGridArgumentError.new("Defaults::QUERY_STORE_MODEL must be an ActiveRecord class or a string which can be constantized to an ActiveRecord class") unless query_store_model.kind_of? Class
140
+ fail ::Wice::WiceGridArgumentError.new('Defaults::QUERY_STORE_MODEL must be an ActiveRecord class or a string which can be constantized to an ActiveRecord class') unless query_store_model.is_a? Class
25
141
  validate_query_model(query_store_model) unless @@model_validated
26
142
  query_store_model
27
143
  end
28
144
 
29
145
  def get_string_matching_operators(model) #:nodoc:
30
- if defined?(Wice::Defaults::STRING_MATCHING_OPERATORS) && Wice::ConfigurationProvider.value_for(:STRING_MATCHING_OPERATORS).is_a?(Hash) &&
31
- str_matching_operator = Wice::ConfigurationProvider.value_for(:STRING_MATCHING_OPERATORS)[model.connection.class.to_s]
146
+ if defined?(Wice::Defaults::STRING_MATCHING_OPERATORS) && (ops = Wice::ConfigurationProvider.value_for(:STRING_MATCHING_OPERATORS)) &&
147
+ ops.is_a?(Hash) && (str_matching_operator = ops[model.connection.class.to_s])
32
148
  str_matching_operator
33
149
  else
34
150
  Wice::ConfigurationProvider.value_for(:STRING_MATCHING_OPERATOR)
@@ -36,7 +152,7 @@ module Wice
36
152
  end
37
153
 
38
154
  def deprecated_call(old_name, new_name, opts) #:nodoc:
39
- if opts[old_name] && ! opts[new_name]
155
+ if opts[old_name] && !opts[new_name]
40
156
  opts[new_name] = opts[old_name]
41
157
  opts.delete(old_name)
42
158
  STDERR.puts "WiceGrid: Parameter :#{old_name} is deprecated, use :#{new_name} instead!"
@@ -48,65 +164,28 @@ module Wice
48
164
  end
49
165
  end
50
166
 
51
- module MergeConditions #:nodoc:
52
- def self.included(base) #:nodoc:
53
- base.extend(ClassMethods)
54
- end
55
-
56
- module ClassMethods #:nodoc:
57
-
58
- def _sanitize_sql_hash_for_conditions(attrs, default_table_name = self.table_name)
59
- attrs = expand_hash_conditions_for_aggregates(attrs)
60
-
61
- table = Arel::Table.new(table_name, arel_engine).alias(default_table_name)
62
- ActiveRecord::PredicateBuilder.build_from_hash(self, attrs, table).map { |b|
63
- connection.visitor.accept b
64
- }.join(' AND ')
65
- end
66
-
67
-
68
- def merge_conditions(*conditions) #:nodoc:
69
- segments = []
70
-
71
- conditions.each do |condition|
72
- unless condition.blank?
73
- sql = condition.is_a?(Hash) ? _sanitize_sql_hash_for_conditions(condition) : sanitize_sql_array(condition)
74
- segments << sql unless sql.blank?
75
- end
76
- end
77
-
78
- "(#{segments.join(') AND (')})" unless segments.empty?
79
- end
80
- end
81
- end
82
-
83
-
84
167
  module NlMessage #:nodoc:
85
168
  class << self
86
-
87
169
  def [](key) #:nodoc:
88
- translated = I18n.t(key, scope: 'wice_grid')
170
+ I18n.t(key, scope: 'wice_grid')
89
171
  end
90
-
91
172
  end
92
173
  end
93
174
 
94
175
  module ConfigurationProvider #:nodoc:
95
176
  class << self
96
-
97
177
  def value_for(key, strict: true) #:nodoc:
98
178
  if Wice::Defaults.const_defined?(key)
99
179
  Wice::Defaults.const_get(key)
100
180
  else
101
181
  if strict
102
- raise WiceGridMissingConfigurationConstantException.new("Could not find constant #{key} in the configuration file!" +
103
- " It is possible that the version of WiceGrid you are using is newer than the installed configuration file in config/initializers. " +
104
- "Constant Wice::Defaults::#{key} is missing and you need to add it manually to wice_grid_config.rb or run the generator task=:\n" +
105
- " rails g wice_grid:install")
182
+ fail WiceGridMissingConfigurationConstantException.new("Could not find constant #{key} in the configuration file!" \
183
+ ' It is possible that the version of WiceGrid you are using is newer than the installed configuration file in config/initializers. ' \
184
+ "Constant Wice::Defaults::#{key} is missing and you need to add it manually to wice_grid_config.rb or run the generator task=:\n" \
185
+ ' rails g wice_grid:install')
106
186
  end # else nil
107
187
  end
108
188
  end
109
-
110
189
  end
111
190
  end
112
191
 
@@ -115,7 +194,7 @@ module Wice
115
194
 
116
195
  module ExceptionsMixin #:nodoc:
117
196
  def initialize(str) #:nodoc:
118
- super("WiceGrid: " + str)
197
+ super('WiceGrid: ' + str)
119
198
  end
120
199
  end
121
200
  class WiceGridArgumentError < ArgumentError #:nodoc:
@@ -127,5 +206,4 @@ module Wice
127
206
  class WiceGridMissingConfigurationConstantException < Exception #:nodoc:
128
207
  include ExceptionsMixin
129
208
  end
130
-
131
- end
209
+ end