Class: ActiveDateRange::DateRangeType

Inherits:
ActiveModel::Type::String
  • Object
show all
Defined in:
lib/active_date_range/active_model_type.rb

Instance Method Summary collapse

Constructor Details

#initialize(safe: false) ⇒ DateRangeType

Pass safe: true for attributes fed by input you don't control, like a query parameter. The attribute then casts to nil instead of raising:

attribute :period, :date_range, safe: true


9
10
11
12
# File 'lib/active_date_range/active_model_type.rb', line 9

def initialize(safe: false)
  @safe = safe
  super()
end

Instance Method Details

#cast(value) ⇒ Object



14
15
16
# File 'lib/active_date_range/active_model_type.rb', line 14

def cast(value)
  @safe ? ActiveDateRange::DateRange.safe_parse(value) : ActiveDateRange::DateRange.parse(value)
end