Module: ROM::SQL::Plugin::Timestamps::ClassInterface Private

Defined in:
lib/rom/sql/plugin/timestamps.rb

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(klass) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



19
20
21
22
23
24
25
# File 'lib/rom/sql/plugin/timestamps.rb', line 19

def self.extended(klass)
  klass.defines :timestamp_columns, :datestamp_columns
  klass.timestamp_columns Set.new
  klass.datestamp_columns Set.new

  super
end

Instance Method Details

#datestamps(*args) ⇒ Object Also known as: datestamp

Set up attributes to datestamp when the command is called

Examples:

class CreateTask < ROM::Commands::Create[:sql]
  result :one
  use :timestamps
  datestamps :created_on, :updated_on
end

create_user = rom.command(:user).create.with(name: 'Jane')

result = create_user.call
result[:created_at]  #=> Date.today

Parameters:

  • name (Symbol)

    of the attribute to set



68
69
70
71
72
# File 'lib/rom/sql/plugin/timestamps.rb', line 68

def datestamps(*args)
  datestamp_columns datestamp_columns.merge(args)

  include InstanceMethods
end

#timestamps(*args) ⇒ Object Also known as: timestamp

Set up attributes to timestamp when the command is called

Examples:

class CreateTask < ROM::Commands::Create[:sql]
  result :one
  use :timestamps
  timestamps :created_at, :updated_at
end

create_user = rom.command(:user).create.with(name: 'Jane')

result = create_user.call
result[:created_at]  #=> Time.now.utc

Parameters:

  • name (Symbol)

    of the attribute to set



44
45
46
47
48
# File 'lib/rom/sql/plugin/timestamps.rb', line 44

def timestamps(*args)
  timestamp_columns timestamp_columns.merge(args)

  include InstanceMethods
end