From 79a12db33bde6e50b1fa3a35fe52bd6518bc180e Mon Sep 17 00:00:00 2001 From: Bogdan Gusiev Date: Tue, 9 Jan 2024 11:52:09 +0200 Subject: [PATCH] Cleanup --- app/views/datagrid/_form.html.erb | 1 - lib/datagrid/drivers/mongoid.rb | 2 +- lib/datagrid/form_builder.rb | 2 +- lib/datagrid/rspec.rb | 2 +- lib/datagrid/utils.rb | 2 +- spec/support/simple_report.rb | 2 +- 6 files changed, 5 insertions(+), 6 deletions(-) diff --git a/app/views/datagrid/_form.html.erb b/app/views/datagrid/_form.html.erb index 065dfc1..7e175c1 100644 --- a/app/views/datagrid/_form.html.erb +++ b/app/views/datagrid/_form.html.erb @@ -7,7 +7,6 @@ <% end %>
<%= f.submit I18n.t("datagrid.form.search").html_safe, class: "datagrid-submit" %> - <%# https://github.com/rails/rails/pull/14949 -%> <%= link_to I18n.t('datagrid.form.reset').html_safe, url_for(grid.to_param => {}), class: "datagrid-reset" %>
<% end -%> diff --git a/lib/datagrid/drivers/mongoid.rb b/lib/datagrid/drivers/mongoid.rb index c5a5e24..5bb30c2 100644 --- a/lib/datagrid/drivers/mongoid.rb +++ b/lib/datagrid/drivers/mongoid.rb @@ -60,7 +60,7 @@ def column_names(scope) end def normalized_column_type(scope, field) - type = to_scope(scope).klass.fields[field.to_s].try(:type) + type = to_scope(scope).klass.fields[field.to_s]&.type return nil unless type { [BigDecimal , String, Symbol, Range, Array, Hash, ] => :string, diff --git a/lib/datagrid/form_builder.rb b/lib/datagrid/form_builder.rb index f7b7d2d..f0f30f5 100644 --- a/lib/datagrid/form_builder.rb +++ b/lib/datagrid/form_builder.rb @@ -166,7 +166,7 @@ def datagrid_range_filter(type, attribute_or_filter, options = {}) def datagrid_range_filter_options(object, filter, type, options) type_method_map = {from: :first, to: :last} options = add_html_classes(options, type) - options[:value] = filter.format(object[filter.name].try(type_method_map[type])) + options[:value] = filter.format(object[filter.name]&.public_send(type_method_map[type])) # In case of datagrid ranged filter # from and to input will have same id if !options.key?(:id) diff --git a/lib/datagrid/rspec.rb b/lib/datagrid/rspec.rb index 1f195ad..a0e5480 100644 --- a/lib/datagrid/rspec.rb +++ b/lib/datagrid/rspec.rb @@ -46,7 +46,7 @@ 1 when :enum select = subject.select_options(filter) - select.first.try(:last) + select.first&.last else raise "unknown filter type: #{filter.class}" end.to_s diff --git a/lib/datagrid/utils.rb b/lib/datagrid/utils.rb index 315c9e4..fb8a56f 100644 --- a/lib/datagrid/utils.rb +++ b/lib/datagrid/utils.rb @@ -117,7 +117,7 @@ def format_date_as_timestamp(value) if !value value elsif value.is_a?(Array) - [value.first.try(:beginning_of_day), value.last.try(:end_of_day)] + [value.first&.beginning_of_day, value.last&.end_of_day] elsif value.is_a?(Range) (value.first.beginning_of_day..value.last.end_of_day) else diff --git a/spec/support/simple_report.rb b/spec/support/simple_report.rb index ed2f2a1..02591f9 100644 --- a/spec/support/simple_report.rb +++ b/spec/support/simple_report.rb @@ -49,7 +49,7 @@ class SimpleReport end column(:pet, html: lambda {|data| content_tag :em, data}) do - self.pet.try(:upcase) + self.pet&.upcase end column(:shipping_date, before: :group)