cerealize 0.9.0 → 1.0.0
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/.gitignore +2 -0
- data/.gitmodules +3 -0
- data/.travis.yml +9 -0
- data/CHANGES +5 -0
- data/CONTRIBUTORS +2 -0
- data/Gemfile +6 -0
- data/README +6 -9
- data/README.rdoc +6 -9
- data/Rakefile +8 -2
- data/cerealize.gemspec +65 -16
- data/lib/cerealize.rb +2 -2
- data/lib/cerealize/version.rb +1 -1
- data/rrr.rb +13 -0
- data/task/.gitignore +1 -0
- data/task/gemgem.rb +41 -11
- data/test/common.rb +3 -2
- data/test/real.rb +7 -1
- data/test/stub.rb +2 -0
- data/test/test_all_codec.rb +52 -57
- data/test/test_attr_hash.rb +16 -16
- data/test/test_basic.rb +47 -48
- data/test/test_transcode.rb +19 -24
- metadata +64 -62
data/.gitmodules
ADDED
data/.travis.yml
ADDED
data/CHANGES
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
= cerealize changes history
|
2
2
|
|
3
|
+
== cerealize 1.0.0 -- 2011-06-29
|
4
|
+
|
5
|
+
* Nothing really changed, but officially support ActiveRecord 2 and 3 now.
|
6
|
+
* Added JRuby and Rubinius support.
|
7
|
+
|
3
8
|
== cerealize 0.9.0 -- 2011-04-28
|
4
9
|
|
5
10
|
* changed class_inheritable_accessor to superclass_delegating_accessor.
|
data/CONTRIBUTORS
ADDED
data/Gemfile
ADDED
data/README
CHANGED
@@ -9,8 +9,7 @@ by Cardinal Blue ( http://cardinalblue.com )
|
|
9
9
|
|
10
10
|
== DESCRIPTION:
|
11
11
|
|
12
|
-
Serialize out of the Cerealize Box
|
13
|
-
- a drop-in replacement for ActiveRecord's serialize
|
12
|
+
Serialize out of the Cerealize Box - a drop-in replacement for ActiveRecord's serialize
|
14
13
|
|
15
14
|
It can auto transcode old encoding (yaml if you're using AR's serialize),
|
16
15
|
to new encoding (marshal, json, you name it) without any migration.
|
@@ -20,10 +19,6 @@ by Cardinal Blue ( http://cardinalblue.com )
|
|
20
19
|
2. Marshal
|
21
20
|
3. JSON (planned)
|
22
21
|
|
23
|
-
Current supported ORM:
|
24
|
-
1. ActiveRecord (tested with 2.3.11)
|
25
|
-
2. DataMapper (planned)
|
26
|
-
|
27
22
|
== SYNOPSIS:
|
28
23
|
|
29
24
|
require 'cerealize'
|
@@ -49,8 +44,10 @@ by Cardinal Blue ( http://cardinalblue.com )
|
|
49
44
|
|
50
45
|
== REQUIREMENTS:
|
51
46
|
|
52
|
-
*
|
53
|
-
*
|
47
|
+
* ActiveRecord 2 or 3
|
48
|
+
* Tested with MRI (official ruby) 1.9.2, 1.8.7, and trunk
|
49
|
+
* Tested with Rubinius (rbx) 1.2.3
|
50
|
+
* Tested with JRuby 1.6.2
|
54
51
|
|
55
52
|
== INSTALL:
|
56
53
|
|
@@ -62,7 +59,7 @@ by Cardinal Blue ( http://cardinalblue.com )
|
|
62
59
|
|
63
60
|
Apache License 2.0
|
64
61
|
|
65
|
-
Copyright (c) 2010, Cardinal Blue
|
62
|
+
Copyright (c) 2010-2011, Cardinal Blue
|
66
63
|
|
67
64
|
Licensed under the Apache License, Version 2.0 (the "License");
|
68
65
|
you may not use this file except in compliance with the License.
|
data/README.rdoc
CHANGED
@@ -9,8 +9,7 @@ by Cardinal Blue ( http://cardinalblue.com )
|
|
9
9
|
|
10
10
|
== DESCRIPTION:
|
11
11
|
|
12
|
-
Serialize out of the Cerealize Box
|
13
|
-
- a drop-in replacement for ActiveRecord's serialize
|
12
|
+
Serialize out of the Cerealize Box - a drop-in replacement for ActiveRecord's serialize
|
14
13
|
|
15
14
|
It can auto transcode old encoding (yaml if you're using AR's serialize),
|
16
15
|
to new encoding (marshal, json, you name it) without any migration.
|
@@ -20,10 +19,6 @@ by Cardinal Blue ( http://cardinalblue.com )
|
|
20
19
|
2. Marshal
|
21
20
|
3. JSON (planned)
|
22
21
|
|
23
|
-
Current supported ORM:
|
24
|
-
1. ActiveRecord (tested with 2.3.11)
|
25
|
-
2. DataMapper (planned)
|
26
|
-
|
27
22
|
== SYNOPSIS:
|
28
23
|
|
29
24
|
require 'cerealize'
|
@@ -49,8 +44,10 @@ by Cardinal Blue ( http://cardinalblue.com )
|
|
49
44
|
|
50
45
|
== REQUIREMENTS:
|
51
46
|
|
52
|
-
*
|
53
|
-
*
|
47
|
+
* ActiveRecord 2 or 3
|
48
|
+
* Tested with MRI (official ruby) 1.9.2, 1.8.7, and trunk
|
49
|
+
* Tested with Rubinius (rbx) 1.2.3
|
50
|
+
* Tested with JRuby 1.6.2
|
54
51
|
|
55
52
|
== INSTALL:
|
56
53
|
|
@@ -62,7 +59,7 @@ by Cardinal Blue ( http://cardinalblue.com )
|
|
62
59
|
|
63
60
|
Apache License 2.0
|
64
61
|
|
65
|
-
Copyright (c) 2010, Cardinal Blue
|
62
|
+
Copyright (c) 2010-2011, Cardinal Blue
|
66
63
|
|
67
64
|
Licensed under the Apache License, Version 2.0 (the "License");
|
68
65
|
you may not use this file except in compliance with the License.
|
data/Rakefile
CHANGED
@@ -11,10 +11,16 @@ task 'gem:spec' do
|
|
11
11
|
require 'cerealize/version'
|
12
12
|
s.name = 'cerealize'
|
13
13
|
s.version = Cerealize::VERSION
|
14
|
+
s.homepage = 'https://github.com/cardinalblue/cerealize'
|
14
15
|
# s.executables = [s.name]
|
15
16
|
|
16
|
-
%w[activerecord].each{ |g| s.add_runtime_dependency(g
|
17
|
-
%w[
|
17
|
+
%w[activerecord].each{ |g| s.add_runtime_dependency(g) }
|
18
|
+
%w[bacon] .each{ |g| s.add_development_dependency(g) }
|
19
|
+
if defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby'
|
20
|
+
s.add_development_dependency('activerecord-jdbcsqlite3-adapter')
|
21
|
+
else
|
22
|
+
s.add_development_dependency('sqlite3')
|
23
|
+
end
|
18
24
|
|
19
25
|
s.authors = ['Cardinal Blue', 'Lin Jen-Shin (godfat)', 'Jaime Cham']
|
20
26
|
s.email = ['dev (XD) cardinalblue.com']
|
data/cerealize.gemspec
CHANGED
@@ -2,35 +2,84 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{cerealize}
|
5
|
-
s.version = "0.
|
5
|
+
s.version = "1.0.0"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
|
-
s.authors = [
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
s.
|
13
|
-
s.
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
s.
|
8
|
+
s.authors = [
|
9
|
+
%q{Cardinal Blue},
|
10
|
+
%q{Lin Jen-Shin (godfat)},
|
11
|
+
%q{Jaime Cham}]
|
12
|
+
s.date = %q{2011-06-29}
|
13
|
+
s.description = %q{ Serialize out of the Cerealize Box - a drop-in replacement for ActiveRecord's serialize
|
14
|
+
|
15
|
+
It can auto transcode old encoding (yaml if you're using AR's serialize),
|
16
|
+
to new encoding (marshal, json, you name it) without any migration.}
|
17
|
+
s.email = [%q{dev (XD) cardinalblue.com}]
|
18
|
+
s.extra_rdoc_files = [
|
19
|
+
%q{CHANGES},
|
20
|
+
%q{CONTRIBUTORS},
|
21
|
+
%q{LICENSE},
|
22
|
+
%q{TODO}]
|
23
|
+
s.files = [
|
24
|
+
%q{.gitignore},
|
25
|
+
%q{.gitmodules},
|
26
|
+
%q{.travis.yml},
|
27
|
+
%q{CHANGES},
|
28
|
+
%q{CONTRIBUTORS},
|
29
|
+
%q{Gemfile},
|
30
|
+
%q{LICENSE},
|
31
|
+
%q{README},
|
32
|
+
%q{README.rdoc},
|
33
|
+
%q{Rakefile},
|
34
|
+
%q{TODO},
|
35
|
+
%q{bench/simple.png},
|
36
|
+
%q{bench/simple.rb},
|
37
|
+
%q{cerealize.gemspec},
|
38
|
+
%q{init.rb},
|
39
|
+
%q{lib/cerealize.rb},
|
40
|
+
%q{lib/cerealize/attr_hash.rb},
|
41
|
+
%q{lib/cerealize/codec/marshal.rb},
|
42
|
+
%q{lib/cerealize/codec/text.rb},
|
43
|
+
%q{lib/cerealize/codec/yaml.rb},
|
44
|
+
%q{lib/cerealize/version.rb},
|
45
|
+
%q{rrr.rb},
|
46
|
+
%q{task/.gitignore},
|
47
|
+
%q{task/gemgem.rb},
|
48
|
+
%q{test/common.rb},
|
49
|
+
%q{test/real.rb},
|
50
|
+
%q{test/stub.rb},
|
51
|
+
%q{test/test_all_codec.rb},
|
52
|
+
%q{test/test_attr_hash.rb},
|
53
|
+
%q{test/test_basic.rb},
|
54
|
+
%q{test/test_transcode.rb}]
|
55
|
+
s.homepage = %q{https://github.com/cardinalblue/cerealize}
|
56
|
+
s.rdoc_options = [
|
57
|
+
%q{--main},
|
58
|
+
%q{README}]
|
59
|
+
s.require_paths = [%q{lib}]
|
60
|
+
s.rubygems_version = %q{1.8.5}
|
18
61
|
s.summary = %q{Serialize out of the Cerealize Box - a drop-in replacement for ActiveRecord's serialize}
|
19
|
-
s.test_files = [
|
62
|
+
s.test_files = [
|
63
|
+
%q{test/test_all_codec.rb},
|
64
|
+
%q{test/test_attr_hash.rb},
|
65
|
+
%q{test/test_basic.rb},
|
66
|
+
%q{test/test_transcode.rb}]
|
20
67
|
|
21
68
|
if s.respond_to? :specification_version then
|
22
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
23
69
|
s.specification_version = 3
|
24
70
|
|
25
71
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
26
|
-
s.add_runtime_dependency(%q<activerecord>, ["
|
72
|
+
s.add_runtime_dependency(%q<activerecord>, [">= 0"])
|
73
|
+
s.add_development_dependency(%q<bacon>, [">= 0"])
|
27
74
|
s.add_development_dependency(%q<sqlite3>, [">= 0"])
|
28
75
|
else
|
29
|
-
s.add_dependency(%q<activerecord>, ["
|
76
|
+
s.add_dependency(%q<activerecord>, [">= 0"])
|
77
|
+
s.add_dependency(%q<bacon>, [">= 0"])
|
30
78
|
s.add_dependency(%q<sqlite3>, [">= 0"])
|
31
79
|
end
|
32
80
|
else
|
33
|
-
s.add_dependency(%q<activerecord>, ["
|
81
|
+
s.add_dependency(%q<activerecord>, [">= 0"])
|
82
|
+
s.add_dependency(%q<bacon>, [">= 0"])
|
34
83
|
s.add_dependency(%q<sqlite3>, [">= 0"])
|
35
84
|
end
|
36
85
|
end
|
data/lib/cerealize.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'cerealize/attr_hash'
|
4
4
|
|
5
|
-
gem 'activerecord'
|
5
|
+
gem 'activerecord'
|
6
6
|
require 'active_record'
|
7
7
|
autoload :YAML, 'yaml'
|
8
8
|
|
@@ -105,7 +105,7 @@ module Cerealize
|
|
105
105
|
|
106
106
|
mod.module_eval <<-RUBY, __FILE__, __LINE__ + 1
|
107
107
|
def #{field_cache}
|
108
|
-
@#{property}
|
108
|
+
@#{property} ||= nil
|
109
109
|
end
|
110
110
|
|
111
111
|
def #{field_cache}=(new_value)
|
data/lib/cerealize/version.rb
CHANGED
data/rrr.rb
ADDED
data/task/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
*.rbc
|
data/task/gemgem.rb
CHANGED
@@ -11,13 +11,15 @@ module Gemgem
|
|
11
11
|
yield(spec = Gem::Specification.new{ |s|
|
12
12
|
s.authors = ['Lin Jen-Shin (godfat)']
|
13
13
|
s.email = ['godfat (XD) godfat.org']
|
14
|
-
s.homepage = "http://github.com/godfat/#{s.name}"
|
15
14
|
|
16
|
-
|
17
|
-
match(/DESCRIPTION:\n\n(.+?)
|
18
|
-
|
15
|
+
description = File.read("#{Gemgem.dir}/README").
|
16
|
+
match(/DESCRIPTION:\n\n(.+?)(?=\n\n[^\n]+:\n)/m)[1].
|
17
|
+
lines.to_a
|
19
18
|
|
20
|
-
s.
|
19
|
+
s.description = description.join
|
20
|
+
s.summary = description.first
|
21
|
+
|
22
|
+
s.extra_rdoc_files = %w[CHANGES CONTRIBUTORS LICENSE TODO]
|
21
23
|
s.rdoc_options = %w[--main README]
|
22
24
|
s.rubygems_version = Gem::VERSION
|
23
25
|
s.date = Time.now.strftime('%Y-%m-%d')
|
@@ -25,6 +27,7 @@ module Gemgem
|
|
25
27
|
s.test_files = gem_files.grep(%r{^test/(.+?/)*test_.+?\.rb$})
|
26
28
|
s.require_paths = %w[lib]
|
27
29
|
})
|
30
|
+
spec.homepage ||= "https://github.com/godfat/#{spec.name}"
|
28
31
|
spec
|
29
32
|
end
|
30
33
|
|
@@ -33,7 +36,18 @@ module Gemgem
|
|
33
36
|
end
|
34
37
|
|
35
38
|
def write
|
36
|
-
File.open("#{dir}/#{spec.name}.gemspec", 'w'){ |f|
|
39
|
+
File.open("#{dir}/#{spec.name}.gemspec", 'w'){ |f|
|
40
|
+
f << split_lines(spec.to_ruby) }
|
41
|
+
end
|
42
|
+
|
43
|
+
def split_lines ruby
|
44
|
+
ruby.gsub(/(.+?)\[(.+?)\]/){ |s|
|
45
|
+
if $2.index(',')
|
46
|
+
"#{$1}[\n #{$2.split(',').map(&:strip).join(",\n ")}]"
|
47
|
+
else
|
48
|
+
s
|
49
|
+
end
|
50
|
+
}
|
37
51
|
end
|
38
52
|
|
39
53
|
def all_files
|
@@ -130,9 +144,27 @@ end
|
|
130
144
|
|
131
145
|
end # of gem namespace
|
132
146
|
|
133
|
-
desc 'Run tests'
|
147
|
+
desc 'Run tests in memory'
|
134
148
|
task :test do
|
135
|
-
|
149
|
+
require 'bacon'
|
150
|
+
Bacon.extend(Bacon::TestUnitOutput)
|
151
|
+
Bacon.summary_on_exit
|
152
|
+
$LOAD_PATH.unshift('lib')
|
153
|
+
Dir['test/test_*.rb'].each{ |file| load file }
|
154
|
+
end
|
155
|
+
|
156
|
+
desc 'Run tests with shell'
|
157
|
+
task 'test:shell', :RUBY_OPTS do |t, args|
|
158
|
+
files = unless defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby'
|
159
|
+
'test/test_*.rb'
|
160
|
+
else
|
161
|
+
Dir['test/test_*.rb'].join(' ')
|
162
|
+
end
|
163
|
+
|
164
|
+
cmd = [Gem.ruby, args[:RUBY_OPTS],
|
165
|
+
'-I', 'lib', '-S', 'bacon', '--quiet', files]
|
166
|
+
|
167
|
+
sh(cmd.compact.join(' '))
|
136
168
|
end
|
137
169
|
|
138
170
|
desc 'Generate rdoc'
|
@@ -148,8 +180,6 @@ task :clean => ['gem:spec'] do
|
|
148
180
|
Gemgem.ignored_files.each{ |file| sh "mv #{file} #{trash}" }
|
149
181
|
end
|
150
182
|
|
151
|
-
|
152
183
|
task :default do
|
153
|
-
|
154
|
-
Rake.application.display_tasks_and_comments
|
184
|
+
puts `#{Gem.ruby} -S #{$PROGRAM_NAME} -T`
|
155
185
|
end
|
data/test/common.rb
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
require 'rubygems' if RUBY_VERSION < '1.9.1'
|
4
3
|
require 'cerealize'
|
5
4
|
|
5
|
+
require 'bacon'
|
6
|
+
|
6
7
|
require_relative 'stub'
|
7
8
|
require_relative 'real'
|
8
9
|
|
9
|
-
|
10
|
+
Bacon.summary_on_exit
|
10
11
|
|
11
12
|
def set_encoding(encoding)
|
12
13
|
Boat.cerealize_option[:captain] = {:class => nil,
|
data/test/real.rb
CHANGED
data/test/stub.rb
CHANGED
@@ -10,9 +10,11 @@ class Person
|
|
10
10
|
attr_accessor(*ATTR)
|
11
11
|
|
12
12
|
def ==(other)
|
13
|
+
return false if other.class != self.class
|
13
14
|
ATTR.all?{|m| send(m) == other.send(m) }
|
14
15
|
end
|
15
16
|
def eql?(other)
|
17
|
+
return false if other.class != self.class
|
16
18
|
ATTR.all?{|m| send(m).eql? other.send(m) }
|
17
19
|
end
|
18
20
|
end
|
data/test/test_all_codec.rb
CHANGED
@@ -8,17 +8,14 @@ end
|
|
8
8
|
|
9
9
|
require_relative 'common'
|
10
10
|
|
11
|
-
|
12
|
-
|
11
|
+
describe Cerealize do
|
12
|
+
before do
|
13
13
|
Boat.delete_all
|
14
14
|
end
|
15
15
|
|
16
|
-
def teardown
|
17
|
-
end
|
18
|
-
|
19
16
|
Cerealize.codec_names.each do |encoding|
|
20
17
|
|
21
|
-
|
18
|
+
should "#{encoding} basic" do
|
22
19
|
set_encoding(encoding)
|
23
20
|
|
24
21
|
b = Boat.create(:name => 'pequod')
|
@@ -27,39 +24,39 @@ class AllCodecTest < Test::Unit::TestCase
|
|
27
24
|
b.save!
|
28
25
|
|
29
26
|
b = Boat.find_by_name('pequod')
|
30
|
-
|
31
|
-
|
27
|
+
b.captain.class.should.equal Person
|
28
|
+
b.captain.name .should.equal 'ahab'
|
32
29
|
|
33
30
|
b.captain = Person.new('ishmael') # make sure not frozen!
|
34
|
-
|
31
|
+
b.captain.name.should.equal 'ishmael'
|
35
32
|
b.captain.name = 'call me ishmael'
|
36
33
|
b.save!
|
37
34
|
|
38
35
|
b = Boat.find_by_name('pequod')
|
39
|
-
|
36
|
+
b.captain.name.should.equal 'call me ishmael'
|
40
37
|
end
|
41
38
|
|
42
39
|
['string', {:key1 => 'v', :key2 => [3,4]}].each do |captain|
|
43
|
-
|
40
|
+
should "#{encoding} for #{captain}_changed?" do
|
44
41
|
b = Boat.create(:captain => captain)
|
45
|
-
|
42
|
+
b.changed?.should.equal false
|
46
43
|
b.captain = b.captain
|
47
|
-
|
44
|
+
b.changed?.should.equal false
|
48
45
|
b.captain = captain
|
49
|
-
|
46
|
+
b.changed?.should.equal false
|
50
47
|
b.captain = captain.dup
|
51
|
-
|
48
|
+
b.changed?.should.equal false
|
52
49
|
b.captain = case captain
|
53
50
|
when String; captain.reverse
|
54
51
|
when Hash; captain.merge(:key2 => [1,2])
|
55
52
|
end
|
56
|
-
|
53
|
+
b.changed?.should.equal true
|
57
54
|
end
|
58
55
|
end
|
59
56
|
|
60
57
|
[ :none, :read, :read_write, :write ].each do |action|
|
61
58
|
|
62
|
-
|
59
|
+
should "#{encoding} partial update #{action}" do
|
63
60
|
set_encoding(encoding)
|
64
61
|
|
65
62
|
Boat.delete_all
|
@@ -85,39 +82,38 @@ class AllCodecTest < Test::Unit::TestCase
|
|
85
82
|
|
86
83
|
b3 = Boat.find_by_name 'titanic'
|
87
84
|
if [:read_write, :write].include?(action)
|
88
|
-
|
85
|
+
b3.captain.name.should.equal 'dawson'
|
89
86
|
elsif action == :none
|
90
|
-
|
87
|
+
b3.captain.name.should.equal 'rose'
|
91
88
|
elsif action == :read
|
92
|
-
|
93
|
-
"captain.name is #{b3.captain.name}"
|
89
|
+
%w{ rose dawson }.should.include?(b3.captain.name)
|
94
90
|
end
|
95
91
|
end
|
96
92
|
end
|
97
93
|
|
98
|
-
|
94
|
+
should "#{encoding} just save" do
|
99
95
|
set_encoding(encoding)
|
100
96
|
b1 = Boat.new :name => 'alinghi'
|
101
97
|
b1.save!
|
102
|
-
|
98
|
+
Boat.find_by_name('alinghi').captain.should.equal nil
|
103
99
|
end
|
104
100
|
|
105
|
-
|
101
|
+
should "#{encoding} just save writing" do
|
106
102
|
set_encoding(encoding)
|
107
103
|
b1 = Boat.new :name => 'surprise'
|
108
104
|
b1.captain = Person.new 'aubrey'
|
109
105
|
b1.save!
|
110
|
-
|
106
|
+
Boat.find_by_name('surprise').captain.name.should.equal 'aubrey'
|
111
107
|
end
|
112
108
|
|
113
|
-
|
109
|
+
should "#{encoding} just reading" do
|
114
110
|
set_encoding(encoding)
|
115
111
|
b1 = Boat.create :name => 'black pearl', :captain => Person.new('sparrow')
|
116
112
|
b2 = Boat.find_by_name 'black pearl'
|
117
|
-
|
113
|
+
b2.captain.name.should.equal 'sparrow'
|
118
114
|
end
|
119
115
|
|
120
|
-
|
116
|
+
should "#{encoding} deep change" do
|
121
117
|
set_encoding(encoding)
|
122
118
|
b1 = Boat.create :name => 'bounty', :captain => (Person.new('bligh'))
|
123
119
|
|
@@ -125,10 +121,10 @@ class AllCodecTest < Test::Unit::TestCase
|
|
125
121
|
b2.captain.hat = Hat.new('blue')
|
126
122
|
b2.save!
|
127
123
|
|
128
|
-
|
124
|
+
Boat.find_by_name('bounty').captain.hat.color.should.equal 'blue'
|
129
125
|
end
|
130
126
|
|
131
|
-
|
127
|
+
should "#{encoding} deeper change object" do
|
132
128
|
set_encoding(encoding)
|
133
129
|
b1 = Boat.create :name => 'bounty', :captain => (Person.new('bligh'))
|
134
130
|
|
@@ -140,10 +136,10 @@ class AllCodecTest < Test::Unit::TestCase
|
|
140
136
|
b2.captain.pocket << :francs
|
141
137
|
b2.save!
|
142
138
|
|
143
|
-
|
139
|
+
Boat.find_by_name('bounty').captain.pocket.should.equal [:pounds, :francs]
|
144
140
|
end
|
145
141
|
|
146
|
-
|
142
|
+
should "#{encoding} deeper change hash" do
|
147
143
|
set_encoding(encoding)
|
148
144
|
b1 = Boat.create :name => 'bounty', :captain => { :name => :bligh }
|
149
145
|
|
@@ -155,77 +151,76 @@ class AllCodecTest < Test::Unit::TestCase
|
|
155
151
|
b2.captain[:pocket] << :francs
|
156
152
|
b2.save!
|
157
153
|
|
158
|
-
|
154
|
+
Boat.find_by_name('bounty').captain[:pocket].should.equal [:pounds, :francs]
|
159
155
|
end
|
160
156
|
|
161
157
|
|
162
|
-
|
158
|
+
should "#{encoding} class checking" do
|
163
159
|
set_encoding(encoding)
|
164
160
|
Boat.create :name => 'lollypop', :cargo => Blob.new
|
165
161
|
Boat.find_by_name 'lollypop'
|
166
162
|
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
end
|
163
|
+
lambda{
|
164
|
+
Boat.create(:name => 'minerva', :cargo => "WRONG KIND").cargo
|
165
|
+
}.should.raise ActiveRecord::SerializationTypeMismatch
|
171
166
|
end
|
172
167
|
|
173
|
-
|
168
|
+
should "#{encoding} simple hash" do
|
174
169
|
set_encoding(encoding)
|
175
170
|
b = Boat.new
|
176
171
|
h = { :name => 'skipper' }
|
177
172
|
b.captain = h
|
178
|
-
|
173
|
+
b.captain.should.equal h
|
179
174
|
b.save
|
180
|
-
|
175
|
+
b.captain.should.equal h
|
181
176
|
b.captain[:actor] = 'alan hale'
|
182
|
-
|
177
|
+
b.captain[:actor].should.equal 'alan hale'
|
183
178
|
end
|
184
179
|
|
185
|
-
|
180
|
+
should "#{encoding} check if really saved" do
|
186
181
|
set_encoding(encoding)
|
187
182
|
b = Boat.new
|
188
183
|
b.captain = { :name => 'ramius' }
|
189
184
|
b.save
|
190
185
|
|
191
186
|
b2 = Boat.find(b.id)
|
192
|
-
|
187
|
+
b2.captain.should.equal b.captain
|
193
188
|
b2.captain[:nationality] = 'russian'
|
194
189
|
b2.save
|
195
190
|
|
196
191
|
b3 = Boat.find(b2.id)
|
197
|
-
|
192
|
+
b3.captain[:nationality].should.equal 'russian'
|
198
193
|
end
|
199
194
|
|
200
|
-
|
195
|
+
should "#{encoding} array cerealize" do
|
201
196
|
set_encoding(encoding)
|
202
197
|
b = Boat.new
|
203
198
|
b.captain = [123, 456]
|
204
199
|
b.save
|
205
|
-
|
206
|
-
|
200
|
+
b.captain.should.equal [123, 456]
|
201
|
+
Boat.find(b.id).captain.should.equal [123, 456]
|
207
202
|
end
|
208
203
|
|
209
|
-
|
204
|
+
should "#{encoding} repeated saves" do
|
210
205
|
set_encoding(encoding)
|
211
206
|
b = Boat.new
|
212
207
|
b.captain = { :name => 'kirk', :age => 23 }
|
213
208
|
b.save
|
214
209
|
|
215
|
-
|
216
|
-
|
210
|
+
b.captain[:age].should.equal 23
|
211
|
+
Boat.first.captain[:age].should.equal 23
|
217
212
|
|
218
213
|
b.captain[:age] += 1
|
219
214
|
b.save
|
220
|
-
|
221
|
-
|
215
|
+
b.captain[:age].should.equal 24
|
216
|
+
Boat.first.captain[:age].should.equal 24
|
222
217
|
|
223
218
|
b.captain[:age] += 1
|
224
219
|
b.save
|
225
220
|
b.captain[:age] += 1
|
226
221
|
b.save
|
227
|
-
|
228
|
-
|
222
|
+
b.captain[:age].should.equal 26
|
223
|
+
Boat.first.captain[:age].should.equal 26
|
229
224
|
|
230
225
|
b.captain[:age] += 1
|
231
226
|
b.save
|
@@ -233,8 +228,8 @@ class AllCodecTest < Test::Unit::TestCase
|
|
233
228
|
b.save
|
234
229
|
b.captain[:age] += 1
|
235
230
|
b.save
|
236
|
-
|
237
|
-
|
231
|
+
b.captain[:age].should.equal 29
|
232
|
+
Boat.first.captain[:age].should.equal 29
|
238
233
|
|
239
234
|
end
|
240
235
|
end
|
data/test/test_attr_hash.rb
CHANGED
@@ -7,8 +7,14 @@ end
|
|
7
7
|
|
8
8
|
require_relative 'common'
|
9
9
|
|
10
|
-
|
11
|
-
def
|
10
|
+
describe 'attr_hash' do
|
11
|
+
def simple_case hh, ah
|
12
|
+
ah.name.should.equal hh[:name]
|
13
|
+
ah.size.should.equal hh[:size]
|
14
|
+
ah.data.should.equal hh
|
15
|
+
end
|
16
|
+
|
17
|
+
should 'simple' do
|
12
18
|
hh = {:name => 'wane', :size => 123456}
|
13
19
|
ah = Apple.new(hh)
|
14
20
|
|
@@ -20,29 +26,23 @@ class AttrHashTest < Test::Unit::TestCase
|
|
20
26
|
simple_case(hh, ah)
|
21
27
|
end
|
22
28
|
|
23
|
-
|
24
|
-
|
25
|
-
|
29
|
+
should 'nil' do
|
30
|
+
Apple.new.name.should.equal nil
|
31
|
+
Apple.new.data.should.equal nil
|
26
32
|
end
|
27
33
|
|
28
|
-
|
34
|
+
should 'dont save twice' do
|
29
35
|
apple = Apple.create(:name => 'banana')
|
30
|
-
|
36
|
+
apple.updated_at.should.not.equal nil
|
31
37
|
|
32
38
|
Apple.record_timestamps = false
|
33
39
|
apple.update_attributes(:updated_at => nil)
|
34
40
|
Apple.record_timestamps = true
|
35
41
|
apple2 = Apple.find(apple.id)
|
36
|
-
|
42
|
+
apple2.updated_at.should.equal nil
|
37
43
|
apple2.update_attributes :name => 'banana'
|
38
|
-
|
44
|
+
apple2.updated_at.should.equal nil
|
39
45
|
apple2.update_attributes :name => 'pineapple'
|
40
|
-
|
41
|
-
end
|
42
|
-
|
43
|
-
def simple_case hh, ah
|
44
|
-
assert_equal hh[:name], ah.name
|
45
|
-
assert_equal hh[:size], ah.size
|
46
|
-
assert_equal hh , ah.data
|
46
|
+
apple2.updated_at.should.not.equal nil
|
47
47
|
end
|
48
48
|
end
|
data/test/test_basic.rb
CHANGED
@@ -8,91 +8,90 @@ end
|
|
8
8
|
|
9
9
|
require_relative 'common'
|
10
10
|
|
11
|
-
|
12
|
-
|
11
|
+
describe Cerealize do
|
12
|
+
before do
|
13
13
|
Boat.delete_all
|
14
14
|
end
|
15
15
|
|
16
|
-
|
16
|
+
should 'no conflict' do
|
17
|
+
Cat.respond_to?(:captain).should.equal false
|
18
|
+
Boat.respond_to?(:food) .should.equal false
|
17
19
|
end
|
18
20
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
end
|
23
|
-
|
24
|
-
def test_cerealize_module
|
25
|
-
assert Cat < Cat::CerealizeMethods
|
26
|
-
assert Boat < Boat::CerealizeMethods
|
21
|
+
should 'cerealize module' do
|
22
|
+
( Cat < Cat::CerealizeMethods).should.equal true
|
23
|
+
(Boat < Boat::CerealizeMethods).should.equal true
|
27
24
|
|
28
|
-
|
29
|
-
|
25
|
+
( Cat < Boat::CerealizeMethods).should.equal nil
|
26
|
+
(Boat < Cat::CerealizeMethods).should.equal nil
|
30
27
|
end
|
31
28
|
|
32
|
-
|
33
|
-
|
34
|
-
|
29
|
+
|
30
|
+
should 'super calling' do
|
31
|
+
Dog.new.mood .should.equal 'mood: '
|
32
|
+
Dog.new(:mood => 'cheerful').mood.should.equal 'mood: cheerful'
|
35
33
|
end
|
36
34
|
|
37
|
-
|
35
|
+
should 'setting nil in hash' do
|
38
36
|
apple = Apple.create(:data => {:name => 'pine'})
|
39
|
-
|
40
|
-
|
37
|
+
apple.data.should.equal({:name => 'pine'})
|
38
|
+
apple.name.should.equal 'pine'
|
41
39
|
apple.data[:name] = nil
|
42
|
-
|
40
|
+
apple.name.should.equal nil
|
43
41
|
apple.save; apple.reload
|
44
|
-
|
45
|
-
|
42
|
+
apple.name.should.equal nil
|
43
|
+
apple.data.should.equal({:name => nil})
|
46
44
|
end
|
47
45
|
|
48
|
-
|
46
|
+
should 'save nil' do
|
49
47
|
apple = Apple.find(Apple.create(:data => [5]).id)
|
50
|
-
|
48
|
+
apple.data.should.equal [5]
|
51
49
|
apple.update_attributes(:data => nil)
|
52
|
-
|
53
|
-
|
50
|
+
apple.data.should.equal nil
|
51
|
+
Apple.find(apple.id).data.should.equal nil
|
54
52
|
end
|
55
53
|
|
56
|
-
|
54
|
+
should 'encoding yaml' do
|
57
55
|
set_encoding(:yaml)
|
58
56
|
Boat.create :name => 'yamato', :captain => Person.new('kosaku')
|
59
57
|
s = Boat.connection.select_value("SELECT captain FROM boats WHERE name='yamato';")
|
60
|
-
|
58
|
+
s[0..2].should.equal '---'
|
61
59
|
end
|
62
60
|
|
63
|
-
|
61
|
+
should 'encoding marshal' do
|
64
62
|
set_encoding(:marshal)
|
65
63
|
Boat.create :name => 'santa maria', :captain => Person.new('columbus')
|
66
64
|
s = Boat.connection.select_value("SELECT captain FROM boats WHERE name='santa maria';")
|
67
|
-
|
65
|
+
s[0..1].should.equal 'BA'
|
68
66
|
end
|
69
67
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
68
|
+
should 'cerealize option' do
|
69
|
+
Cat.cerealize_option.should.equal(
|
70
|
+
{:name => {:class => String,
|
71
|
+
:encoding => :yaml,
|
72
|
+
:codec => Cerealize::Codec::Yaml},
|
73
|
+
|
74
|
+
:tail => {:class => Array,
|
75
|
+
:encoding => :marshal,
|
76
|
+
:codec => Cerealize::Codec::Marshal,
|
77
|
+
:force_encoding => true},
|
78
|
+
|
79
|
+
:food => {:class => Hash,
|
80
|
+
:encoding => :marshal,
|
81
|
+
:codec => Cerealize::Codec::Marshal,
|
82
|
+
:force_encoding => false}})
|
85
83
|
end
|
86
84
|
|
87
|
-
|
85
|
+
should 'inheritance' do
|
88
86
|
mood = {:mood => {:class => String,
|
89
87
|
:encoding => :marshal,
|
90
88
|
:codec => Cerealize::Codec::Marshal}}
|
91
89
|
hook = {:hook => {:class => Integer,
|
92
90
|
:encoding => :marshal,
|
93
91
|
:codec => Cerealize::Codec::Marshal}}
|
94
|
-
|
95
|
-
|
92
|
+
Dog.cerealize_option.should.equal mood.merge(hook)
|
93
|
+
BigDog.cerealize_option.should.equal mood.merge(hook)
|
96
94
|
end
|
97
95
|
|
96
|
+
|
98
97
|
end
|
data/test/test_transcode.rb
CHANGED
@@ -8,31 +8,26 @@ end
|
|
8
8
|
|
9
9
|
require_relative 'common'
|
10
10
|
|
11
|
-
|
12
|
-
|
11
|
+
describe Cerealize do
|
12
|
+
before do
|
13
13
|
Cat.delete_all
|
14
14
|
end
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
def test_no_such_codec
|
20
|
-
assert_raise Cerealize::NoSuchCodec do
|
16
|
+
should 'no such codec' do
|
17
|
+
lambda{
|
21
18
|
Cat.dup.send(:cerealize, :bad, Hash, :encoding => :blah)
|
22
|
-
|
19
|
+
}.should.raise(Cerealize::NoSuchCodec)
|
23
20
|
end
|
24
21
|
|
25
|
-
|
22
|
+
should 'no suitable codec if force encoding' do
|
26
23
|
cat = Cat.new
|
27
24
|
cat[:tail] = '---'
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
Cat.find(id).tail
|
32
|
-
end
|
25
|
+
lambda{
|
26
|
+
cat.tail
|
27
|
+
}.should.raise(Cerealize::NoSuitableCodec)
|
33
28
|
end
|
34
29
|
|
35
|
-
|
30
|
+
should 'auto transcode yaml' do
|
36
31
|
name = 'Nine Tails'
|
37
32
|
marshaled_name = Cerealize::Codec::Marshal.encode(name)
|
38
33
|
cat = Cat.new
|
@@ -41,20 +36,20 @@ class TranscodeTest < Test::Unit::TestCase
|
|
41
36
|
id = cat.id
|
42
37
|
|
43
38
|
new_cat = Cat.find(id)
|
44
|
-
|
39
|
+
new_cat.name.should.equal name
|
45
40
|
new_cat.name.reverse!
|
46
41
|
|
47
42
|
# no change if not saved yet
|
48
|
-
|
43
|
+
new_cat[:name].should.equal marshaled_name
|
49
44
|
new_cat.save
|
50
45
|
|
51
46
|
# should be transcode into YAML
|
52
|
-
|
47
|
+
Cerealize::Codec::Yaml.yours?(new_cat[:name]).should.equal true
|
53
48
|
new_cat.reload
|
54
|
-
|
49
|
+
Cerealize::Codec::Yaml.yours?(new_cat[:name]).should.equal true
|
55
50
|
end
|
56
51
|
|
57
|
-
|
52
|
+
should 'auto transcode marshal' do
|
58
53
|
food = {:a => :b}
|
59
54
|
yamled_food = Cerealize::Codec::Yaml.encode(food)
|
60
55
|
cat = Cat.new
|
@@ -62,13 +57,13 @@ class TranscodeTest < Test::Unit::TestCase
|
|
62
57
|
cat.save
|
63
58
|
cat.reload
|
64
59
|
|
65
|
-
|
66
|
-
|
60
|
+
cat .food .should.equal food
|
61
|
+
cat[:food].should.equal yamled_food
|
67
62
|
cat.food.merge!(:c => :d)
|
68
63
|
cat.save
|
69
64
|
cat.reload
|
70
65
|
|
71
|
-
|
72
|
-
|
66
|
+
Cerealize::Codec::Marshal.yours?(cat[:food]).should.equal true
|
67
|
+
cat.food.should.equal food.merge(:c => :d)
|
73
68
|
end
|
74
69
|
end
|
metadata
CHANGED
@@ -1,64 +1,70 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: cerealize
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
6
|
-
- 0
|
7
|
-
- 9
|
8
|
-
- 0
|
9
|
-
version: 0.9.0
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
10
6
|
platform: ruby
|
11
|
-
authors:
|
7
|
+
authors:
|
12
8
|
- Cardinal Blue
|
13
9
|
- Lin Jen-Shin (godfat)
|
14
10
|
- Jaime Cham
|
15
11
|
autorequire:
|
16
12
|
bindir: bin
|
17
13
|
cert_chain: []
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
dependencies:
|
22
|
-
- !ruby/object:Gem::Dependency
|
14
|
+
date: 2011-06-29 00:00:00.000000000Z
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
23
17
|
name: activerecord
|
24
|
-
|
25
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
18
|
+
requirement: &2152593320 !ruby/object:Gem::Requirement
|
26
19
|
none: false
|
27
|
-
requirements:
|
28
|
-
- -
|
29
|
-
- !ruby/object:Gem::Version
|
30
|
-
|
31
|
-
- 3
|
32
|
-
version: "3"
|
20
|
+
requirements:
|
21
|
+
- - ! '>='
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: '0'
|
33
24
|
type: :runtime
|
34
|
-
version_requirements: *id001
|
35
|
-
- !ruby/object:Gem::Dependency
|
36
|
-
name: sqlite3
|
37
25
|
prerelease: false
|
38
|
-
|
26
|
+
version_requirements: *2152593320
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bacon
|
29
|
+
requirement: &2152592600 !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
31
|
+
requirements:
|
32
|
+
- - ! '>='
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: *2152592600
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: sqlite3
|
40
|
+
requirement: &2152591980 !ruby/object:Gem::Requirement
|
39
41
|
none: false
|
40
|
-
requirements:
|
41
|
-
- -
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
|
44
|
-
- 0
|
45
|
-
version: "0"
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
46
|
type: :development
|
47
|
-
|
48
|
-
|
49
|
-
|
47
|
+
prerelease: false
|
48
|
+
version_requirements: *2152591980
|
49
|
+
description: ! " Serialize out of the Cerealize Box - a drop-in replacement for ActiveRecord's
|
50
|
+
serialize\n\n It can auto transcode old encoding (yaml if you're using AR's serialize),\n
|
51
|
+
to new encoding (marshal, json, you name it) without any migration."
|
52
|
+
email:
|
50
53
|
- dev (XD) cardinalblue.com
|
51
54
|
executables: []
|
52
|
-
|
53
55
|
extensions: []
|
54
|
-
|
55
|
-
extra_rdoc_files:
|
56
|
+
extra_rdoc_files:
|
56
57
|
- CHANGES
|
58
|
+
- CONTRIBUTORS
|
57
59
|
- LICENSE
|
58
60
|
- TODO
|
59
|
-
files:
|
61
|
+
files:
|
60
62
|
- .gitignore
|
63
|
+
- .gitmodules
|
64
|
+
- .travis.yml
|
61
65
|
- CHANGES
|
66
|
+
- CONTRIBUTORS
|
67
|
+
- Gemfile
|
62
68
|
- LICENSE
|
63
69
|
- README
|
64
70
|
- README.rdoc
|
@@ -74,6 +80,8 @@ files:
|
|
74
80
|
- lib/cerealize/codec/text.rb
|
75
81
|
- lib/cerealize/codec/yaml.rb
|
76
82
|
- lib/cerealize/version.rb
|
83
|
+
- rrr.rb
|
84
|
+
- task/.gitignore
|
77
85
|
- task/gemgem.rb
|
78
86
|
- test/common.rb
|
79
87
|
- test/real.rb
|
@@ -82,40 +90,34 @@ files:
|
|
82
90
|
- test/test_attr_hash.rb
|
83
91
|
- test/test_basic.rb
|
84
92
|
- test/test_transcode.rb
|
85
|
-
|
86
|
-
homepage: http://github.com/godfat/
|
93
|
+
homepage: https://github.com/cardinalblue/cerealize
|
87
94
|
licenses: []
|
88
|
-
|
89
95
|
post_install_message:
|
90
|
-
rdoc_options:
|
96
|
+
rdoc_options:
|
91
97
|
- --main
|
92
98
|
- README
|
93
|
-
require_paths:
|
99
|
+
require_paths:
|
94
100
|
- lib
|
95
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
101
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
96
102
|
none: false
|
97
|
-
requirements:
|
98
|
-
- -
|
99
|
-
- !ruby/object:Gem::Version
|
100
|
-
|
101
|
-
|
102
|
-
version: "0"
|
103
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - ! '>='
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
108
|
none: false
|
105
|
-
requirements:
|
106
|
-
- -
|
107
|
-
- !ruby/object:Gem::Version
|
108
|
-
|
109
|
-
- 0
|
110
|
-
version: "0"
|
109
|
+
requirements:
|
110
|
+
- - ! '>='
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: '0'
|
111
113
|
requirements: []
|
112
|
-
|
113
114
|
rubyforge_project:
|
114
|
-
rubygems_version: 1.
|
115
|
+
rubygems_version: 1.8.5
|
115
116
|
signing_key:
|
116
117
|
specification_version: 3
|
117
|
-
summary: Serialize out of the Cerealize Box - a drop-in replacement for ActiveRecord's
|
118
|
-
|
118
|
+
summary: Serialize out of the Cerealize Box - a drop-in replacement for ActiveRecord's
|
119
|
+
serialize
|
120
|
+
test_files:
|
119
121
|
- test/test_all_codec.rb
|
120
122
|
- test/test_attr_hash.rb
|
121
123
|
- test/test_basic.rb
|