Sha256: e399f5adf0c8b9cfccbfb43e78df6427e2b7cc103f2806bf938102332a78d6de

Contents?: true

Size: 1.05 KB

Versions: 4

Compression:

Stored size: 1.05 KB

Contents

# frozen_string_literal: true

module SuperSettings
  # 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.
  class HistoryItem
    include Attributes

    attr_accessor :key, :value, :changed_by, :created_at
    attr_writer :deleted

    def initialize(*)
      @deleted = false
      super
    end

    def deleted?
      !!@deleted
    end

    # 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.
    #
    # @return [String, nil]
    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
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
super_settings-2.0.3 lib/super_settings/history_item.rb
super_settings-2.0.2 lib/super_settings/history_item.rb
super_settings-2.0.1 lib/super_settings/history_item.rb
super_settings-2.0.0 lib/super_settings/history_item.rb