Sha256: 2613ed95b858ce95a6f9401656dfd7aad3ab6471759ddc8fd38c96eb659411ae

Contents?: true

Size: 385 Bytes

Versions: 6

Compression:

Stored size: 385 Bytes

Contents

module Cardboard
  class Field::Date < Field
    validate :is_required
    validate :is_date

    def value
      Chronic.parse(value_uid)
    end

    def value=(val)
      self.value_uid = val
    end

    def default
      Time.now
    end

    private

    def is_date
      errors.add(:value, "not a recognized date format") if value_uid.present? && value.blank?
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
cardboard_cms-0.3.1 app/models/cardboard/field/date.rb
cardboard_cms-0.2.2 app/models/cardboard/field/date.rb
cardboard_cms-0.2.1 app/models/cardboard/field/date.rb
cardboard_cms-0.1.8 app/models/cardboard/field/date.rb
cardboard_cms-0.1.6 app/models/cardboard/field/date.rb
cardboard_cms-0.1.4 app/models/cardboard/field/date.rb