Class: Protobuf::ActiveRecord::Serialization::ClassMethods::DateCaller

Inherits:
Object
  • Object
show all
Defined in:
lib/protobuf/active_record/serialization.rb

Instance Method Summary collapse

Constructor Details

#initialize(field) ⇒ DateCaller

Returns a new instance of DateCaller.



163
164
165
# File 'lib/protobuf/active_record/serialization.rb', line 163

def initialize(field)
  @field = field
end

Instance Method Details

#call(selph) ⇒ Object



167
168
169
170
171
172
173
174
175
176
177
# File 'lib/protobuf/active_record/serialization.rb', line 167

def call(selph)
  value = selph.__send__(@field)

  if value
    value.to_time(:utc).to_i
  else
    nil
  end
rescue NameError # Has happened when field is not on model or ignored from db
  return nil
end