Module: TimeForABoolean
- Defined in:
- lib/time_for_a_boolean.rb,
lib/time_for_a_boolean/railtie.rb,
lib/time_for_a_boolean/version.rb
Defined Under Namespace
Classes: Railtie
Constant Summary collapse
- VERSION =
'0.2.0'
Instance Method Summary collapse
Instance Method Details
#time_for_a_boolean(attribute, field = "#{attribute}_at") ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/time_for_a_boolean.rb', line 8 def time_for_a_boolean(attribute, field="#{attribute}_at") define_method(attribute) do !send(field).nil? && send(field) <= -> { Time.current }.() end alias_method "#{attribute}?", attribute setter_attribute = "#{field}=" define_method("#{attribute}=") do |value| if ActiveModel::Type::Boolean::FALSE_VALUES.include?(value) send(setter_attribute, nil) else send(setter_attribute, -> { Time.current }.()) end end end |