Module: DataMapper::Timestamp::ClassMethods

Defined in:
lib/gems/dm-timestamps-0.9.9/lib/dm-timestamps.rb

Instance Method Summary collapse

Instance Method Details

#timestamps(*names) ⇒ Object

Raises:

  • (ArgumentError)


35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/gems/dm-timestamps-0.9.9/lib/dm-timestamps.rb', line 35

def timestamps(*names)
  raise ArgumentError, 'You need to pass at least one argument' if names.empty?

  names.each do |name|
    case name
      when *TIMESTAMP_PROPERTIES.keys
        type = TIMESTAMP_PROPERTIES[name].first
        property name, type, :nullable => false, :auto_validation => false
      when :at
        timestamps(:created_at, :updated_at)
      when :on
        timestamps(:created_on, :updated_on)
      else
        raise InvalidTimestampName, "Invalid timestamp property name '#{name}'"
    end
  end
end