Module: TemporalScopes::HasTemporalScopes::InstanceMethods

Defined in:
lib/temporal_scopes/has_temporal_scopes.rb

Overview

The following instance methods are added to ActiveRecord::Base objects, which classes have been called has_temporal_scopes on.

Instance Method Summary collapse

Instance Method Details

#archive(params = {}) ⇒ ActiveRecord::Base

Archives an object, that is, makes it a past object.

Examples:

Archiving an object now.

article.archive

Archiving an object with effect 4 hours ago.

article.archive at: 4.hours.ago

Parameters:

  • params (Hash) (defaults to: {})

    a hash of parameters.

Options Hash (params):

  • :at (DateTime) — default: Time.zonw.now

    when to archive the object, i.e. the time when the present object becomes a past object, i.e. expires.

Returns:

  • (ActiveRecord::Base)

    the archived object.



119
120
121
122
123
124
125
# File 'lib/temporal_scopes/has_temporal_scopes.rb', line 119

def archive(params = {})
  unless self.valid_to
    archive_at = params[:at] || Time.zone.now
    update_attribute(:valid_to, archive_at)
  end
  return self
end