Skip to content

Commit

Permalink
Fix FALSE_VALUES reference for AR 4.x
Browse files Browse the repository at this point in the history
  • Loading branch information
molawson committed Jul 3, 2018
1 parent e441b72 commit 95b82f2
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/boolean_timestamp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,20 @@ def define_boolean_timestamp_scopes(method_name, fully_qualified_column_name)
end

def define_boolean_timestamp_accessors(method_name, column_name)
false_values = if ActiveRecord::VERSION::MAJOR >= 5
ActiveModel::Type::Boolean::FALSE_VALUES
else
ActiveRecord::ConnectionAdapters::Column::FALSE_VALUES
end

define_method(method_name) do
public_send(column_name).present? && !public_send(column_name).future?
end

alias_method("#{method_name}?", method_name)

define_method("#{method_name}=") do |value|
if ActiveModel::Type::Boolean::FALSE_VALUES.include?(value)
if false_values.include?(value)
public_send("#{column_name}=", nil)
elsif !public_send(method_name)
public_send("#{column_name}=", Time.current)
Expand Down

0 comments on commit 95b82f2

Please sign in to comment.