Module: Changed
- Defined in:
- lib/changed.rb,
lib/changed/config.rb,
lib/changed/engine.rb,
lib/changed/builder.rb,
lib/changed/version.rb,
lib/changed/auditable.rb,
app/models/changed/audit.rb,
app/models/changed/association.rb,
app/models/changed/application_record.rb
Defined Under Namespace
Modules: Auditable Classes: ApplicationRecord, Association, Audit, Builder, Config, Engine, Field, Relationship
Constant Summary collapse
- VERSION =
'2.0.1'.freeze
Class Method Summary collapse
-
.changer ⇒ Object
Access the changer (this value is set as the changer within an audit and defaults to config).
-
.changer=(changer) ⇒ Object
Customize the changer (uses a request store to only change lifeycle event).
-
.config ⇒ Object
Access the library configuration.
- .options ⇒ Object
- .options=(options) ⇒ Object
-
.perform(options = {}, &block) ⇒ Object
Perform a block with custom override options.
-
.timestamp ⇒ Object
Access the timestamp (this value is set as the timestamp within an audit and defaults to now).
-
.timestamp=(timestamp) ⇒ Object
Customize the timestamp (uses a request store to only change lifeycle event).
Class Method Details
.changer ⇒ Object
Access the changer (this value is set as the changer within an audit and defaults to config).
40 41 42 |
# File 'lib/changed.rb', line 40 def self.changer [:changer] || config.default_changer_proc&.call end |
.changer=(changer) ⇒ Object
53 54 55 |
# File 'lib/changed.rb', line 53 def self.changer=(changer) [:changer] = changer end |
.config ⇒ Object
17 18 19 |
# File 'lib/changed.rb', line 17 def self.config @config ||= Config.new end |
.options ⇒ Object
85 86 87 |
# File 'lib/changed.rb', line 85 def self. RequestStore.store[OPTIONS_REQUEST_STORE_KEY] ||= {} end |
.options=(options) ⇒ Object
81 82 83 |
# File 'lib/changed.rb', line 81 def self.() RequestStore.store[OPTIONS_REQUEST_STORE_KEY] = end |
.perform(options = {}, &block) ⇒ Object
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
.name = "Sprocket"
.save!
end
70 71 72 73 74 75 76 |
# File 'lib/changed.rb', line 70 def self.perform( = {}, &block) backup = self. self. = block.call ensure self. = backup end |
.timestamp ⇒ Object
Access the timestamp (this value is set as the timestamp within an audit and defaults to now).
22 23 24 |
# File 'lib/changed.rb', line 22 def self. [:timestamp] || Time.now end |
.timestamp=(timestamp) ⇒ Object
Customize the timestamp (uses a request store to only change lifeycle event).
Attributes
-
timestamp- A timestamp to use.
Examples
Changed. = 2.hours.ago
35 36 37 |
# File 'lib/changed.rb', line 35 def self.() [:timestamp] = end |