Sha256: 8a254238181927b6e65b7a29c08f3907063e61f0bdb68671306f33c99a56cf5a
Contents?: true
Size: 1.13 KB
Versions: 2
Compression:
Stored size: 1.13 KB
Contents
module Microscope class InstanceMethod class DateInstanceMethod < InstanceMethod def initialize(*args) super @now = 'Date.today' @cropped_field_regex = /_on$/ end def apply return unless @field_name =~ @cropped_field_regex cropped_field = field.name.gsub(@cropped_field_regex, '') infinitive_verb = self.class.past_participle_to_infinitive(cropped_field) model.class_eval <<-RUBY, __FILE__, __LINE__ + 1 define_method "#{cropped_field}?" do value = send("#{field.name}") !value.nil? && value <= #{@now} end define_method "#{cropped_field}=" do |value| if Microscope::InstanceMethod.value_to_boolean(value) self.#{field.name} ||= #{@now} else self.#{field.name} = nil end end define_method "not_#{cropped_field}?" do !#{cropped_field}? end define_method "#{infinitive_verb}!" do send("#{field.name}=", #{@now}) save! end RUBY end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
microscope-0.5.6.1 | lib/microscope/instance_method/date_instance_method.rb |
microscope-0.5.6 | lib/microscope/instance_method/date_instance_method.rb |