class CIA::AttributeChange

Public Class Methods

max_value_size() click to toggle source
# File lib/cia/attribute_change.rb, line 21
def self.max_value_size
  @max_value_size ||= (columns.detect { |c| c.name == "old_value" }.limit || 255)
end
on_attribute(attribute) click to toggle source
# File lib/cia/attribute_change.rb, line 17
def self.on_attribute(attribute)
  where(attribute_name: attribute)
end
serialize_for_storage(item) { |item| ... } click to toggle source
# File lib/cia/attribute_change.rb, line 25
def self.serialize_for_storage(item, &block)
  raise "Pass me a block to reduce size" unless block_given?
  before, json = nil

  loop do
    json = JSON.dump(item)
    raise "The block did not reduce the size" if before && json.bytesize >= before
    before = json.bytesize
    break if max_value_size >= before
    item = yield(item)
  end

  json
end

Private Instance Methods

source_must_be_present?() click to toggle source
# File lib/cia/attribute_change.rb, line 42
def source_must_be_present?
  event.present? && event.source_must_be_present?
end