acts_as_serializable 0.1.2 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -60,7 +60,7 @@ begin
60
60
 
61
61
  task :test do
62
62
  Rake::Task[:spec].invoke
63
- Rake::Task[:features].invoke
63
+ # Rake::Task[:features].invoke
64
64
  end
65
65
 
66
66
  desc "Run tests with RCov"
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.2
1
+ 0.1.5
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{acts_as_serializable}
5
- s.version = "0.1.2"
5
+ s.version = "0.1.5"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Birkir A. Barkarson"]
9
- s.date = %q{2009-06-11}
9
+ s.date = %q{2009-06-16}
10
10
  s.description = %q{Easy versioning of serialization methods}
11
11
  s.email = %q{birkirb@stoicviking.net}
12
12
  s.extra_rdoc_files = [
@@ -20,12 +20,12 @@ Gem::Specification.new do |s|
20
20
  "acts_as_serializable.gemspec",
21
21
  "init.rb",
22
22
  "lib/acts_as_serializable.rb",
23
- "lib/version.rb",
24
- "lib/versions.rb",
23
+ "lib/serializable/version.rb",
24
+ "lib/serializable/versions.rb",
25
25
  "spec/acts_as_serializable_spec.rb",
26
- "spec/app/serializations/test_rails_model/test_rails_model/version_1_0_0.rb",
27
- "spec/app/serializations/test_rails_model/test_rails_model/version_1_5.rb",
28
- "spec/app/serializations/test_rails_model/test_rails_model/version_2_1.rb",
26
+ "spec/app/serializations/test_rails_model/version_1_0_0.rb",
27
+ "spec/app/serializations/test_rails_model/version_1_5.rb",
28
+ "spec/app/serializations/test_rails_model/version_2_1.rb",
29
29
  "spec/serializations/test_model/version_1_0_0.rb",
30
30
  "spec/serializations/test_model/version_1_5.rb",
31
31
  "spec/serializations/test_model/version_2_1.rb",
@@ -48,9 +48,9 @@ Gem::Specification.new do |s|
48
48
  "spec/serializations/test_model/version_1_0_0.rb",
49
49
  "spec/serializations/test_model/version_2_1.rb",
50
50
  "spec/serializations/test_model/version_1_5.rb",
51
- "spec/app/serializations/test_rails_model/test_rails_model/version_1_0_0.rb",
52
- "spec/app/serializations/test_rails_model/test_rails_model/version_2_1.rb",
53
- "spec/app/serializations/test_rails_model/test_rails_model/version_1_5.rb"
51
+ "spec/app/serializations/test_rails_model/version_1_0_0.rb",
52
+ "spec/app/serializations/test_rails_model/version_2_1.rb",
53
+ "spec/app/serializations/test_rails_model/version_1_5.rb"
54
54
  ]
55
55
 
56
56
  if s.respond_to? :specification_version then
@@ -1,4 +1,3 @@
1
- require 'builder/xmlmarkup'
2
1
  require 'jsonbuilder'
3
2
  require 'active_support'
4
3
  require 'find'
@@ -33,7 +32,7 @@ module Serializable
33
32
  Find.find(serialization_directory) do |path|
34
33
  if File.file?(path) && versioned_klass = path.match(SERIALIZED_CLASS_NAME_REGEXP)
35
34
  require path
36
- klass = Serializable.const_get("#{klass_name}").const_get("Version_#{versioned_klass[1]}")
35
+ klass = Serializations.const_get("#{klass_name}").const_get("Version_#{versioned_klass[1]}")
37
36
  if klass && klass.respond_to?(:serialize)
38
37
  define_local_serialization_method(versioned_klass[1])
39
38
  end
@@ -72,7 +71,7 @@ module Serializable
72
71
  def define_local_serialization_method(method_version)
73
72
  class_eval <<-EOV
74
73
  def serialize_to_version_#{method_version}(builder, options)
75
- Serializable::#{self.name}::Version_#{method_version}.serialize(self, builder, options)
74
+ Serializations::#{self.name}::Version_#{method_version}.serialize(self, builder, options)
76
75
  end
77
76
  EOV
78
77
  @serialization_versions << Version.new(method_version)
@@ -92,11 +91,11 @@ module Serializable
92
91
  # This module contains instance methods
93
92
  module InstanceMethods
94
93
  def to_hash(options = {})
95
- serialize(Builder::Hash.new, options)
94
+ serialize(Builder::HashStructure.new, options)
96
95
  end
97
96
 
98
97
  def to_json(options = {})
99
- serialize(Builder::Json.new, options)
98
+ serialize(Builder::JsonFormat.new, options).to_json
100
99
  end
101
100
 
102
101
  def to_xml(options = {})
@@ -118,6 +117,10 @@ module Serializable
118
117
  end
119
118
  end
120
119
  end
120
+
121
+ def serialize_for(builder, options = {})
122
+ self.send(builder.serialization_method!, options)
123
+ end
121
124
  end
122
125
 
123
126
  end
File without changes
File without changes
@@ -23,7 +23,7 @@ class WithSerialize < SerializableObject
23
23
  acts_as_serializable
24
24
 
25
25
  def serialize(builder, options)
26
- builder
26
+ builder.test('value')
27
27
  end
28
28
  end
29
29
 
@@ -65,22 +65,21 @@ describe Serializable, 'if included in a class, then that class' do
65
65
 
66
66
  context 'with the serialized method overriden to return the builder' do
67
67
 
68
- it '#to_xml should return an Builder::XmlMarkup' do
68
+ it '#to_xml should return an Builder::XmlMarkup serialization' do
69
69
  klass = WithSerialize.new
70
- klass.to_xml.test.should == "<test/>"
70
+ klass.to_xml.should == "<test>value</test>"
71
71
  end
72
72
 
73
- it '#to_hash should return an Builder::Hash' do
73
+ it '#to_hash should return an Builder::HashStructure serialization' do
74
74
  klass = WithSerialize.new
75
- klass.to_hash.test('value').should == 'value'
75
+ klass.to_hash.should == 'value'
76
76
  end
77
77
 
78
- it '#to_json should return an Builder::Json' do
78
+ it '#to_json should return an Builder::JsonFormat serialization' do
79
79
  klass = WithSerialize.new
80
- klass.to_json.test('value').should == '"value"'
80
+ klass.to_json.should == '"value"'
81
81
  end
82
82
  end
83
-
84
83
  end
85
84
 
86
85
  describe Serializable, 'when included in a class that has multiple versioned serialization methods' do
@@ -91,7 +90,7 @@ describe Serializable, 'when included in a class that has multiple versioned ser
91
90
  klass = SerializableObject.new
92
91
 
93
92
  klass.to_xml(:version => '1.0.0').should == "This is version 1.0.0"
94
- klass.to_json(:version => '1.5.0').should == "This is version 1.5.0"
93
+ klass.to_json(:version => '1.5.0').should == "\"This is version 1.5.0\""
95
94
  klass.to_hash(:version => '2.1.0').should == "This is version 2.1"
96
95
  end
97
96
 
@@ -99,7 +98,7 @@ describe Serializable, 'when included in a class that has multiple versioned ser
99
98
  klass = SerializableObject.new
100
99
 
101
100
  klass.to_xml(:version => '1.4.0').should == "This is version 1.0.0"
102
- klass.to_json(:version => '3.1.0').should == "This is version 2.1"
101
+ klass.to_json(:version => '3.1.0').should == "\"This is version 2.1\""
103
102
  end
104
103
 
105
104
  it 'should raise an error if no corresponding version exists' do
@@ -107,6 +106,14 @@ describe Serializable, 'when included in a class that has multiple versioned ser
107
106
 
108
107
  lambda { klass.to_hash(:version => '0.1.0') }.should raise_error(RuntimeError, "Version 0.1.0 given but no serialization method found")
109
108
  end
109
+
110
+ it '#serialize_for should call a to_format methods for a given builder' do
111
+ klass = SerializableObject.new
112
+
113
+ klass.serialize_for(Builder::XmlMarkup.new).should == "This is version 2.1"
114
+ klass.serialize_for(Builder::JsonFormat.new).should == "\"This is version 2.1\""
115
+ klass.serialize_for(Builder::HashStructure.new).should == "This is version 2.1"
116
+ end
110
117
  end
111
118
 
112
119
  context 'and a to_format method is called with no version option' do
@@ -140,7 +147,7 @@ describe Serializable, 'when included in a class that has multiple serialization
140
147
  klass = TestModel.new
141
148
 
142
149
  klass.to_xml(:version => '1.0.0').should == "This is version 1.0.0 for TestModel"
143
- klass.to_json(:version => '1.5.0').should == "This is version 1.5.0 for TestModel"
150
+ klass.to_json(:version => '1.5.0').should == "\"This is version 1.5.0 for TestModel\""
144
151
  klass.to_hash(:version => '2.1.0').should == "This is version 2.1 for TestModel"
145
152
  end
146
153
 
@@ -148,7 +155,7 @@ describe Serializable, 'when included in a class that has multiple serialization
148
155
  klass = TestModel.new
149
156
 
150
157
  klass.to_xml(:version => '1.4.0').should == "This is version 1.0.0 for TestModel"
151
- klass.to_json(:version => '3.1.0').should == "This is version 2.1 for TestModel"
158
+ klass.to_json(:version => '3.1.0').should == "\"This is version 2.1 for TestModel\""
152
159
  end
153
160
 
154
161
  it 'should raise an error if no corresponding version exists' do
@@ -177,7 +184,7 @@ describe Serializable, 'when included in a class that has multiple serialization
177
184
  klass = TestRailsModel.new
178
185
 
179
186
  klass.to_xml(:version => '1.0.0').should == "This is version 1.0.0 for TestRailsModel"
180
- klass.to_json(:version => '1.5.0').should == "This is version 1.5.0 for TestRailsModel"
187
+ klass.to_json(:version => '1.5.0').should == "\"This is version 1.5.0 for TestRailsModel\""
181
188
  klass.to_hash(:version => '2.1.0').should == "This is version 2.1 for TestRailsModel"
182
189
  end
183
190
  end
@@ -1,4 +1,4 @@
1
- module Serializable
1
+ module Serializations
2
2
  module TestRailsModel
3
3
  class Version_1_0_0
4
4
  def self.serialize(test_model, builder, options)
@@ -1,4 +1,4 @@
1
- module Serializable
1
+ module Serializations
2
2
  module TestRailsModel
3
3
  class Version_1_5
4
4
  def self.serialize(test_model, builder, options)
@@ -1,4 +1,4 @@
1
- module Serializable
1
+ module Serializations
2
2
  module TestRailsModel
3
3
  class Version_2_1
4
4
  def self.serialize(test_model, builder, options)
@@ -1,4 +1,4 @@
1
- module Serializable
1
+ module Serializations
2
2
  module TestModel
3
3
  class Version_1_0_0
4
4
  def self.serialize(test_model, builder, options)
@@ -1,4 +1,4 @@
1
- module Serializable
1
+ module Serializations
2
2
  module TestModel
3
3
  class Version_1_5
4
4
  def self.serialize(test_model, builder, options)
@@ -1,4 +1,4 @@
1
- module Serializable
1
+ module Serializations
2
2
  module TestModel
3
3
  class Version_2_1
4
4
  def self.serialize(test_model, builder, options)
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  require 'rubygems'
2
2
  require 'spec'
3
3
 
4
- require 'lib/version'
5
- require 'lib/versions'
4
+ require 'lib/serializable/version'
5
+ require 'lib/serializable/versions'
6
6
  require 'lib/acts_as_serializable'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts_as_serializable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Birkir A. Barkarson
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-06-11 00:00:00 +09:00
12
+ date: 2009-06-16 00:00:00 +09:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -48,12 +48,12 @@ files:
48
48
  - acts_as_serializable.gemspec
49
49
  - init.rb
50
50
  - lib/acts_as_serializable.rb
51
- - lib/version.rb
52
- - lib/versions.rb
51
+ - lib/serializable/version.rb
52
+ - lib/serializable/versions.rb
53
53
  - spec/acts_as_serializable_spec.rb
54
- - spec/app/serializations/test_rails_model/test_rails_model/version_1_0_0.rb
55
- - spec/app/serializations/test_rails_model/test_rails_model/version_1_5.rb
56
- - spec/app/serializations/test_rails_model/test_rails_model/version_2_1.rb
54
+ - spec/app/serializations/test_rails_model/version_1_0_0.rb
55
+ - spec/app/serializations/test_rails_model/version_1_5.rb
56
+ - spec/app/serializations/test_rails_model/version_2_1.rb
57
57
  - spec/serializations/test_model/version_1_0_0.rb
58
58
  - spec/serializations/test_model/version_1_5.rb
59
59
  - spec/serializations/test_model/version_2_1.rb
@@ -94,6 +94,6 @@ test_files:
94
94
  - spec/serializations/test_model/version_1_0_0.rb
95
95
  - spec/serializations/test_model/version_2_1.rb
96
96
  - spec/serializations/test_model/version_1_5.rb
97
- - spec/app/serializations/test_rails_model/test_rails_model/version_1_0_0.rb
98
- - spec/app/serializations/test_rails_model/test_rails_model/version_2_1.rb
99
- - spec/app/serializations/test_rails_model/test_rails_model/version_1_5.rb
97
+ - spec/app/serializations/test_rails_model/version_1_0_0.rb
98
+ - spec/app/serializations/test_rails_model/version_2_1.rb
99
+ - spec/app/serializations/test_rails_model/version_1_5.rb