Sha256: 3bc53e7bd92b82f9d1869a34bde083b65d836e3ced5ac7a057f0f8f161e940b5

Contents?: true

Size: 958 Bytes

Versions: 3

Compression:

Stored size: 958 Bytes

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 deleted?
      # Stupid strict mode...
      !!(defined?(@deleted) && @deleted)
    end

    # The method could be overriden to change how the changed_by attribute is displayed.
    # For instance, you could store a user id in the changed_by column and add an association
    # on this model.
    #
    # @example
    #   class SuperSettings::HistoryItem
    #     def changed_by_display
    #       user = User.find_by(id: changed_by) if changed_by
    #       user ? user.name : changed_by
    #     end
    #   end
    #
    # @return [String]
    def changed_by_display
      changed_by
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
super_settings-0.0.1.rc3 lib/super_settings/history_item.rb
super_settings-0.0.1.rc2 lib/super_settings/history_item.rb
super_settings-0.0.1.rc1 lib/super_settings/history_item.rb