ransack_ui 1.3.4 → 2.0.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 450cbf63ff25b9609e853303c1772d2ddd87b479
4
- data.tar.gz: 4135fc35e6a6e29275ad04857459e9dc9489abcb
2
+ SHA256:
3
+ metadata.gz: c76bc56f01efed6de571cb9a79a094095af122c6a35f46abb9bf6567de74b275
4
+ data.tar.gz: 26367f813d7dd0851ede9a027aea951ff307fd9e2f7d1380abe72eb5afc762f0
5
5
  SHA512:
6
- metadata.gz: ecf779eea45d25fa69ceea221335f12509cf12106fb021b168cc3c7c60117553ca12124a120df361b30de851383e4bd78d8aab1c16d8d1f64174de6d0ea2cddc
7
- data.tar.gz: 621623bc8377f1e43aca92a2f826689131674e0d495865768d1edfe14f0bcb92bdfd1999b80c886db4c46dfbd2d65c60de8bdf336fd52881f3bad4468f6e33dd
6
+ metadata.gz: 06223a0eee0aa80c48b987aea5271aae10d4d2921265cd70725b9731615fbae62270684d23069502df922618e0f6d65e7b163291fb4fa8f9a0c63b3695fb5cce
7
+ data.tar.gz: 664bb6c97c1a9fd16b4bc461de11cb466e5236297551ad3932816c1122b5e65f5442730bbee135f4f19fd07cadbb1fe752779916794d533af2cd33b6572ec4d8
data/.rubocop_todo.yml ADDED
@@ -0,0 +1,129 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2019-11-08 16:20:08 +1030 using RuboCop version 0.76.0.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 1
10
+ # Cop supports --auto-correct.
11
+ # Configuration parameters: TreatCommentsAsGroupSeparators, Include.
12
+ # Include: **/*.gemspec
13
+ Gemspec/OrderedDependencies:
14
+ Exclude:
15
+ - 'ransack_ui.gemspec'
16
+
17
+ # Offense count: 5
18
+ # Cop supports --auto-correct.
19
+ # Configuration parameters: AllowUnusedKeywordArguments, IgnoreEmptyMethods.
20
+ Lint/UnusedMethodArgument:
21
+ Exclude:
22
+ - 'lib/ransack_ui/adapters/active_record/base.rb'
23
+ - 'lib/ransack_ui/ransack_overrides/adapters/active_record/base.rb'
24
+ - 'lib/ransack_ui/view_helpers.rb'
25
+
26
+ # Offense count: 6
27
+ Metrics/AbcSize:
28
+ Max: 53
29
+
30
+ # Offense count: 2
31
+ # Configuration parameters: CountComments, ExcludedMethods.
32
+ # ExcludedMethods: refine
33
+ Metrics/BlockLength:
34
+ Max: 200
35
+
36
+ # Offense count: 1
37
+ # Configuration parameters: CountBlocks.
38
+ Metrics/BlockNesting:
39
+ Max: 5
40
+
41
+ # Offense count: 3
42
+ Metrics/CyclomaticComplexity:
43
+ Max: 12
44
+
45
+ # Offense count: 7
46
+ # Configuration parameters: CountComments, ExcludedMethods.
47
+ Metrics/MethodLength:
48
+ Max: 46
49
+
50
+ # Offense count: 1
51
+ # Configuration parameters: CountComments.
52
+ Metrics/ModuleLength:
53
+ Max: 202
54
+
55
+ # Offense count: 3
56
+ Metrics/PerceivedComplexity:
57
+ Max: 13
58
+
59
+ # Offense count: 2
60
+ # Configuration parameters: NamePrefix, NamePrefixBlacklist, NameWhitelist, MethodDefinitionMacros.
61
+ # NamePrefix: is_, has_, have_
62
+ # NamePrefixBlacklist: is_, has_, have_
63
+ # NameWhitelist: is_a?
64
+ # MethodDefinitionMacros: define_method, define_singleton_method
65
+ Naming/PredicateName:
66
+ Exclude:
67
+ - 'spec/**/*'
68
+ - 'lib/ransack_ui/adapters/active_record/base.rb'
69
+ - 'lib/ransack_ui/ransack_overrides/adapters/active_record/base.rb'
70
+
71
+ # Offense count: 2
72
+ # Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames.
73
+ # AllowedNames: io, id, to, by, on, in, at, ip, db, os
74
+ Naming/UncommunicativeMethodParamName:
75
+ Exclude:
76
+ - 'lib/ransack_ui/view_helpers.rb'
77
+
78
+ # Offense count: 1
79
+ # Cop supports --auto-correct.
80
+ # Configuration parameters: EnforcedStyle, SingleLineConditionsOnly, IncludeTernaryExpressions.
81
+ # SupportedStyles: assign_to_condition, assign_inside_condition
82
+ Style/ConditionalAssignment:
83
+ Exclude:
84
+ - 'lib/ransack_ui/ransack_overrides/helpers/form_builder.rb'
85
+
86
+ # Offense count: 11
87
+ Style/Documentation:
88
+ Exclude:
89
+ - 'spec/**/*'
90
+ - 'test/**/*'
91
+ - 'lib/ransack_ui/adapters/active_record/base.rb'
92
+ - 'lib/ransack_ui/controller_helpers.rb'
93
+ - 'lib/ransack_ui/rails/engine.rb'
94
+ - 'lib/ransack_ui/ransack_overrides/adapters/active_record/base.rb'
95
+ - 'lib/ransack_ui/ransack_overrides/configuration.rb'
96
+ - 'lib/ransack_ui/ransack_overrides/context.rb'
97
+ - 'lib/ransack_ui/ransack_overrides/helpers/form_builder.rb'
98
+ - 'lib/ransack_ui/ransack_overrides/nodes/attribute.rb'
99
+ - 'lib/ransack_ui/ransack_overrides/nodes/condition.rb'
100
+ - 'lib/ransack_ui/ransack_overrides/nodes/grouping.rb'
101
+ - 'lib/ransack_ui/view_helpers.rb'
102
+
103
+ # Offense count: 1
104
+ # Cop supports --auto-correct.
105
+ Style/EachWithObject:
106
+ Exclude:
107
+ - 'lib/ransack_ui/ransack_overrides/helpers/form_builder.rb'
108
+
109
+ # Offense count: 17
110
+ # Cop supports --auto-correct.
111
+ # Configuration parameters: EnforcedStyle.
112
+ # SupportedStyles: always, never
113
+ Style/FrozenStringLiteralComment:
114
+ Enabled: false
115
+
116
+ # Offense count: 1
117
+ # Cop supports --auto-correct.
118
+ # Configuration parameters: EnforcedStyle.
119
+ # SupportedStyles: use_perl_names, use_english_names
120
+ Style/SpecialGlobalVars:
121
+ Exclude:
122
+ - 'ransack_ui.gemspec'
123
+
124
+ # Offense count: 43
125
+ # Cop supports --auto-correct.
126
+ # Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
127
+ # URISchemes: http, https
128
+ Metrics/LineLength:
129
+ Max: 144
data/CHANGELOG.md ADDED
@@ -0,0 +1,20 @@
1
+ # Change Log
2
+
3
+ ## v2.0.0
4
+
5
+ ### 💥 Breaking Changes
6
+
7
+ * Bumped minimum supported version of Select2 from V3 to V4 (Note: Select2 usage is entirely optional.)
8
+ * Changed Ransack dependency requirement from ~> 2.0 to Ransack < 4
9
+
10
+ ### 🚀 Features
11
+
12
+ * Moved project ownership from github.com:ndbroadbent/ransack_ui.git to github.com:fatfreecrm/ransack_ui.git
13
+
14
+ ### 🐛 Bug Fixes
15
+
16
+ * Fixed html issue with "Add a filter" rendering
17
+
18
+ ### 📝 Documentation
19
+
20
+ * Added CHANGELOG.md
data/Gemfile CHANGED
@@ -1,7 +1,8 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  # Include rake in Gemfile so that `bundle exec rake` doesn't raise an error
4
- gem 'rake', :group => :test
4
+ gem 'rake', group: :test
5
+ gem 'rubocop', '~> 0.76.0'
5
6
 
6
7
  # Specify your gem's dependencies in ransack_ui.gemspec
7
8
  gemspec
data/README.md CHANGED
@@ -3,8 +3,6 @@
3
3
  Provides HTML templates and JavaScript to build a fully functional
4
4
  advanced search form using Ransack.
5
5
 
6
- Please note: this project is still in *alpha* and the following instructions are not yet complete/fully working.
7
-
8
6
  ## Installation
9
7
 
10
8
  Add this line to your application's Gemfile:
@@ -50,8 +48,9 @@ Now you can start playing with the results.
50
48
  4. Push to the branch (`git push origin my-new-feature`)
51
49
  5. Create new Pull Request
52
50
 
53
- ## Credits / Acknowledgements
51
+ ## Acknowledgements
54
52
 
55
- * Nathan Broadbent (ndbroadbent) - creator of ransack_ui code
56
- * Ernie Miller (ernie) for creating ransack - https://github.com/ernie/ransack
57
- * Steve Kenworthy (steveyken) - for tiny tweaks
53
+ * Ernie Miller (@ernie) - Creator of ransack (https://github.com/ernie/ransack)
54
+ * Nathan Broadbent (@ndbroadbent)
55
+ * Steve Kenworthy (@steveyken)
56
+ * Daniel O'Connor (@CloCkWeRX)
data/Rakefile CHANGED
@@ -1 +1 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler/gem_tasks'
@@ -37,5 +37,5 @@ Ransack.predicate_inputs = {}
37
37
  Ransack.option_predicates = ['eq', 'eq_any', 'not_eq', 'not_eq_all', 'null', 'not_null']
38
38
 
39
39
  # Use a tags input for 'in' if Select2 is available
40
- if Select2?
40
+ if $.fn.select2?
41
41
  Ransack.predicate_inputs.in = 'tags'
@@ -12,7 +12,7 @@
12
12
 
13
13
  # Store initial predicates and set up Select2 on select lists in .filters
14
14
  containers = el.find('.filters')
15
- if Select2?
15
+ if $.fn.select2?
16
16
  @init_select2(containers)
17
17
  @store_initial_predicates(containers)
18
18
 
@@ -59,17 +59,17 @@
59
59
  @destroy_multi_input(multi_input, selected_attribute.val())
60
60
 
61
61
  # Handle association columns with AJAX autocomplete
62
- if selected_attribute.data('ajax-url') and Select2?
62
+ if selected_attribute.data('ajax--url') and $.fn.select2?
63
63
  @set_option_predicates(base_id, available, column_type)
64
64
 
65
65
  # Handle columns with options detected from validates :inclusion
66
- else if selected_attribute.data('select-options') and Select2?
66
+ else if selected_attribute.data('select-options') and $.fn.select2?
67
67
  @set_option_predicates(base_id, available, column_type, true)
68
68
 
69
69
  # Handle regular columns
70
70
  else
71
- if Select2?
72
- predicate_select2.select2("enable")
71
+ if $.fn.select2?
72
+ predicate_select2.prop('disabled', false)
73
73
 
74
74
  # If Select2 is on query input, remove and set defaults
75
75
  if query_select2.length > 0
@@ -102,11 +102,11 @@
102
102
  predicate_select.append $("<option value=#{predicate}>#{label}</option>")
103
103
 
104
104
  # Select first predicate if current selection is invalid
105
- if Select2?
106
- predicate_select.select2('val', previous_val)
105
+ if $.fn.select2?
106
+ predicate_select.val(previous_val)
107
107
 
108
108
  # Run predicate_changed callback
109
- predicate_select.change()
109
+ predicate_select.trigger('change')
110
110
 
111
111
  return true
112
112
 
@@ -138,14 +138,14 @@
138
138
  # Hide query input when not needed
139
139
  if p in no_query_predicates
140
140
  # If Select2 is on query input, remove and set defaults
141
- if Select2? && query_select2.length
141
+ if $.fn.select2? && query_select2.length
142
142
  query_input.select2('destroy')
143
143
 
144
144
  query_input.val("true")
145
145
  query_input.hide()
146
146
  query_input.parent().find('.ui-datepicker-trigger').hide()
147
147
 
148
- if Select2?
148
+ if $.fn.select2?
149
149
  # Turn query input into Select2 tag list when query accepts multiple values
150
150
  if p in ["in", "not_in"] || p.match(/_(all|any)$/)
151
151
  # Add dummy 'multi' input for select2 if not already added
@@ -175,7 +175,7 @@
175
175
  query_input.css('display', '')
176
176
 
177
177
  # Handle association columns with AJAX autocomplete
178
- if selected_attribute.data('ajax-url')
178
+ if selected_attribute.data('ajax--url')
179
179
  if query_select2.length
180
180
  query_input.hide()
181
181
  else
@@ -193,7 +193,7 @@
193
193
  return if selected_attribute.data('select-options')
194
194
 
195
195
  # Don't show query input if ajax auto complete is present on selected attribute
196
- unless p in ['eq', 'not_eq'] and selected_attribute.data('ajax-url')
196
+ unless p in ['eq', 'not_eq'] and selected_attribute.data('ajax--url')
197
197
  unless query_input.is(":visible")
198
198
  query_input.val('')
199
199
  #query_input.show()
@@ -226,7 +226,7 @@
226
226
  predicate_select.append $("<option value=#{predicate}>#{label}</option>")
227
227
 
228
228
  # Select first predicate if current selection is invalid
229
- predicate_select.select2('val', previous_val)
229
+ predicate_select.val(previous_val)
230
230
 
231
231
  # Attempts to find a predicate translation for the specific column type,
232
232
  # or returns the default label.
@@ -288,12 +288,12 @@
288
288
  # Hide all query inputs
289
289
  inputs.hide()
290
290
 
291
- if Select2?
291
+ if $.fn.select2?
292
292
  # Find newly created input and setup Select2
293
293
  multi_query = @element.find('#' + multi_id)
294
294
 
295
295
  # Handle association columns with AJAX autocomplete
296
- if selected_attribute.data('ajax-url')
296
+ if selected_attribute.data('ajax--url')
297
297
  # Set label to single association label, if anything was selected
298
298
  if query_select2.length && query_input.select2('data')
299
299
  query_input_data = query_input.select2('data')
@@ -310,30 +310,31 @@
310
310
  else
311
311
  # Setup Select2 with tagging support (can create options)
312
312
  multi_query.select2
313
- tags: []
313
+ data: [], tags: true
314
314
  tokenSeparators: [',']
315
- formatNoMatches: (t) ->
316
- "Add a search term"
315
+ language:
316
+ noMatches: (t) ->
317
+ "Add a search term"
317
318
 
318
- multi_query.select2('val', values)
319
+ multi_query.val(values)
319
320
 
320
321
  setup_select2_association: (query_input, selected_attribute, multiple = false) ->
321
322
  selected_attribute_val = selected_attribute.val()
322
323
  # Set up Select2 for query input
323
324
  query_input.select2
324
- placeholder: "Search #{selected_attribute.data('ajax-entity')}"
325
+ placeholder: "Search #{selected_attribute.data('ajax--entity')}"
325
326
  minimumInputLength: 1
326
327
  allowClear: true
327
328
  multiple: multiple
328
329
  ajax:
329
- url: selected_attribute.data('ajax-url')
330
+ url: selected_attribute.data('ajax--url')
330
331
  dataType: 'json'
331
- type: selected_attribute.data('ajax-type')
332
- data: (query, page) ->
332
+ type: selected_attribute.data('ajax--type')
333
+ data: (params) ->
333
334
  obj = {}
334
- obj[selected_attribute.data('ajax-key')] = query
335
+ obj[selected_attribute.data('ajax--key')] = params
335
336
  obj
336
- results: (data, page) ->
337
+ processResults: (data) ->
337
338
  {results: $.map(data, (text, id) -> {id: id, text: text}) }
338
339
  initSelection: (element, callback) ->
339
340
  data = []
@@ -348,7 +349,7 @@
348
349
  callback(multiple and data or data[0])
349
350
  else
350
351
  # If no label could be found, clear value
351
- element.select2('val', '')
352
+ element.val('')
352
353
 
353
354
  setup_select2_options: (query_input, selected_attribute, multiple = false) ->
354
355
  query_input.select2
@@ -374,7 +375,7 @@
374
375
  if data.length
375
376
  callback(multiple and data or data[0])
376
377
  else
377
- element.select2('val', '')
378
+ element.val('')
378
379
 
379
380
  add_query_input: (base_input, base_name, id, value) ->
380
381
  base_input.after $('<input name="'+base_name+'['+id+'][value]" '+
@@ -401,7 +402,7 @@
401
402
  target.before content.replace(regexp, new_id)
402
403
  prev_container = target.prev()
403
404
 
404
- if Select2?
405
+ if $.fn.select2?
405
406
  @init_select2(prev_container)
406
407
 
407
408
  if $.ransack.button_group_select?
@@ -409,7 +410,7 @@
409
410
 
410
411
  @store_initial_predicates(prev_container)
411
412
  # Fire change event on any new selects.
412
- prev_container.find("select").change()
413
+ prev_container.find("select").trigger('change')
413
414
  false
414
415
 
415
416
  remove_fields: (e) ->
@@ -441,11 +442,11 @@
441
442
  width: '230px'
442
443
  placeholder: "Select a Field"
443
444
  allowClear: true
444
- formatSelection: (object, container) ->
445
+ templateSelection: (object) ->
445
446
  # If initializing and element is not present,
446
447
  # search for option element in original select tag
447
448
  if !object.element
448
- this.element.find('option').each (i, option) ->
449
+ container.find('select option').each (i, option) ->
449
450
  if option.value == object.id
450
451
  object.element = option
451
452
  return false
@@ -3,13 +3,13 @@
3
3
 
4
4
  <%= f.attribute_fields do |a| %>
5
5
  <span class="fields" data-object-name="<%= f.object_name %>">
6
- <%= a.attribute_select({}, :class => 'ransack_attribute') %>
6
+ <%= a.attribute_select({}, class: 'ransack_attribute') %>
7
7
  <% end %>
8
8
 
9
- <%= f.predicate_select({}, :class => 'ransack_predicate') %>
9
+ <%= f.predicate_select({}, class: 'ransack_predicate') %>
10
10
 
11
11
  <%= f.value_fields do |v| %>
12
12
  <span class="fields value" data-object-name="<%= f.object_name %>">
13
- <%= v.text_field :value, :style => "width: 200px;", :class => "ransack_query" %>
13
+ <%= v.text_field :value, style: "width: 200px;", class: "ransack_query" %>
14
14
  <% end %>
15
15
  </div>
@@ -2,7 +2,6 @@ module RansackUI
2
2
  module Adapters
3
3
  module ActiveRecord
4
4
  module Base
5
-
6
5
  def self.extended(base)
7
6
  base.class_eval do
8
7
  class_attribute :_ransackable_associations
@@ -23,12 +22,12 @@ module RansackUI
23
22
  # Return array of attributes with [name, type]
24
23
  # (Default to :string type for ransackers)
25
24
  def ransackable_attributes(auth_object = nil)
26
- columns.map{|c| [c.name, c.type] } +
27
- _ransackers.keys.map {|k,v| [k, v.type || :string] }
25
+ columns.map { |c| [c.name, c.type] } +
26
+ _ransackers.keys.map { |k, v| [k, v.type || :string] }
28
27
  end
29
28
 
30
29
  def ransackable_associations(auth_object = nil)
31
- all_associations = reflect_on_all_associations.map {|a| a.name.to_s}
30
+ all_associations = reflect_on_all_associations.map { |a| a.name.to_s }
32
31
  if self._ransackable_associations.any?
33
32
  # Return intersection of all associations, and associations defined on the model
34
33
  all_associations & self._ransackable_associations
@@ -10,7 +10,7 @@ module RansackUI
10
10
  #
11
11
  def load_ransack_search(klass = nil)
12
12
  klass ||= controller_path.classify.constantize
13
- @ransack_search = klass.search(params[:q])
13
+ @ransack_search = klass.ransack(params[:q])
14
14
  @ransack_search.build_grouping if @ransack_search.groupings.empty?
15
15
  @ransack_search
16
16
  end
@@ -4,17 +4,17 @@ require 'ransack_ui/controller_helpers'
4
4
  module RansackUI
5
5
  module Rails
6
6
  class Engine < ::Rails::Engine
7
- initializer "ransack_ui.view_helpers" do
8
- ActionView::Base.send :include, ViewHelpers
7
+ initializer 'ransack_ui.view_helpers' do
8
+ ActionView::Base.include ViewHelpers
9
9
  end
10
10
 
11
- initializer "ransack_ui.controller_helpers" do
12
- ActionController::Base.send :include, ControllerHelpers
11
+ initializer 'ransack_ui.controller_helpers' do
12
+ ActionController::Base.include ControllerHelpers
13
13
  end
14
14
 
15
15
  config.before_configuration do
16
16
  # Add images to be precompiled
17
- ::Rails.application.config.assets.precompile += %w(ransack_ui/delete.png ransack_ui/calendar.png)
17
+ ::Rails.application.config.assets.precompile += %w[ransack_ui/delete.png ransack_ui/calendar.png]
18
18
  end
19
19
  end
20
20
  end
@@ -7,12 +7,12 @@ module Ransack
7
7
  # Return array of attributes with [name, type]
8
8
  # (Default to :string type for ransackers)
9
9
  def ransackable_attributes(auth_object = nil)
10
- columns.map{|c| [c.name, c.type] } +
11
- _ransackers.map {|k,v| [k, v.type || :string] }
10
+ columns.map { |c| [c.name, c.type] } +
11
+ _ransackers.map { |k, v| [k, v.type || :string] }
12
12
  end
13
13
 
14
14
  def self.extended(base)
15
- alias :search :ransack unless base.method_defined? :search
15
+ alias_method :search, :ransack unless base.method_defined? :search
16
16
  base.class_eval do
17
17
  class_attribute :_ransackers
18
18
  class_attribute :_ransackable_associations
@@ -32,7 +32,7 @@ module Ransack
32
32
  end
33
33
 
34
34
  def ransackable_associations(auth_object = nil)
35
- all_associations = reflect_on_all_associations.map {|a| a.name.to_s}
35
+ all_associations = reflect_on_all_associations.map { |a| a.name.to_s }
36
36
  if self._ransackable_associations.any?
37
37
  # Return intersection of all associations, and associations defined on the model
38
38
  all_associations & self._ransackable_associations
@@ -40,7 +40,6 @@ module Ransack
40
40
  all_associations
41
41
  end
42
42
  end
43
-
44
43
  end
45
44
  end
46
45
  end
@@ -12,4 +12,4 @@ module Ransack
12
12
  self.options[:ajax_options] = options
13
13
  end
14
14
  end
15
- end
15
+ end
@@ -6,4 +6,4 @@ module Ransack
6
6
  klass.ransackable_attributes(auth_object).map(&:first).include? str
7
7
  end
8
8
  end
9
- end
9
+ end
@@ -7,13 +7,12 @@ module Ransack
7
7
  self.cached_searchable_attributes_for_base = {}
8
8
 
9
9
  def attribute_select(options = {}, html_options = {})
10
- raise ArgumentError, "attribute_select must be called inside a search FormBuilder!" unless object.respond_to?(:context)
11
- options[:include_blank] = true unless options.has_key?(:include_blank)
10
+ raise ArgumentError, 'attribute_select must be called inside a search FormBuilder!' unless object.respond_to?(:context)
11
+
12
+ options[:include_blank] = true unless options.key?(:include_blank)
12
13
 
13
14
  # Set default associations set on model with 'has_ransackable_associations'
14
- if options[:associations].nil?
15
- options[:associations] = object.context.klass.ransackable_associations
16
- end
15
+ options[:associations] = object.context.klass.ransackable_associations if options[:associations].nil?
17
16
 
18
17
  bases = [''] + association_array(options[:associations])
19
18
  if bases.size > 1
@@ -31,32 +30,33 @@ module Ransack
31
30
  end
32
31
 
33
32
  def sort_select(options = {}, html_options = {})
34
- raise ArgumentError, "sort_select must be called inside a search FormBuilder!" unless object.respond_to?(:context)
35
- options[:include_blank] = true unless options.has_key?(:include_blank)
33
+ raise ArgumentError, 'sort_select must be called inside a search FormBuilder!' unless object.respond_to?(:context)
34
+
35
+ options[:include_blank] = true unless options.key?(:include_blank)
36
36
  bases = [''] + association_array(options[:associations])
37
37
  if bases.size > 1
38
38
  @template.select(
39
39
  @object_name, :name,
40
40
  @template.grouped_options_for_select(attribute_collection_for_bases(bases), object.name),
41
- objectify_options(options), @default_options.merge({:class => 'ransack_sort'}).merge(html_options)
41
+ objectify_options(options), @default_options.merge(class: 'ransack_sort').merge(html_options)
42
42
  ) + @template.collection_select(
43
43
  @object_name, :dir, [['asc', object.translate('asc')], ['desc', object.translate('desc')]], :first, :last,
44
- objectify_options(options.except(:include_blank)), @default_options.merge({:class => 'ransack_sort_order'}).merge(html_options)
44
+ objectify_options(options.except(:include_blank)), @default_options.merge(class: 'ransack_sort_order').merge(html_options)
45
45
  )
46
46
  else
47
47
  # searchable_attributes now returns [c, type]
48
- collection = object.context.searchable_attributes(bases.first).map do |c, type|
48
+ collection = object.context.searchable_attributes(bases.first).map do |c, _type|
49
49
  [
50
50
  attr_from_base_and_column(bases.first, c),
51
- Translate.attribute(attr_from_base_and_column(bases.first, c), :context => object.context)
51
+ Translate.attribute(attr_from_base_and_column(bases.first, c), context: object.context)
52
52
  ]
53
53
  end
54
54
  @template.collection_select(
55
55
  @object_name, :name, collection, :first, :last,
56
- objectify_options(options), @default_options.merge({:class => 'ransack_sort'}).merge(html_options)
56
+ objectify_options(options), @default_options.merge(class: 'ransack_sort').merge(html_options)
57
57
  ) + @template.collection_select(
58
58
  @object_name, :dir, [['asc', object.translate('asc')], ['desc', object.translate('desc')]], :first, :last,
59
- objectify_options(options.except(:include_blank)), @default_options.merge({:class => 'ransack_sort_order'}).merge(html_options)
59
+ objectify_options(options.except(:include_blank)), @default_options.merge(class: 'ransack_sort_order').merge(html_options)
60
60
  )
61
61
  end
62
62
  end
@@ -69,27 +69,27 @@ module Ransack
69
69
  condition.values.each do |value|
70
70
  # If value is present, and the attribute is an association,
71
71
  # load the selected record and include the record name as a data attribute
72
- if value.value.present?
73
- condition_attributes = condition.attributes
74
- if condition_attributes.any?
75
- attribute = condition_attributes.first.name
76
- klass_name = foreign_klass_for_attribute(attribute)
77
-
78
- if klass_name
79
- klass = klass_name.constantize
80
-
81
- value_object = klass.find_by_id(value.value)
82
- if value_object
83
- labels[attribute] ||= {}
84
-
85
- if value_object.respond_to? :full_name
86
- labels[attribute][value.value] = value_object.full_name
87
- elsif value_object.respond_to? :name
88
- labels[attribute][value.value] = value_object.name
89
- end
90
- end
91
- end
92
- end
72
+ next unless value.value.present?
73
+
74
+ condition_attributes = condition.attributes
75
+ next unless condition_attributes.any?
76
+
77
+ attribute = condition_attributes.first.name
78
+ klass_name = foreign_klass_for_attribute(attribute)
79
+
80
+ next unless klass_name
81
+
82
+ klass = klass_name.constantize
83
+
84
+ value_object = klass.find_by_id(value.value)
85
+ next unless value_object
86
+
87
+ labels[attribute] ||= {}
88
+
89
+ if value_object.respond_to? :full_name
90
+ labels[attribute][value.value] = value_object.full_name
91
+ elsif value_object.respond_to? :name
92
+ labels[attribute][value.value] = value_object.name
93
93
  end
94
94
  end
95
95
  end
@@ -98,18 +98,17 @@ module Ransack
98
98
  labels
99
99
  end
100
100
 
101
-
102
101
  def predicate_keys(options)
103
- keys = options[:compounds] ? Predicate.names : Predicate.names.reject {|k| k.match(/_(any|all)$/)}
104
- if only = options[:only]
102
+ keys = options[:compounds] ? Predicate.names : Predicate.names.reject { |k| k.match(/_(any|all)$/) }
103
+ if (only = options[:only])
105
104
  if only.respond_to? :call
106
- keys = keys.select {|k| only.call(k)}
105
+ keys = keys.select { |k| only.call(k) }
107
106
  else
108
107
  only = Array.wrap(only).map(&:to_s)
109
108
  # Create compounds hash, e.g. {"eq" => ["eq", "eq_any", "eq_all"], "blank" => ["blank"]}
110
- key_groups = keys.inject(Hash.new([])){ |h,k| h[k.sub(/_(any|all)$/, '')] += [k]; h }
109
+ key_groups = keys.inject(Hash.new([])) { |h, k| h[k.sub(/_(any|all)$/, '')] += [k]; h }
111
110
  # Order compounds hash by 'only' keys
112
- keys = only.map {|k| key_groups[k] }.flatten.compact
111
+ keys = only.map { |k| key_groups[k] }.flatten.compact
113
112
  end
114
113
  end
115
114
  keys
@@ -124,19 +123,19 @@ module Ransack
124
123
  # then replace the default predicate with the first in the ordered list
125
124
  @object.predicate_name = keys.first if @object.default?
126
125
  @template.collection_select(
127
- @object_name, :p, keys.map {|k| [k, Translate.predicate(k)]}, :first, :last,
126
+ @object_name, :p, keys.map { |k| [k, Translate.predicate(k)] }, :first, :last,
128
127
  objectify_options(options), @default_options.merge(html_options)
129
128
  )
130
129
  end
131
130
 
132
131
  def attribute_collection_for_bases(bases)
133
132
  bases.map do |base|
134
- if collection = attribute_collection_for_base(base)
135
- [
136
- Translate.association(base, :context => object.context),
137
- collection
138
- ]
139
- end
133
+ next unless (collection = attribute_collection_for_base(base))
134
+
135
+ [
136
+ Translate.association(base, context: object.context),
137
+ collection
138
+ ]
140
139
  end.compact
141
140
  end
142
141
 
@@ -146,21 +145,19 @@ module Ransack
146
145
 
147
146
  # Detect any inclusion validators to build list of options for a column
148
147
  column_select_options = klass.validators.each_with_object({}) do |v, hash|
149
- if v.is_a? ActiveModel::Validations::InclusionValidator
150
- v.attributes.each do |a|
151
- # Try to translate options from activerecord.attribute_options.<model>.<attribute>
152
- inclusions = v.send(:delimiter)
153
- inclusions = inclusions.call if inclusions.respond_to?(:call) # handle lambda
154
- hash[a.to_s] = inclusions.each_with_object({}) do |o, options|
155
- options[o.to_s] = I18n.translate("activerecord.attribute_options.#{klass.to_s.downcase}.#{a}.#{o}", :default => o.to_s.titleize)
156
- end
148
+ next unless v.is_a? ActiveModel::Validations::InclusionValidator
149
+
150
+ v.attributes.each do |a|
151
+ # Try to translate options from activerecord.attribute_options.<model>.<attribute>
152
+ inclusions = v.send(:delimiter)
153
+ inclusions = inclusions.call if inclusions.respond_to?(:call) # handle lambda
154
+ hash[a.to_s] = inclusions.each_with_object({}) do |o, options|
155
+ options[o.to_s] = I18n.translate("activerecord.attribute_options.#{klass.to_s.downcase}.#{a}.#{o}", default: o.to_s.titleize)
157
156
  end
158
157
  end
159
158
  end
160
159
 
161
- if klass.respond_to?(:ransack_column_select_options)
162
- column_select_options.merge!(klass.ransack_column_select_options)
163
- end
160
+ column_select_options.merge!(klass.ransack_column_select_options) if klass.respond_to?(:ransack_column_select_options)
164
161
 
165
162
  searchable_attributes_for_base(base).map do |attribute_data|
166
163
  column = attribute_data[:column]
@@ -175,24 +172,24 @@ module Ransack
175
172
  # Set column options if detected from inclusion validator
176
173
  if column_select_options[column]
177
174
  # Format options as an array of hashes with id and text columns, for Select2
178
- html_options[:'data-select-options'] = column_select_options[column].map {|id, text|
179
- {:id => id, :text => text}
180
- }.to_json
175
+ html_options[:'data-select-options'] = column_select_options[column].map do |id, text|
176
+ { id: id, text: text }
177
+ end.to_json
181
178
  end
182
179
 
183
180
  foreign_klass = attribute_data[:foreign_klass]
184
181
 
185
182
  if foreign_klass
186
- # If field is a foreign key, set up 'data-ajax-*' attributes for auto-complete
187
- controller = ActiveSupport::Inflector::tableize(foreign_klass.to_s)
188
- html_options[:'data-ajax-entity'] = I18n.translate(controller, :default => controller)
183
+ # If field is a foreign key, set up 'data-ajax--*' attributes for auto-complete
184
+ controller = ActiveSupport::Inflector.tableize(foreign_klass.to_s)
185
+ html_options[:'data-ajax--entity'] = I18n.translate(controller, default: controller)
189
186
  if ajax_options[:url]
190
- html_options[:'data-ajax-url'] = ajax_options[:url].sub(':controller', controller)
187
+ html_options[:'data-ajax--url'] = ajax_options[:url].sub(':controller', controller)
191
188
  else
192
- html_options[:'data-ajax-url'] = "/#{controller}.json"
189
+ html_options[:'data-ajax--url'] = "/#{controller}.json"
193
190
  end
194
- html_options[:'data-ajax-type'] = ajax_options[:type] || 'GET'
195
- html_options[:'data-ajax-key'] = ajax_options[:key] || 'query'
191
+ html_options[:'data-ajax--type'] = ajax_options[:type] || 'GET'
192
+ html_options[:'data-ajax--key'] = ajax_options[:key] || 'query'
196
193
  end
197
194
 
198
195
  [
@@ -201,11 +198,10 @@ module Ransack
201
198
  html_options
202
199
  ]
203
200
  end
204
- rescue UntraversableAssociationError => e
201
+ rescue UntraversableAssociationError
205
202
  nil
206
203
  end
207
204
 
208
-
209
205
  private
210
206
 
211
207
  def searchable_attributes_for_base(base)
@@ -214,22 +210,22 @@ module Ransack
214
210
 
215
211
  self.class.cached_searchable_attributes_for_base[cache_key] ||= object.context.searchable_attributes(base).map do |column, type|
216
212
  klass = object.context.traverse(base)
217
- foreign_keys = klass.reflect_on_all_associations.select(&:belongs_to?).
218
- each_with_object({}) {|r, h| h[r.foreign_key.to_sym] = r.class_name }
213
+ foreign_keys = klass.reflect_on_all_associations.select(&:belongs_to?)
214
+ .each_with_object({}) { |r, h| h[r.foreign_key.to_sym] = r.class_name }
219
215
 
220
216
  # Don't show 'id' column for base model
221
217
  next nil if base.blank? && column == 'id'
222
218
 
223
219
  attribute = attr_from_base_and_column(base, column)
224
- attribute_label = Translate.attribute(attribute, :context => object.context)
220
+ attribute_label = Translate.attribute(attribute, context: object.context)
225
221
 
226
222
  # Set model name as label for 'id' column on that model's table.
227
223
  if column == 'id'
228
224
  foreign_klass = object.context.traverse(base).model_name
229
225
  # Check that model can autocomplete. If not, skip this id column.
230
- next nil unless ActiveSupport::Inflector::constantize(foreign_klass.to_s)._ransack_can_autocomplete
226
+ next nil unless ActiveSupport::Inflector.constantize(foreign_klass.to_s)._ransack_can_autocomplete
231
227
 
232
- attribute_label = I18n.translate(foreign_klass, :default => foreign_klass)
228
+ attribute_label = I18n.translate(foreign_klass, default: foreign_klass)
233
229
  else
234
230
  foreign_klass = foreign_keys[column.to_sym]
235
231
  end
@@ -251,9 +247,7 @@ module Ransack
251
247
 
252
248
  bases.each do |base|
253
249
  searchable_attributes_for_base(base).each do |attribute_data|
254
- if attribute == attribute_data[:attribute]
255
- return attribute_data[:foreign_klass]
256
- end
250
+ return attribute_data[:foreign_klass] if attribute == attribute_data[:attribute]
257
251
  end
258
252
  end
259
253
  end
@@ -5,8 +5,8 @@ module Ransack
5
5
  Attribute.class_eval do
6
6
  def valid?
7
7
  bound? && attr &&
8
- context.klassify(parent).ransackable_attributes(context.auth_object)
9
- .map(&:first).include?(attr_name)
8
+ context.klassify(parent).ransackable_attributes(context.auth_object)
9
+ .map(&:first).include?(attr_name)
10
10
  end
11
11
  end
12
12
  end
@@ -10,4 +10,4 @@ module Ransack
10
10
  end
11
11
  end
12
12
  end
13
- end
13
+ end
@@ -3,7 +3,6 @@ require 'ransack/nodes/grouping'
3
3
  module Ransack
4
4
  module Nodes
5
5
  Grouping.class_eval do
6
-
7
6
  def new_condition(opts = {})
8
7
  attrs = opts[:attributes] || 1
9
8
  vals = opts[:values] || 1
@@ -14,7 +13,6 @@ module Ransack
14
13
  vals.times { condition.build_value }
15
14
  condition
16
15
  end
17
-
18
16
  end
19
17
  end
20
- end
18
+ end
@@ -1,3 +1,3 @@
1
1
  module RansackUI
2
- VERSION = "1.3.4"
2
+ VERSION = '2.0.0'.freeze
3
3
  end
@@ -1,29 +1,29 @@
1
1
  module RansackUI
2
2
  module ViewHelpers
3
3
  def ransack_ui_search(options = {})
4
- render 'ransack_ui/search', :options => options
4
+ render 'ransack_ui/search', options: options
5
5
  end
6
6
 
7
7
  def link_to_add_fields(name, f, type, options)
8
8
  new_object = f.object.send "build_#{type}"
9
- fields = f.send("#{type}_fields", new_object, :child_index => "new_#{type}") do |builder|
10
- render "ransack_ui/#{type.to_s}_fields", :f => builder, :options => options
9
+ fields = f.send("#{type}_fields", new_object, child_index: "new_#{type}") do |builder|
10
+ render "ransack_ui/#{type}_fields", f: builder, options: options
11
11
  end
12
12
 
13
13
  if options[:theme].to_s == 'bootstrap'
14
- link_to nil, :class => "add_fields btn btn-small btn-primary", "data-field-type" => type, "data-content" => "#{fields}" do
14
+ link_to nil, :class => 'add_fields btn btn-small btn-primary', 'data-field-type' => type, 'data-content' => "#{fields}" do
15
15
  "<i class=\"icon-plus icon-white\"></i><span>#{name}</span>".html_safe
16
16
  end
17
17
  else
18
- link_to name, nil, :class => "add_fields", "data-field-type" => type, "data-content" => "#{fields}"
18
+ link_to name, nil, :class => 'add_fields', 'data-field-type' => type, 'data-content' => "#{fields}"
19
19
  end
20
20
  end
21
21
 
22
22
  def link_to_remove_fields(name, f, options)
23
23
  if options[:theme].to_s == 'bootstrap'
24
- link_to '<i class="icon-remove icon-white"></i>'.html_safe, nil, :class => "remove_fields btn btn-mini btn-danger"
24
+ link_to '<i class="icon-remove icon-white"></i>'.html_safe, nil, class: 'remove_fields btn btn-mini btn-danger'
25
25
  else
26
- link_to image_tag('ransack_ui/delete.png', :size => '16x16', :alt => name), nil, :class => "remove_fields"
26
+ link_to image_tag('ransack_ui/delete.png', size: '16x16', alt: name), nil, class: 'remove_fields'
27
27
  end
28
28
  end
29
29
  end
data/lib/ransack_ui.rb CHANGED
@@ -1,9 +1,9 @@
1
- require "ransack_ui/version"
2
- require "ransack_ui/rails/engine"
3
- require "ransack_chronic"
1
+ require 'ransack_ui/version'
2
+ require 'ransack_ui/rails/engine'
3
+ require 'ransack_chronic'
4
4
 
5
5
  # Require ransack overrides
6
6
  require 'ransack_ui/adapters/active_record'
7
- Dir.glob(File.expand_path('../ransack_ui/ransack_overrides/**/*.rb', __FILE__)) {|f| require f }
7
+ Dir.glob(File.expand_path('ransack_ui/ransack_overrides/**/*.rb', __dir__)) { |f| require f }
8
8
 
9
- require "ransack"
9
+ require 'ransack'
data/ransack_ui.gemspec CHANGED
@@ -1,23 +1,22 @@
1
- # -*- encoding: utf-8 -*-
2
- lib = File.expand_path('../lib', __FILE__)
1
+ lib = File.expand_path('lib', __dir__)
3
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
3
  require 'ransack_ui/version'
5
4
 
6
5
  Gem::Specification.new do |gem|
7
- gem.name = "ransack_ui"
6
+ gem.name = 'ransack_ui'
8
7
  gem.version = RansackUI::VERSION
9
- gem.authors = ["Nathan Broadbent"]
10
- gem.email = ["nathan.f77@gmail.com"]
11
- gem.description = "Framework for building a search UI with Ransack"
12
- gem.summary = "UI Builder for Ransack"
13
- gem.homepage = "https://github.com/ndbroadbent/ransack_ui"
14
- gem.license = "MIT"
8
+ gem.authors = ['Nathan Broadbent']
9
+ gem.email = ['nathan.f77@gmail.com']
10
+ gem.description = 'Framework for building a search UI with Ransack'
11
+ gem.summary = 'UI Builder for Ransack'
12
+ gem.homepage = 'https://github.com/ndbroadbent/ransack_ui'
13
+ gem.license = 'MIT'
15
14
 
16
15
  gem.files = `git ls-files`.split($/)
17
- gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
16
+ gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
18
17
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
- gem.require_paths = ["lib"]
18
+ gem.require_paths = ['lib']
20
19
 
21
20
  gem.add_dependency 'ransack_chronic', '>= 1.1.0'
22
- gem.add_dependency 'ransack'
21
+ gem.add_dependency 'ransack', '< 4'
23
22
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ransack_ui
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.4
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Broadbent
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-02 00:00:00.000000000 Z
11
+ date: 2024-08-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ransack_chronic
@@ -28,16 +28,16 @@ dependencies:
28
28
  name: ransack
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "<"
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: '4'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - "<"
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: '4'
41
41
  description: Framework for building a search UI with Ransack
42
42
  email:
43
43
  - nathan.f77@gmail.com
@@ -46,6 +46,8 @@ extensions: []
46
46
  extra_rdoc_files: []
47
47
  files:
48
48
  - ".gitignore"
49
+ - ".rubocop_todo.yml"
50
+ - CHANGELOG.md
49
51
  - Gemfile
50
52
  - LICENSE.txt
51
53
  - README.md
@@ -83,7 +85,7 @@ homepage: https://github.com/ndbroadbent/ransack_ui
83
85
  licenses:
84
86
  - MIT
85
87
  metadata: {}
86
- post_install_message:
88
+ post_install_message:
87
89
  rdoc_options: []
88
90
  require_paths:
89
91
  - lib
@@ -98,9 +100,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
98
100
  - !ruby/object:Gem::Version
99
101
  version: '0'
100
102
  requirements: []
101
- rubyforge_project:
102
- rubygems_version: 2.4.3
103
- signing_key:
103
+ rubygems_version: 3.5.9
104
+ signing_key:
104
105
  specification_version: 4
105
106
  summary: UI Builder for Ransack
106
107
  test_files: []