module Changed

Constants

Field
OPTIONS_REQUEST_STORE_KEY
Relationship
VERSION

Public Class Methods

changer() click to toggle source

Access the changer (this value is set as the changer within an audit and defaults to config).

# File lib/changed.rb, line 40
def self.changer
  options[:changer] || config.default_changer_proc&.call
end
changer=(changer) click to toggle source

Customize the changer (uses a request store to only change lifeycle event).

Attributes

  • changer - A changer to use.

Examples

Changed.changer = User.current
# File lib/changed.rb, line 53
def self.changer=(changer)
  options[:changer] = changer
end
config() click to toggle source

Access the library configuration.

Examples

Changed.config.default_changer_proc = ->{ User.system }
# File lib/changed.rb, line 17
def self.config
  @config ||= Config.new
end
options() click to toggle source
# File lib/changed.rb, line 85
def self.options
  RequestStore.store[OPTIONS_REQUEST_STORE_KEY] ||= {}
end
options=(options) click to toggle source
# File lib/changed.rb, line 81
def self.options=(options)
  RequestStore.store[OPTIONS_REQUEST_STORE_KEY] = options
end
perform(options = {}, &block) click to toggle source

Perform a block with custom override options.

Attributes

  • options - Values for the changer and / or timestamp.

  • block - Some code to run with the new options.

Examples

Changed.perform(changer: User.system, timestamp: 2.hours.ago) do
  widget.name = "Sprocket"
  widget.save!
end
# File lib/changed.rb, line 70
def self.perform(options = {}, &block)
  backup = self.options
  self.options = options
  block.call
ensure
  self.options = backup
end
timestamp() click to toggle source

Access the timestamp (this value is set as the timestamp within an audit and defaults to now).

# File lib/changed.rb, line 22
def self.timestamp
  options[:timestamp] || Time.now
end
timestamp=(timestamp) click to toggle source

Customize the timestamp (uses a request store to only change lifeycle event).

Attributes

  • timestamp - A timestamp to use.

Examples

Changed.timestamp = 2.hours.ago
# File lib/changed.rb, line 35
def self.timestamp=(timestamp)
  options[:timestamp] = timestamp
end