active_scaffold 3.5.5 → 3.6.0.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (131) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +18 -2
  3. data/README.md +17 -7
  4. data/app/assets/javascripts/jquery/active_scaffold.js +28 -2
  5. data/app/views/active_scaffold_overrides/_base_form.html.erb +2 -2
  6. data/app/views/active_scaffold_overrides/_form.html.erb +1 -1
  7. data/app/views/active_scaffold_overrides/_form_association_footer.html.erb +3 -2
  8. data/app/views/active_scaffold_overrides/_form_association_record.html.erb +6 -6
  9. data/app/views/active_scaffold_overrides/_horizontal_subform.html.erb +1 -1
  10. data/app/views/active_scaffold_overrides/_horizontal_subform_header.html.erb +1 -1
  11. data/app/views/active_scaffold_overrides/_list.html.erb +2 -1
  12. data/app/views/active_scaffold_overrides/_list_messages.html.erb +1 -0
  13. data/app/views/active_scaffold_overrides/_messages.html.erb +1 -0
  14. data/app/views/active_scaffold_overrides/_render_field.js.erb +2 -1
  15. data/app/views/active_scaffold_overrides/_show_association_horizontal.html.erb +2 -1
  16. data/app/views/active_scaffold_overrides/_show_columns.html.erb +2 -2
  17. data/app/views/active_scaffold_overrides/_show_horizontal_record.html.erb +4 -4
  18. data/app/views/active_scaffold_overrides/_update_calculations.js.erb +1 -1
  19. data/app/views/active_scaffold_overrides/_update_column.js.erb +2 -2
  20. data/app/views/active_scaffold_overrides/action_confirmation.html.erb +2 -2
  21. data/app/views/active_scaffold_overrides/delete.html.erb +2 -2
  22. data/app/views/active_scaffold_overrides/on_action_update.js.erb +16 -6
  23. data/app/views/active_scaffold_overrides/on_update.js.erb +1 -1
  24. data/app/views/active_scaffold_overrides/row.js.erb +1 -1
  25. data/app/views/active_scaffold_overrides/update_column.js.erb +1 -1
  26. data/lib/active_scaffold.rb +11 -13
  27. data/lib/active_scaffold/actions/core.rb +25 -35
  28. data/lib/active_scaffold/actions/create.rb +1 -1
  29. data/lib/active_scaffold/actions/delete.rb +2 -2
  30. data/lib/active_scaffold/actions/field_search.rb +2 -2
  31. data/lib/active_scaffold/actions/list.rb +8 -7
  32. data/lib/active_scaffold/actions/nested.rb +9 -9
  33. data/lib/active_scaffold/actions/search.rb +1 -1
  34. data/lib/active_scaffold/actions/show.rb +1 -1
  35. data/lib/active_scaffold/actions/subform.rb +3 -1
  36. data/lib/active_scaffold/actions/update.rb +5 -4
  37. data/lib/active_scaffold/active_record_permissions.rb +2 -11
  38. data/lib/active_scaffold/attribute_params.rb +16 -23
  39. data/lib/active_scaffold/bridges.rb +8 -8
  40. data/lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb +1 -1
  41. data/lib/active_scaffold/bridges/calendar_date_select/as_cds_bridge.rb +1 -1
  42. data/lib/active_scaffold/bridges/cancan/cancan_bridge.rb +3 -18
  43. data/lib/active_scaffold/bridges/carrierwave/carrierwave_bridge.rb +1 -1
  44. data/lib/active_scaffold/bridges/chosen/helpers.rb +7 -6
  45. data/lib/active_scaffold/bridges/date_picker/ext.rb +0 -13
  46. data/lib/active_scaffold/bridges/date_picker/helper.rb +3 -3
  47. data/lib/active_scaffold/bridges/file_column/as_file_column_bridge.rb +1 -1
  48. data/lib/active_scaffold/bridges/file_column/file_column_helpers.rb +3 -3
  49. data/lib/active_scaffold/bridges/file_column/test/functional/file_column_keep_test.rb +8 -7
  50. data/lib/active_scaffold/bridges/file_column/test/test_helper.rb +2 -4
  51. data/lib/active_scaffold/bridges/paper_trail.rb +1 -1
  52. data/lib/active_scaffold/bridges/paperclip/list_ui.rb +1 -1
  53. data/lib/active_scaffold/bridges/paperclip/paperclip_bridge.rb +1 -1
  54. data/lib/active_scaffold/bridges/paperclip/paperclip_bridge_helpers.rb +2 -2
  55. data/lib/active_scaffold/bridges/record_select/helpers.rb +9 -9
  56. data/lib/active_scaffold/bridges/shared/date_bridge.rb +3 -3
  57. data/lib/active_scaffold/bridges/usa_state_select/usa_state_select_helper.rb +1 -1
  58. data/lib/active_scaffold/config/base.rb +89 -21
  59. data/lib/active_scaffold/config/core.rb +127 -18
  60. data/lib/active_scaffold/config/delete.rb +2 -0
  61. data/lib/active_scaffold/config/field_search.rb +7 -1
  62. data/lib/active_scaffold/config/form.rb +10 -1
  63. data/lib/active_scaffold/config/list.rb +27 -11
  64. data/lib/active_scaffold/config/mark.rb +3 -1
  65. data/lib/active_scaffold/config/nested.rb +16 -17
  66. data/lib/active_scaffold/config/search.rb +9 -0
  67. data/lib/active_scaffold/config/show.rb +4 -0
  68. data/lib/active_scaffold/config/update.rb +4 -0
  69. data/lib/active_scaffold/configurable.rb +11 -6
  70. data/lib/active_scaffold/constraints.rb +1 -1
  71. data/lib/active_scaffold/core.rb +46 -16
  72. data/lib/active_scaffold/data_structures/action_columns.rb +50 -59
  73. data/lib/active_scaffold/data_structures/action_link.rb +20 -8
  74. data/lib/active_scaffold/data_structures/action_links.rb +6 -2
  75. data/lib/active_scaffold/data_structures/association/abstract.rb +9 -5
  76. data/lib/active_scaffold/data_structures/association/active_record.rb +1 -1
  77. data/lib/active_scaffold/data_structures/column.rb +51 -33
  78. data/lib/active_scaffold/data_structures/nested_info.rb +1 -1
  79. data/lib/active_scaffold/data_structures/set.rb +8 -0
  80. data/lib/active_scaffold/data_structures/sorting.rb +5 -2
  81. data/lib/active_scaffold/delayed_setup.rb +2 -1
  82. data/lib/active_scaffold/extensions/action_controller_rendering.rb +2 -1
  83. data/lib/active_scaffold/extensions/action_view_rendering.rb +1 -1
  84. data/lib/active_scaffold/extensions/cow_proxy.rb +43 -0
  85. data/lib/active_scaffold/extensions/ice_nine.rb +36 -0
  86. data/lib/active_scaffold/extensions/left_outer_joins.rb +8 -33
  87. data/lib/active_scaffold/extensions/routing_mapper.rb +4 -43
  88. data/lib/active_scaffold/extensions/unsaved_record.rb +2 -4
  89. data/lib/active_scaffold/finder.rb +26 -30
  90. data/lib/active_scaffold/helpers/action_link_helpers.rb +16 -16
  91. data/lib/active_scaffold/helpers/association_helpers.rb +5 -5
  92. data/lib/active_scaffold/helpers/controller_helpers.rb +11 -1
  93. data/lib/active_scaffold/helpers/form_column_helpers.rb +25 -24
  94. data/lib/active_scaffold/helpers/id_helpers.rb +2 -2
  95. data/lib/active_scaffold/helpers/list_column_helpers.rb +8 -6
  96. data/lib/active_scaffold/helpers/search_column_helpers.rb +4 -4
  97. data/lib/active_scaffold/helpers/view_helpers.rb +7 -13
  98. data/lib/active_scaffold/marked_model.rb +2 -2
  99. data/lib/active_scaffold/orm_checks.rb +1 -5
  100. data/lib/active_scaffold/paginator.rb +6 -4
  101. data/lib/active_scaffold/registry.rb +22 -0
  102. data/lib/active_scaffold/responds_to_parent.rb +2 -6
  103. data/lib/active_scaffold/tableless.rb +63 -59
  104. data/lib/active_scaffold/version.rb +2 -2
  105. data/lib/generators/active_scaffold/controller_generator.rb +2 -2
  106. data/lib/generators/active_scaffold/install_generator.rb +1 -1
  107. data/lib/generators/active_scaffold/resource_generator.rb +2 -2
  108. data/test/bridges/date_picker_test.rb +1 -2
  109. data/test/bridges/paperclip_test.rb +5 -5
  110. data/test/class_with_finder.rb +2 -2
  111. data/test/company.rb +2 -2
  112. data/test/config/create_test.rb +4 -2
  113. data/test/config/nested_test.rb +1 -1
  114. data/test/config/show_test.rb +1 -1
  115. data/test/config/update_test.rb +7 -6
  116. data/test/data_structures/action_links_test.rb +1 -1
  117. data/test/data_structures/sorting_test.rb +7 -0
  118. data/test/misc/active_record_permissions_test.rb +1 -9
  119. data/test/misc/attribute_params_test.rb +8 -8
  120. data/test/misc/calculation_test.rb +1 -1
  121. data/test/misc/constraints_test.rb +2 -2
  122. data/test/misc/convert_numbers_format_test.rb +3 -3
  123. data/test/misc/lang_test.rb +1 -1
  124. data/test/misc/parse_datetime_test.rb +3 -4
  125. data/test/misc/tableless_test.rb +6 -0
  126. data/test/mock_app/Rakefile +1 -1
  127. data/test/mock_app/config/application.rb +1 -1
  128. data/test/mock_app/config/boot.rb +1 -1
  129. data/test/mock_app/config/environment.rb +2 -2
  130. data/test/test_helper.rb +8 -1
  131. metadata +38 -13
@@ -0,0 +1,36 @@
1
+ module IceNine
2
+ class Freezer
3
+ def self.find(name)
4
+ freezer = name.split('::').reduce(self) do |mod, const|
5
+ mod.const_lookup(const) or break mod # rubocop:disable Style/AndOr
6
+ end
7
+ freezer if freezer < self # only return a descendant freezer
8
+ end
9
+
10
+ class ObjectWithExclussion < Object
11
+ class_attribute :excluded_vars
12
+ self.excluded_vars = []
13
+ def self.freeze_instance_variables(object, recursion_guard)
14
+ object.instance_variables.each do |ivar_name|
15
+ next if excluded_vars.include? ivar_name
16
+ Freezer.guarded_deep_freeze(
17
+ object.instance_variable_get(ivar_name),
18
+ recursion_guard
19
+ )
20
+ end
21
+ end
22
+ private_class_method :freeze_instance_variables
23
+ end
24
+
25
+ class ActiveScaffold < ::IceNine::Freezer::Object
26
+ class DataStructures < ::IceNine::Freezer::Object
27
+ class Column < ::IceNine::Freezer::ObjectWithExclussion
28
+ self.excluded_vars = %i[@active_record_class @column]
29
+ end
30
+
31
+ class Association < ::IceNine::Freezer::NoFreeze
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -18,11 +18,6 @@ if Rails.version < '5.0.0'
18
18
  end
19
19
  alias left_joins left_outer_joins
20
20
 
21
- def outer_joins(*args)
22
- ActiveSupport::Deprecation.warn 'use left_outer_joins or left_joins which is added to Rails 5.0.0'
23
- left_outer_joins(*args)
24
- end
25
-
26
21
  def left_outer_joins!(*args)
27
22
  self.joins_values += [''] # HACK: for using left_outer_joins in update_all/delete_all
28
23
  self.left_outer_joins_values += args
@@ -30,39 +25,19 @@ if Rails.version < '5.0.0'
30
25
  end
31
26
  alias left_joins! left_outer_joins!
32
27
 
33
- def outer_joins!(*args)
34
- ActiveSupport::Deprecation.warn 'use left_outer_joins! or left_joins! which is added to Rails 5.0.0'
35
- left_outer_joins!(*args)
36
- end
37
-
38
- if Rails.version < '4.1'
39
- def build_arel
40
- if left_outer_joins_values.empty?
41
- super
42
- else
43
- relation = except(:left_outer_joins)
44
- join_dependency = ActiveRecord::Associations::JoinDependency.new(@klass, left_outer_joins_values, [])
45
- join_dependency.join_associations.each do |association|
46
- relation = association.join_relation(relation)
47
- end
48
- relation.build_arel
49
- end
50
- end
51
- else
52
- def build_arel
53
- if left_outer_joins_values.empty?
54
- super
55
- else
56
- relation = except(:left_outer_joins)
57
- relation.joins! ActiveRecord::Associations::JoinDependency.new(@klass, left_outer_joins_values, [])
58
- relation.build_arel
59
- end
28
+ def build_arel
29
+ if left_outer_joins_values.empty?
30
+ super
31
+ else
32
+ relation = except(:left_outer_joins)
33
+ relation.joins! ActiveRecord::Associations::JoinDependency.new(@klass, left_outer_joins_values, [])
34
+ relation.build_arel
60
35
  end
61
36
  end
62
37
  end
63
38
  end
64
39
  ActiveRecord::Relation.send :include, ActiveScaffold::OuterJoins
65
40
  module ActiveRecord::Querying
66
- delegate :left_outer_joins, :left_joins, :outer_joins, :to => :all
41
+ delegate :left_outer_joins, :left_joins, :to => :all
67
42
  end
68
43
  end
@@ -29,13 +29,13 @@ module ActiveScaffold
29
29
  actions = get_actions(ACTIVE_SCAFFOLD_ASSOCIATION_ROUTING, options)
30
30
 
31
31
  mapper.collection do
32
- ActionDispatch::Routing::ACTIVE_SCAFFOLD_ASSOCIATION_ROUTING[:collection].each do |name, type|
32
+ ActiveScaffold::Routing::ACTIVE_SCAFFOLD_ASSOCIATION_ROUTING[:collection].each do |name, type|
33
33
  mapper.match(name, via: type) if actions.include? name
34
34
  end
35
35
  end
36
36
 
37
37
  mapper.member do
38
- ActionDispatch::Routing::ACTIVE_SCAFFOLD_ASSOCIATION_ROUTING[:member].each do |name, type|
38
+ ActiveScaffold::Routing::ACTIVE_SCAFFOLD_ASSOCIATION_ROUTING[:member].each do |name, type|
39
39
  mapper.match(name, via: type) if actions.include? name
40
40
  end
41
41
  end
@@ -52,13 +52,13 @@ module ActiveScaffold
52
52
  actions = get_actions(ACTIVE_SCAFFOLD_CORE_ROUTING, options)
53
53
 
54
54
  mapper.collection do
55
- ActionDispatch::Routing::ACTIVE_SCAFFOLD_CORE_ROUTING[:collection].each do |name, type|
55
+ ActiveScaffold::Routing::ACTIVE_SCAFFOLD_CORE_ROUTING[:collection].each do |name, type|
56
56
  mapper.match(name, via: type) if actions.include? name
57
57
  end
58
58
  end
59
59
 
60
60
  mapper.member do
61
- ActionDispatch::Routing::ACTIVE_SCAFFOLD_CORE_ROUTING[:member].each do |name, type|
61
+ ActiveScaffold::Routing::ACTIVE_SCAFFOLD_CORE_ROUTING[:member].each do |name, type|
62
62
  mapper.match(name, via: type) if actions.include? name
63
63
  end
64
64
  mapper.get 'list', action: :index if mapper.send(:parent_resource).actions.include? :index
@@ -72,47 +72,8 @@ end
72
72
 
73
73
  module ActionDispatch
74
74
  module Routing
75
- ACTIVE_SCAFFOLD_CORE_ROUTING = ActiveScaffold::Routing::ACTIVE_SCAFFOLD_CORE_ROUTING
76
- ACTIVE_SCAFFOLD_ASSOCIATION_ROUTING = ActiveScaffold::Routing::ACTIVE_SCAFFOLD_ASSOCIATION_ROUTING
77
-
78
75
  class Mapper
79
76
  module Resources
80
- def parent_options
81
- opts = parent_resource.instance_variable_get(:@options)
82
- if Rails.version >= '5.0.0'
83
- opts.merge(
84
- only: parent_resource.instance_variable_get(:@only),
85
- except: parent_resource.instance_variable_get(:@except)
86
- )
87
- end
88
- opts
89
- end
90
-
91
- def define_active_scaffold_concern
92
- ActiveSupport::Deprecation.warn 'Add concern :active_scaffold, ActiveScaffold::Routing::Basic.new(association: true) to your routes file.'
93
- concern :active_scaffold, ActiveScaffold::Routing::Basic.new(association: true)
94
- end
95
-
96
- def define_active_scaffold_association_concern
97
- ActiveSupport::Deprecation.warn 'Add concern :active_scaffold_association, ActiveScaffold::Routing::Association.new to your routes file.'
98
- concern :active_scaffold_association, ActiveScaffold::Routing::Association.new
99
- end
100
-
101
- def as_routes(opts = {association: true})
102
- define_active_scaffold_concern unless @concerns[:active_scaffold]
103
- if opts[:association] && !@concerns[:active_scaffold_association]
104
- define_active_scaffold_association_concern
105
- end
106
- ActiveSupport::Deprecation.warn 'Use concerns: :active_scaffold in resources instead of as_routes, or concerns :active_scaffold in resources block if want to disable association routes or restrict routes with only or except options.'
107
- concerns :active_scaffold, parent_options.merge(association: opts[:association])
108
- end
109
-
110
- def as_association_routes
111
- define_active_scaffold_association_concern unless @concerns[:active_scaffold_association]
112
- ActiveSupport::Deprecation.warn 'Use concerns: :active_scaffold_association in resources instead of as_association_routes, or concerns :active_scaffold_association in resources block if want to restrict routes with only or except options.'
113
- concerns :active_scaffold_association, parent_options
114
- end
115
-
116
77
  def as_nested_resources(*resources)
117
78
  options = resources.extract_options!
118
79
  nested_options = options.merge(parent_scaffold: parent_scaffold)
@@ -18,10 +18,8 @@ module ActiveScaffold::UnsavedRecord
18
18
  def keeping_errors
19
19
  old_errors = errors.dup if errors.present?
20
20
  result = yield
21
- if old_errors
22
- old_errors.each do |attr|
23
- old_errors[attr].each { |msg| errors.add(attr, msg) unless errors.added?(attr, msg) }
24
- end
21
+ old_errors&.each do |attr|
22
+ old_errors[attr].each { |msg| errors.add(attr, msg) unless errors.added?(attr, msg) }
25
23
  end
26
24
  result && old_errors.blank?
27
25
  end
@@ -95,7 +95,7 @@ module ActiveScaffold
95
95
  if respond_to?("condition_for_#{column.name}_column")
96
96
  return send("condition_for_#{column.name}_column", column, value, like_pattern)
97
97
  end
98
- return unless column && column.search_sql && value.present?
98
+ return unless column&.search_sql && value.present?
99
99
  search_ui = column.search_ui || column.column_type
100
100
  begin
101
101
  sql, *values =
@@ -122,7 +122,7 @@ module ActiveScaffold
122
122
  def condition_for_search_ui(column, value, like_pattern, search_ui)
123
123
  case search_ui
124
124
  when :boolean, :checkbox
125
- ['%{search_sql} = ?', column.column ? ActiveScaffold::Core.column_type_cast(value, column.column) : value]
125
+ ['%<search_sql>s = ?', column.column ? ActiveScaffold::Core.column_type_cast(value, column.column) : value]
126
126
  when :integer, :decimal, :float
127
127
  condition_for_numeric(column, value)
128
128
  when :string, :range
@@ -131,47 +131,47 @@ module ActiveScaffold
131
131
  condition_for_datetime(column, value)
132
132
  when :select, :multi_select, :country, :usa_state, :chosen, :multi_chosen
133
133
  values = Array(value).select(&:present?)
134
- ['%{search_sql} in (?)', values] if values.present?
134
+ ['%<search_sql>s in (?)', values] if values.present?
135
135
  else
136
136
  if column.text?
137
- ["%{search_sql} #{ActiveScaffold::Finder.like_operator} ?", like_pattern.sub('?', value)]
137
+ ["%<search_sql>s #{ActiveScaffold::Finder.like_operator} ?", like_pattern.sub('?', value)]
138
138
  else
139
- ['%{search_sql} = ?', ActiveScaffold::Core.column_type_cast(value, column.column)]
139
+ ['%<search_sql>s = ?', ActiveScaffold::Core.column_type_cast(value, column.column)]
140
140
  end
141
141
  end
142
142
  end
143
143
 
144
144
  def condition_for_numeric(column, value)
145
145
  if !value.is_a?(Hash)
146
- ['%{search_sql} = ?', condition_value_for_numeric(column, value)]
146
+ ['%<search_sql>s = ?', condition_value_for_numeric(column, value)]
147
147
  elsif ActiveScaffold::Finder::NULL_COMPARATORS.include?(value[:opt])
148
148
  condition_for_null_type(column, value[:opt])
149
149
  elsif value[:from].blank? || !ActiveScaffold::Finder::NUMERIC_COMPARATORS.include?(value[:opt])
150
150
  nil
151
151
  elsif value[:opt] == 'BETWEEN'
152
- ['(%{search_sql} BETWEEN ? AND ?)', condition_value_for_numeric(column, value[:from]), condition_value_for_numeric(column, value[:to])]
152
+ ['(%<search_sql>s BETWEEN ? AND ?)', condition_value_for_numeric(column, value[:from]), condition_value_for_numeric(column, value[:to])]
153
153
  else
154
- ["%{search_sql} #{value[:opt]} ?", condition_value_for_numeric(column, value[:from])]
154
+ ["%<search_sql>s #{value[:opt]} ?", condition_value_for_numeric(column, value[:from])]
155
155
  end
156
156
  end
157
157
 
158
158
  def condition_for_range(column, value, like_pattern = nil)
159
159
  if !value.is_a?(Hash)
160
160
  if column.text?
161
- ["%{search_sql} #{ActiveScaffold::Finder.like_operator} ?", like_pattern.sub('?', value)]
161
+ ["%<search_sql>s #{ActiveScaffold::Finder.like_operator} ?", like_pattern.sub('?', value)]
162
162
  else
163
- ['%{search_sql} = ?', ActiveScaffold::Core.column_type_cast(value, column.column)]
163
+ ['%<search_sql>s = ?', ActiveScaffold::Core.column_type_cast(value, column.column)]
164
164
  end
165
165
  elsif ActiveScaffold::Finder::NULL_COMPARATORS.include?(value[:opt])
166
166
  condition_for_null_type(column, value[:opt], like_pattern)
167
167
  elsif value[:from].blank?
168
168
  nil
169
169
  elsif ActiveScaffold::Finder::STRING_COMPARATORS.values.include?(value[:opt])
170
- ["%{search_sql} #{ActiveScaffold::Finder.like_operator} ?", value[:opt].sub('?', value[:from])]
170
+ ["%<search_sql>s #{ActiveScaffold::Finder.like_operator} ?", value[:opt].sub('?', value[:from])]
171
171
  elsif value[:opt] == 'BETWEEN'
172
- ['(%{search_sql} BETWEEN ? AND ?)', value[:from], value[:to]]
172
+ ['(%<search_sql>s BETWEEN ? AND ?)', value[:from], value[:to]]
173
173
  elsif ActiveScaffold::Finder::NUMERIC_COMPARATORS.include?(value[:opt])
174
- ["%{search_sql} #{value[:opt]} ?", value[:from]]
174
+ ["%<search_sql>s #{value[:opt]} ?", value[:from]]
175
175
  end
176
176
  end
177
177
 
@@ -230,7 +230,7 @@ module ActiveScaffold
230
230
  unless value.nil? || value.blank?
231
231
  if value.is_a? Hash
232
232
  time = Time.zone.local(*%i[year month day hour minute second].collect { |part| value[part].to_i }) rescue nil
233
- time.send(conversion) if time
233
+ time&.send(conversion)
234
234
  elsif value.respond_to?(:strftime)
235
235
  if conversion == :to_time
236
236
  # Explicitly get the current zone, because TimeWithZone#to_time in rails 3.2.3 returns UTC.
@@ -250,7 +250,7 @@ module ActiveScaffold
250
250
  format, offset = format_for_datetime(column, value)
251
251
  format.gsub!(/%-d|%-m|%_m/) { |s| s.gsub(/[-_]/, '') } # strptime fails with %-d, %-m, %_m
252
252
  value = translate_days_and_months(value, format) if I18n.locale != :en
253
- time = DateTime.strptime(value, format) rescue nil
253
+ time = Time.strptime(value, format) rescue nil
254
254
  if time
255
255
  time = Time.zone.local_to_utc(time).in_time_zone unless offset
256
256
  time = time.send(conversion) unless conversion == :to_time
@@ -267,11 +267,7 @@ module ActiveScaffold
267
267
  when :integer then value.to_i rescue value ? 1 : 0
268
268
  when :float then value.to_f
269
269
  when :decimal
270
- if Rails.version >= '4.2.0'
271
- ::ActiveRecord::Type::Decimal.new.type_cast_from_user(value)
272
- else
273
- ::ActiveRecord::ConnectionAdapters::Column.value_to_decimal(value)
274
- end
270
+ ::ActiveRecord::Type::Decimal.new.type_cast_from_user(value)
275
271
  else
276
272
  value
277
273
  end
@@ -293,28 +289,28 @@ module ActiveScaffold
293
289
  if from_value.nil? && to_value.nil?
294
290
  nil
295
291
  elsif !from_value
296
- ['%{search_sql} <= ?', to_value.to_s(:db)]
292
+ ['%<search_sql>s <= ?', to_value.to_s(:db)]
297
293
  elsif !to_value
298
- ['%{search_sql} >= ?', from_value.to_s(:db)]
294
+ ['%<search_sql>s >= ?', from_value.to_s(:db)]
299
295
  else
300
- ['%{search_sql} BETWEEN ? AND ?', from_value.to_s(:db), to_value.to_s(:db)]
296
+ ['%<search_sql>s BETWEEN ? AND ?', from_value.to_s(:db), to_value.to_s(:db)]
301
297
  end
302
298
  end
303
299
 
304
300
  def condition_for_record_select_type(column, value, like_pattern = nil)
305
301
  if value.is_a?(Array)
306
- ['%{search_sql} IN (?)', value]
302
+ ['%<search_sql>s IN (?)', value]
307
303
  else
308
- ['%{search_sql} = ?', value]
304
+ ['%<search_sql>s = ?', value]
309
305
  end
310
306
  end
311
307
 
312
308
  def condition_for_null_type(column, value, like_pattern = nil)
313
309
  case value.to_s
314
310
  when 'null'
315
- ['%{search_sql} is null', []]
311
+ ['%<search_sql>s is null', []]
316
312
  when 'not_null'
317
- ['%{search_sql} is not null', []]
313
+ ['%<search_sql>s is not null', []]
318
314
  end
319
315
  end
320
316
  end
@@ -415,7 +411,7 @@ module ActiveScaffold
415
411
 
416
412
  # create a general-use options array that's compatible with Rails finders
417
413
  finder_options = {
418
- :reorder => options[:sorting].try(:clause, (grouped_columns_calculations if grouped_search?)),
414
+ :reorder => options[:sorting]&.clause((grouped_columns_calculations if grouped_search?)),
419
415
  :conditions => search_conditions
420
416
  }
421
417
  if active_scaffold_config.mongoid?
@@ -466,7 +462,7 @@ module ActiveScaffold
466
462
 
467
463
  query = append_to_query(query, find_options)
468
464
  # we build the paginator differently for method- and sql-based sorting
469
- pager = if options[:sorting] && options[:sorting].sorts_by_method?
465
+ pager = if options[:sorting]&.sorts_by_method?
470
466
  ::Paginator.new(count, options[:per_page]) do |offset, per_page|
471
467
  calculate_last_modified(query)
472
468
  sorted_collection = sort_collection_by_column(query.to_a, *options[:sorting].first)
@@ -536,7 +532,7 @@ module ActiveScaffold
536
532
  def sort_collection_by_column(collection, column, order)
537
533
  sorter = column.sort[:method]
538
534
  collection = collection.sort_by do |record|
539
- value = (sorter.is_a? Proc) ? record.instance_eval(&sorter) : record.instance_eval(sorter.to_s)
535
+ value = sorter.is_a?(Proc) ? record.instance_eval(&sorter) : record.instance_eval(sorter.to_s)
540
536
  value = '' if value.nil?
541
537
  value
542
538
  end
@@ -79,8 +79,8 @@ module ActiveScaffold
79
79
  end
80
80
 
81
81
  def render_action_link(link, record = nil, options = {})
82
- if link.action.nil? || link.column.try(:association).try(:polymorphic?)
83
- link = action_link_to_inline_form(link, record) if link.column.try(:association)
82
+ if link.action.nil? || link.column&.association&.polymorphic?
83
+ link = action_link_to_inline_form(link, record) if link.column&.association
84
84
  options[:authorized] = false if link.action.nil? || link.controller.nil?
85
85
  options.delete :link if link.crud_type == :create
86
86
  end
@@ -95,9 +95,9 @@ module ActiveScaffold
95
95
 
96
96
  # setup the action link to inline form
97
97
  def action_link_to_inline_form(link, record)
98
- link = link.clone
98
+ link = link.dup
99
99
  associated = record.send(link.column.association.name)
100
- if link.column.association.try(:polymorphic?)
100
+ if link.column.association&.polymorphic?
101
101
  link.controller = controller_path_for_activerecord(associated.class)
102
102
  return link if link.controller.nil?
103
103
  end
@@ -160,7 +160,7 @@ module ActiveScaffold
160
160
  end
161
161
 
162
162
  def cache_action_link_url?(link, record)
163
- active_scaffold_config.cache_action_link_urls && link.type == :member && !link.dynamic_parameters.is_a?(Proc) && !sti_record?(record)
163
+ active_scaffold_config.user.cache_action_link_urls && link.type == :member && !link.dynamic_parameters.is_a?(Proc) && !sti_record?(record)
164
164
  end
165
165
 
166
166
  def cached_action_link_url(link, record)
@@ -178,8 +178,8 @@ module ActiveScaffold
178
178
 
179
179
  def replace_id_params_in_action_link_url(link, record, url)
180
180
  url = record ? url.sub('--ID--', record.to_param.to_s) : url.clone
181
- if link.column.try(:association).try(:singular?)
182
- child_id = record.send(link.column.association.name).try(:to_param)
181
+ if link.column&.association&.singular?
182
+ child_id = record.send(link.column.association.name)&.to_param
183
183
  if child_id.present?
184
184
  url.sub!('--CHILD_ID--', child_id)
185
185
  else
@@ -243,7 +243,7 @@ module ActiveScaffold
243
243
  end
244
244
 
245
245
  def cache_action_link_url_options?(link, record)
246
- active_scaffold_config.cache_action_link_urls && (link.type == :collection || !link.dynamic_parameters.is_a?(Proc)) && !sti_record?(record)
246
+ active_scaffold_config.user.cache_action_link_urls && (link.type == :collection || !link.dynamic_parameters.is_a?(Proc)) && !sti_record?(record)
247
247
  end
248
248
 
249
249
  def cached_action_link_url_options(link, record)
@@ -290,8 +290,8 @@ module ActiveScaffold
290
290
  missing_options, url_options = url.partition { |_, v| v.nil? }
291
291
  replacements = {}
292
292
  replacements['--ID--'] = record.id.to_s if record
293
- if link.column.try(:association).try(:singular?)
294
- replacements['--CHILD_ID--'] = record.send(link.column.association.name).try(:id).to_s
293
+ if link.column&.association&.singular?
294
+ replacements['--CHILD_ID--'] = record.send(link.column.association.name)&.id.to_s
295
295
  elsif nested?
296
296
  replacements['--CHILD_ID--'] = params[nested.param_name].to_s
297
297
  end
@@ -303,7 +303,7 @@ module ActiveScaffold
303
303
 
304
304
  def action_link_selected?(link, record)
305
305
  missing_options, url_options = replaced_action_link_url_options(link, record)
306
- safe_params = (Rails.version < '4.2' ? params.to_h : params.to_unsafe_h)
306
+ safe_params = params.to_unsafe_h
307
307
  (url_options - safe_params.to_a).blank? && missing_options.all? { |k, _| params[k].nil? }
308
308
  end
309
309
 
@@ -316,7 +316,7 @@ module ActiveScaffold
316
316
  html_options[:method] = link.method if link.method != :get
317
317
 
318
318
  html_options[:data] ||= {}
319
- html_options[:data][:confirm] = link.confirm(h(record.try(:to_label))) if link.confirm?
319
+ html_options[:data][:confirm] = link.confirm(h(record&.to_label)) if link.confirm?
320
320
  if !options[:page] && !options[:popup] && (options[:inline] || link.inline?)
321
321
  html_options[:class] << ' as_action'
322
322
  html_options[:data][:position] = link.position if link.position
@@ -346,7 +346,7 @@ module ActiveScaffold
346
346
 
347
347
  def get_action_link_id(link, record = nil, column = nil)
348
348
  column ||= link.column
349
- if column.try(:association) && record
349
+ if column&.association && record
350
350
  id = if column.association.collection?
351
351
  "#{column.association.name}-#{record.id}"
352
352
  elsif record.send(column.association.name).present?
@@ -355,7 +355,7 @@ module ActiveScaffold
355
355
  "#{column.association.name}-#{record.id}"
356
356
  end
357
357
  end
358
- id ||= record.try(:id) || (nested? ? nested_parent_id : '')
358
+ id ||= record&.id || (nested? ? nested_parent_id : '')
359
359
  action_id = "#{id_from_controller("#{link.controller}-") if params[:parent_controller] || (link.controller && link.controller != controller.controller_path)}#{link.action}"
360
360
  action_link_id(action_id, id)
361
361
  end
@@ -371,13 +371,13 @@ module ActiveScaffold
371
371
  end
372
372
 
373
373
  def url_options_for_nested_link(column, record, link, url_options)
374
- if column.try(:association)
374
+ if column&.association
375
375
  url_options[:parent_scaffold] = controller_path
376
376
  url_options[column.model.name.foreign_key.to_sym] = url_options.delete(:id)
377
377
  url_options[:id] = if column.association.singular? && url_options[:action].to_sym != :index
378
378
  '--CHILD_ID--'
379
379
  end
380
- elsif link.parameters && link.parameters[:named_scope]
380
+ elsif link.parameters&.dig(:named_scope)
381
381
  url_options[:parent_scaffold] = controller_path
382
382
  url_options[active_scaffold_config.model.name.foreign_key.to_sym] = url_options.delete(:id)
383
383
  end