Class: SafeType::DateTime
- Inherits:
-
Rule
- Object
- Rule
- SafeType::DateTime
show all
- Defined in:
- lib/safe_type/primitive/date_time.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Rule
#after, #before, coerce, #coerce
Constructor Details
#initialize(type: ::DateTime, from: nil, to: nil, **args) ⇒ DateTime
Returns a new instance of DateTime.
3
4
5
6
7
|
# File 'lib/safe_type/primitive/date_time.rb', line 3
def initialize(type: ::DateTime, from: nil, to: nil, **args)
@from = from
@to = to
super
end
|
Class Method Details
.default(value = nil, from: nil, to: nil) ⇒ Object
15
16
17
18
19
20
21
|
# File 'lib/safe_type/primitive/date_time.rb', line 15
def self.default(value=nil, from: nil, to: nil)
new(
default: value,
from: from,
to: to
)
end
|
.strict(from: nil, to: nil) ⇒ Object
23
24
25
26
27
28
29
|
# File 'lib/safe_type/primitive/date_time.rb', line 23
def self.strict(from: nil, to: nil)
new(
required: true,
from: from,
to: to
)
end
|
Instance Method Details
#is_valid?(input) ⇒ Boolean
9
10
11
12
13
|
# File 'lib/safe_type/primitive/date_time.rb', line 9
def is_valid?(input)
return false unless @from.nil? || input >= @from
return false unless @to.nil? || input <= @to
super
end
|