Class: Sanitized::DateTime
- Inherits:
-
ActiveModel::Type::DateTime
- Object
- ActiveModel::Type::DateTime
- Sanitized::DateTime
- Includes:
- Base
- Defined in:
- lib/sanitized/date_time.rb
Overview
Description
ActiveModel::Type to cast and sanitize a model’s DateTime attribute according to the options specified on initialisation.
attribute :attr_name, Sanitized::DateTime.new(:end_of_week, :at_noon), default: Time.now
Can optionally include a custom block:
type_cast = Sanitized::DateTime.new(:beginning_of_week, :at_noon) do |value|
... custome code ...
end
attribute :attr_name, type_cast, default: Date.today
Class Method Summary collapse
-
.exclusive_options ⇒ Object
Return an Array of the options that modify both the date and the time.
-
.valid_options ⇒ Object
return a Hash of valid options with the other options they are exclusive with.
Methods included from Base
Class Method Details
.exclusive_options ⇒ Object
Return an Array of the options that modify both the date and the time
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/sanitized/date_time.rb', line 78 def self. [ :at_beginning_of_day, :at_beginning_of_hour, :at_beginning_of_minute, :at_beginning_of_month, :at_beginning_of_quarter, :at_beginning_of_week, :at_beginning_of_year, :at_end_of_day, :at_end_of_hour, :at_end_of_minute, :at_end_of_month, :at_end_of_quarter, :at_end_of_week, :at_end_of_year, :at_midday, :at_middle_of_day, :at_midnight, :at_noon, :beginning_of_day, :beginning_of_hour, :beginning_of_minute, :beginning_of_month, :beginning_of_quarter, :beginning_of_week, :beginning_of_year, :end_of_month, :end_of_quarter, :end_of_week, :end_of_year, :end_of_day, :end_of_hour, :end_of_minute, :midday, :middle_of_day, :midnight, :noon ] end |
.valid_options ⇒ Object
return a Hash of valid options with the other options they are exclusive with
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/sanitized/date_time.rb', line 34 def self. { at_beginning_of_day: self., at_beginning_of_hour: self., at_beginning_of_minute: self., at_beginning_of_month: self., at_beginning_of_quarter: self., at_beginning_of_week: self., at_beginning_of_year: self., at_end_of_day: self., at_end_of_hour: self., at_end_of_minute: self., at_end_of_month: self., at_end_of_quarter: self., at_end_of_week: self., at_end_of_year: self., at_midday: self., at_middle_of_day: self., at_midnight: self., at_noon: self., beginning_of_day: self., beginning_of_hour: self., beginning_of_minute: self., beginning_of_month: self., beginning_of_quarter: self., beginning_of_week: self., beginning_of_year: self., end_of_month: self., end_of_quarter: self., end_of_week: self., end_of_year: self., end_of_day: self., end_of_hour: self., end_of_minute: self., midday: self., middle_of_day: self., midnight: self., noon: self. } end |