Sha256: 087afa1abd0b3ec0e6e0bf5191426f3d4330345fce8ba60b9fbd91310e62bb23

Contents?: true

Size: 677 Bytes

Versions: 1

Compression:

Stored size: 677 Bytes

Contents

require "active_support/core_ext/module/delegation"
require "active_record/connection_adapters/column"
require "time_for_a_boolean/version"
require "time_for_a_boolean/railtie"

module TimeForABoolean
  def time_for_a_boolean(attribute)
    define_method(attribute) do
      !send("#{attribute}_at").nil? &&
        send("#{attribute}_at") <= -> { Time.current }.()
    end
    alias_method "#{attribute}?", attribute
    define_method("#{attribute}=") do |value|
      if ActiveRecord::ConnectionAdapters::Column::TRUE_VALUES.include?(value)
        send("#{attribute}_at=", -> { Time.current }.())
      else
        send("#{attribute}_at=", nil)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
time_for_a_boolean-0.0.6 lib/time_for_a_boolean.rb