cia 0.5.3 → 0.5.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile.lock +3 -1
- data/Readme.md +3 -1
- data/cia.gemspec +1 -0
- data/gemfiles/rails2.gemfile.lock +3 -1
- data/gemfiles/rails3.gemfile.lock +3 -1
- data/lib/cia/attribute_change.rb +21 -0
- data/lib/cia/version.rb +1 -1
- data/spec/cia/attribute_change_spec.rb +35 -0
- metadata +21 -5
data/Gemfile.lock
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
cia (0.5.
|
4
|
+
cia (0.5.4)
|
5
|
+
json
|
5
6
|
|
6
7
|
GEM
|
7
8
|
remote: https://rubygems.org/
|
@@ -25,6 +26,7 @@ GEM
|
|
25
26
|
bump (0.3.9)
|
26
27
|
diff-lcs (1.1.3)
|
27
28
|
i18n (0.6.1)
|
29
|
+
json (1.8.0)
|
28
30
|
multi_json (1.5.0)
|
29
31
|
rake (10.0.3)
|
30
32
|
rspec (2.12.0)
|
data/Readme.md
CHANGED
@@ -81,7 +81,9 @@ CIA.audit(:actor => current_user, :my_pretty_audit_property => "12345") do
|
|
81
81
|
...
|
82
82
|
end
|
83
83
|
|
84
|
-
|
84
|
+
# storing complex objects in old/new and reducing it's size if it's to big (serialized via json)
|
85
|
+
value = CIA::AttributeChange.serialize_for_storage(["some", "complex"*1000, "object"]){|too_big| too_big.delete_at(1); too_big }
|
86
|
+
CIA::AttributeChange.create!(:old_value => value)
|
85
87
|
```
|
86
88
|
|
87
89
|
|
data/cia.gemspec
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
PATH
|
2
2
|
remote: /Users/mgrosser/code/tools/cia
|
3
3
|
specs:
|
4
|
-
cia (0.5.
|
4
|
+
cia (0.5.3)
|
5
|
+
json
|
5
6
|
|
6
7
|
GEM
|
7
8
|
remote: https://rubygems.org/
|
@@ -16,6 +17,7 @@ GEM
|
|
16
17
|
rake
|
17
18
|
bump (0.3.9)
|
18
19
|
diff-lcs (1.1.3)
|
20
|
+
json (1.8.0)
|
19
21
|
rake (0.9.2.2)
|
20
22
|
rspec (2.10.0)
|
21
23
|
rspec-core (~> 2.10.0)
|
@@ -1,7 +1,8 @@
|
|
1
1
|
PATH
|
2
2
|
remote: /Users/mgrosser/code/tools/cia
|
3
3
|
specs:
|
4
|
-
cia (0.5.
|
4
|
+
cia (0.5.3)
|
5
|
+
json
|
5
6
|
|
6
7
|
GEM
|
7
8
|
remote: https://rubygems.org/
|
@@ -25,6 +26,7 @@ GEM
|
|
25
26
|
bump (0.3.9)
|
26
27
|
diff-lcs (1.1.3)
|
27
28
|
i18n (0.6.1)
|
29
|
+
json (1.8.0)
|
28
30
|
multi_json (1.5.0)
|
29
31
|
rake (10.0.3)
|
30
32
|
rspec (2.12.0)
|
data/lib/cia/attribute_change.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require "json"
|
2
|
+
|
1
3
|
module CIA
|
2
4
|
class AttributeChange < ActiveRecord::Base
|
3
5
|
include SourceValidation
|
@@ -20,6 +22,25 @@ module CIA
|
|
20
22
|
scoped(:conditions => {:attribute_name => attribute})
|
21
23
|
end
|
22
24
|
|
25
|
+
def self.max_value_size
|
26
|
+
@max_value_size ||= columns.detect { |c| c.name == "old_value" }.limit
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.serialize_for_storage(item, &block)
|
30
|
+
raise "Pass me a block to reduce size" unless block_given?
|
31
|
+
before, json = nil
|
32
|
+
|
33
|
+
loop do
|
34
|
+
json = JSON.dump(item)
|
35
|
+
raise "The block did not reduce the size" if before && json.bytesize >= before
|
36
|
+
before = json.bytesize
|
37
|
+
break if max_value_size >= before
|
38
|
+
item = yield(item)
|
39
|
+
end
|
40
|
+
|
41
|
+
json
|
42
|
+
end
|
43
|
+
|
23
44
|
private
|
24
45
|
|
25
46
|
def source_must_be_present?
|
data/lib/cia/version.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# encoding: utf-8
|
1
2
|
require 'spec_helper'
|
2
3
|
|
3
4
|
describe CIA::AttributeChange do
|
@@ -62,4 +63,38 @@ describe CIA::AttributeChange do
|
|
62
63
|
change.valid?.should be_true
|
63
64
|
end
|
64
65
|
end
|
66
|
+
|
67
|
+
describe ".max_value_size" do
|
68
|
+
it "is the width of the old/new column" do
|
69
|
+
CIA::AttributeChange.max_value_size.should == 255
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe ".serialize_for_storage" do
|
74
|
+
it "stores as json" do
|
75
|
+
CIA::AttributeChange.serialize_for_storage([["xxx"]]){}.should == '[["xxx"]]'
|
76
|
+
end
|
77
|
+
|
78
|
+
it "calls the block to remove an item" do
|
79
|
+
CIA::AttributeChange.serialize_for_storage([["xxx"], ["x"*300], ["yyy"]]){ |array| array.delete_at(1); array }.should == '[["xxx"],["yyy"]]'
|
80
|
+
end
|
81
|
+
|
82
|
+
it "blows up if block fails to reduce size to prevent loops" do
|
83
|
+
expect{
|
84
|
+
CIA::AttributeChange.serialize_for_storage([["xxx"], ["x"*300], ["yyy"]]){ |array| array }
|
85
|
+
}.to raise_error
|
86
|
+
end
|
87
|
+
|
88
|
+
it "takes multibyte into account" do
|
89
|
+
called = false
|
90
|
+
CIA::AttributeChange.serialize_for_storage(["å" * 200]){ |array| called = true; "x" }
|
91
|
+
called.should == true
|
92
|
+
end
|
93
|
+
|
94
|
+
it "does not go crazy on multibytes" do
|
95
|
+
called = false
|
96
|
+
CIA::AttributeChange.serialize_for_storage(["å" * 100]){ |array| called = true; "x" }
|
97
|
+
called.should == false
|
98
|
+
end
|
99
|
+
end
|
65
100
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cia
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,8 +9,24 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-05-
|
13
|
-
dependencies:
|
12
|
+
date: 2013-05-28 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: json
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
14
30
|
description:
|
15
31
|
email: michael@grosser.it
|
16
32
|
executables: []
|
@@ -54,7 +70,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
54
70
|
version: '0'
|
55
71
|
segments:
|
56
72
|
- 0
|
57
|
-
hash:
|
73
|
+
hash: 1152273165294657851
|
58
74
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
75
|
none: false
|
60
76
|
requirements:
|
@@ -63,7 +79,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
63
79
|
version: '0'
|
64
80
|
segments:
|
65
81
|
- 0
|
66
|
-
hash:
|
82
|
+
hash: 1152273165294657851
|
67
83
|
requirements: []
|
68
84
|
rubyforge_project:
|
69
85
|
rubygems_version: 1.8.25
|