Module: Dolly::Timestamp

Included in:
Document
Defined in:
lib/dolly/timestamp.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



13
14
15
# File 'lib/dolly/timestamp.rb', line 13

def self.included(base)
  base.extend(ClassMethods)
end

Instance Method Details

#timestamped?Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/dolly/timestamp.rb', line 9

def timestamped?
  respond_to?(:created_at) && respond_to?(:updated_at)
end

#write_timestamps(is_persisted) ⇒ Object



3
4
5
6
7
# File 'lib/dolly/timestamp.rb', line 3

def write_timestamps(is_persisted)
  return unless timestamped?
  write_attribute(:created_at, Time.now) unless is_persisted
  write_attribute(:updated_at, Time.now)
end