Skip to content

Commit 157cc95

Browse files
committed
Coding style
1 parent 7373848 commit 157cc95

File tree

5 files changed

+22
-16
lines changed

5 files changed

+22
-16
lines changed

.rubocop.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
AllCops:
22
TargetRubyVersion: 2.5
33
Exclude:
4+
- gemfiles/*
45
- spec/**/*.rb
56
- lib/ajax-datatables-rails.rb
67
- lib/generators/rails/templates/*.rb

ajax-datatables-rails.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# frozen_string_literal: true
22

3-
$LOAD_PATH.push File.expand_path('../lib', __FILE__)
3+
$LOAD_PATH.push File.expand_path('lib', __dir__)
44
require 'ajax-datatables-rails/version'
55

66
Gem::Specification.new do |s|

lib/ajax-datatables-rails/base.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ def additional_data
3232

3333
def as_json(*)
3434
{
35-
recordsTotal: records_total_count,
35+
recordsTotal: records_total_count,
3636
recordsFiltered: records_filtered_count,
37-
data: sanitize(data)
37+
data: sanitize(data)
3838
}.merge(get_additional_data)
3939
end
4040

lib/ajax-datatables-rails/datatable/column/search.rb

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ module Datatable
55
class Column
66
module Search
77

8-
SMALLEST_PQ_INTEGER = -2147483648
9-
LARGEST_PQ_INTEGER = 2147483647
8+
SMALLEST_PQ_INTEGER = -2_147_483_648
9+
LARGEST_PQ_INTEGER = 2_147_483_647
1010
NOT_NULL_VALUE = '!NULL'
1111
EMPTY_VALUE = ''
1212

@@ -54,12 +54,13 @@ def regex_search
5454
end
5555
end
5656

57+
# rubocop:disable Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity
5758
def non_regex_search
5859
case cond
5960
when Proc
6061
filter
6162
when :eq, :not_eq, :lt, :gt, :lteq, :gteq, :in
62-
is_searchable_integer? ? raw_search(cond) : empty_search
63+
searchable_integer? ? raw_search(cond) : empty_search
6364
when :null_value
6465
null_value_search
6566
when :start_with
@@ -74,6 +75,7 @@ def non_regex_search
7475
date_range_search
7576
end
7677
end
78+
# rubocop:enable Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity
7779

7880
def null_value_search
7981
if formatted_value == NOT_NULL_VALUE
@@ -95,21 +97,24 @@ def empty_search
9597
casted_column.matches(EMPTY_VALUE)
9698
end
9799

98-
def is_searchable_integer?
100+
def searchable_integer?
99101
if formatted_value.is_a?(Array)
100-
valids = formatted_value.map { |v| is_integer?(v) && !is_out_of_range?(v) }
102+
valids = formatted_value.map { |v| integer?(v) && !out_of_range?(v) }
101103
!valids.include?(false)
102104
else
103-
is_integer?(formatted_value) && !is_out_of_range?(formatted_value)
105+
integer?(formatted_value) && !out_of_range?(formatted_value)
104106
end
105107
end
106108

107-
def is_out_of_range?(search_value)
109+
def out_of_range?(search_value)
108110
Integer(search_value) > LARGEST_PQ_INTEGER || Integer(search_value) < SMALLEST_PQ_INTEGER
109111
end
110112

111-
def is_integer?(string)
112-
true if Integer(string) rescue false
113+
def integer?(string)
114+
Integer(string)
115+
true
116+
rescue ArgumentError
117+
false
113118
end
114119

115120
end

lib/generators/datatable/config_generator.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ module Datatable
66
module Generators
77
class ConfigGenerator < ::Rails::Generators::Base
88
source_root File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
9-
desc <<DESC
10-
Description:
11-
Creates an initializer file for AjaxDatatablesRails configuration at config/initializers.
12-
DESC
9+
desc <<~DESC
10+
Description:
11+
Creates an initializer file for AjaxDatatablesRails configuration at config/initializers.
12+
DESC
1313

1414
def copy_config_file
1515
template 'ajax_datatables_rails_config.rb', 'config/initializers/ajax_datatables_rails.rb'

0 commit comments

Comments
 (0)