Module: DataMapper::Timestamps::ClassMethods

Defined in:
lib/dm-timestamps.rb

Instance Method Summary collapse

Instance Method Details

#timestamps(*names) ⇒ Object

Raises:

  • (ArgumentError)


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

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 }

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

        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