Class: Spina::Admin::Conferences::IntervalType
- Inherits:
-
ActiveRecord::Type::Value
- Object
- ActiveRecord::Type::Value
- Spina::Admin::Conferences::IntervalType
- Defined in:
- lib/spina/admin/conferences/types/interval_type.rb
Overview
This type maps between ActiveSupport::Duration and interval in PostgreSQL
Instance Method Summary collapse
Instance Method Details
#cast(value) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/spina/admin/conferences/types/interval_type.rb', line 8 def cast(value) case value when ::ActiveSupport::Duration value when ::String ::ActiveSupport::Duration.parse(value) when ::Integer ::ActiveSupport::Duration.build(value) end rescue ActiveSupport::Duration::ISO8601Parser::ParsingError nil end |
#serialize(value) ⇒ Object
21 22 23 24 25 |
# File 'lib/spina/admin/conferences/types/interval_type.rb', line 21 def serialize(value) return unless value.class == ::ActiveSupport::Duration value.iso8601 end |