Class: CIA::AttributeChange
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- CIA::AttributeChange
- Includes:
- SourceValidation
- Defined in:
- lib/cia/attribute_change.rb
Class Method Summary collapse
- .max_value_size ⇒ Object
- .on_attribute(attribute) ⇒ Object
- .serialize_for_storage(item, &block) ⇒ Object
Methods included from SourceValidation
Class Method Details
.max_value_size ⇒ Object
21 22 23 |
# 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) ⇒ Object
17 18 19 |
# File 'lib/cia/attribute_change.rb', line 17 def self.on_attribute(attribute) where(attribute_name: attribute) end |
.serialize_for_storage(item, &block) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# 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 |