Class: SuperSettings::HistoryItem
- Inherits:
-
Object
- Object
- SuperSettings::HistoryItem
- Includes:
- Attributes
- Defined in:
- lib/super_settings/history_item.rb
Overview
Model for each item in a setting's history. When a setting is changed, the system will track the value it is changed to, who it was changed by, and when.
Instance Attribute Summary collapse
-
#changed_by ⇒ Object
Returns the value of attribute changed_by.
-
#created_at ⇒ Object
Returns the value of attribute created_at.
-
#deleted ⇒ Object
writeonly
Sets the attribute deleted.
-
#key ⇒ Object
Returns the value of attribute key.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
- #as_json ⇒ Object
-
#changed_by_display ⇒ String?
The display value for the changed_by attribute.
- #deleted? ⇒ Boolean
-
#initialize ⇒ HistoryItem
constructor
A new instance of HistoryItem.
Methods included from Attributes
Constructor Details
#initialize ⇒ HistoryItem
Returns a new instance of HistoryItem.
12 13 14 15 |
# File 'lib/super_settings/history_item.rb', line 12 def initialize(*) @deleted = false super end |
Instance Attribute Details
#changed_by ⇒ Object
Returns the value of attribute changed_by.
9 10 11 |
# File 'lib/super_settings/history_item.rb', line 9 def changed_by @changed_by end |
#created_at ⇒ Object
Returns the value of attribute created_at.
9 10 11 |
# File 'lib/super_settings/history_item.rb', line 9 def created_at @created_at end |
#deleted=(value) ⇒ Object (writeonly)
Sets the attribute deleted
10 11 12 |
# File 'lib/super_settings/history_item.rb', line 10 def deleted=(value) @deleted = value end |
#key ⇒ Object
Returns the value of attribute key.
9 10 11 |
# File 'lib/super_settings/history_item.rb', line 9 def key @key end |
#value ⇒ Object
Returns the value of attribute value.
9 10 11 |
# File 'lib/super_settings/history_item.rb', line 9 def value @value end |
Instance Method Details
#as_json ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/super_settings/history_item.rb', line 38 def as_json { value: value, changed_by: changed_by, created_at: created_at&.utc&.iso8601(6), deleted: deleted? } end |
#changed_by_display ⇒ String?
The display value for the changed_by attribute. This method can be overridden
in the configuration by calling model.define_changed_by_display with the block to use
to get the display value for the changed_by attribute. The default value is
the changed_by attribute itself.
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/super_settings/history_item.rb', line 27 def changed_by_display return changed_by if changed_by.nil? display_proc = SuperSettings.configuration.model.changed_by_display if display_proc && !changed_by.nil? display_proc.call(changed_by) || changed_by else changed_by end end |
#deleted? ⇒ Boolean
17 18 19 |
# File 'lib/super_settings/history_item.rb', line 17 def deleted? !!@deleted end |