Module: DataMapper::Timestamps::ClassMethods

Defined in:
lib/dm-timestamps.rb

Instance Method Summary collapse

Instance Method Details

#timestamps(*names) ⇒ Object

Raises:

  • (ArgumentError)


38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/dm-timestamps.rb', line 38

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
        options = {required: true}

        options.update(auto_validation: false) if Property.accepted_options.include?(:auto_validation)

        property name, TIMESTAMP_PROPERTIES[name].first, options
      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