Class: SuperSettings::HistoryItem

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Methods included from Attributes

#attributes=

Constructor Details

#initializeHistoryItem

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_byObject

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_atObject

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

Parameters:

  • value

    the value to set the attribute deleted to.



10
11
12
# File 'lib/super_settings/history_item.rb', line 10

def deleted=(value)
  @deleted = value
end

#keyObject

Returns the value of attribute key.



9
10
11
# File 'lib/super_settings/history_item.rb', line 9

def key
  @key
end

#valueObject

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_jsonObject



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_displayString?

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.

Returns:

  • (String, nil)


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

Returns:

  • (Boolean)


17
18
19
# File 'lib/super_settings/history_item.rb', line 17

def deleted?
  !!@deleted
end