Class: ValidatesDateTime::ValidatesDateTimeRestriction

Inherits:
Struct
  • Object
show all
Defined in:
lib/validates_date_time.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#parse_methodObject

Returns the value of attribute parse_method

Returns:

  • (Object)

    the current value of parse_method



21
22
23
# File 'lib/validates_date_time.rb', line 21

def parse_method
  @parse_method
end

#raw_valueObject

Returns the value of attribute raw_value

Returns:

  • (Object)

    the current value of raw_value



21
22
23
# File 'lib/validates_date_time.rb', line 21

def raw_value
  @raw_value
end

Instance Method Details

#last_valueObject



39
40
41
# File 'lib/validates_date_time.rb', line 39

def last_value
  @last_value
end

#parse(string) ⇒ Object



35
36
37
# File 'lib/validates_date_time.rb', line 35

def parse(string)
  ActiveRecord::ConnectionAdapters::Column.send("string_to_#{parse_method}", string)
end

#to_sObject



43
44
45
46
47
48
49
# File 'lib/validates_date_time.rb', line 43

def to_s
  if raw_value.is_a?(Symbol)
    raw_value.to_s.humanize
  else
    @last_value.to_s
  end
end

#value(record) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/validates_date_time.rb', line 22

def value(record)
  @last_value = case raw_value
    when Symbol
      record.send(raw_value)
    when Proc
      raw_value.call(record)
    else
      raw_value
  end
  
  @last_value = parse(@last_value)
end