Module: Date::NoBrainerExtensions
- Included in:
- Date
- Defined in:
- lib/no_brainer/document/types/date.rb
Constant Summary collapse
- InvalidType =
NoBrainer::Error::InvalidType
Instance Method Summary collapse
- #nobrainer_cast_db_to_model(value) ⇒ Object
- #nobrainer_cast_model_to_db(value) ⇒ Object
- #nobrainer_cast_user_to_model(value) ⇒ Object
Instance Method Details
#nobrainer_cast_db_to_model(value) ⇒ Object
17 18 19 |
# File 'lib/no_brainer/document/types/date.rb', line 17 def nobrainer_cast_db_to_model(value) value.is_a?(Time) ? value.to_date : value end |
#nobrainer_cast_model_to_db(value) ⇒ Object
21 22 23 |
# File 'lib/no_brainer/document/types/date.rb', line 21 def nobrainer_cast_model_to_db(value) value.is_a?(Date) ? Time.utc(value.year, value.month, value.day) : value end |
#nobrainer_cast_user_to_model(value) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/no_brainer/document/types/date.rb', line 5 def nobrainer_cast_user_to_model(value) case value when Date then value when String value = value.strip date = Date.parse(value) rescue (raise InvalidType) raise InvalidType unless date.iso8601 == value date else raise InvalidType end end |