Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
bogdan committed Jan 9, 2024
1 parent 004972c commit 79a12db
Show file tree
Hide file tree
Showing 6 changed files with 5 additions and 6 deletions.
1 change: 0 additions & 1 deletion app/views/datagrid/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
<% end %>
<div class="datagrid-actions">
<%= 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" %>
</div>
<% end -%>
2 changes: 1 addition & 1 deletion lib/datagrid/drivers/mongoid.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion lib/datagrid/form_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion lib/datagrid/rspec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/datagrid/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/support/simple_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 79a12db

Please sign in to comment.