birkirb-acts_as_serializable 0.1.2 → 0.1.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/Rakefile +1 -1
- data/VERSION +1 -1
- data/acts_as_serializable.gemspec +6 -1
- data/lib/acts_as_serializable.rb +9 -3
- data/lib/builder/hash_structure.rb +7 -0
- data/lib/builder/json_format.rb +7 -0
- data/lib/builder/xml_markup.rb +7 -0
- data/spec/acts_as_serializable_spec.rb +8 -0
- data/spec/builder_patch_spec.rb +19 -0
- metadata +6 -1
data/Rakefile
CHANGED
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.1.
|
|
1
|
+
0.1.4
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Gem::Specification.new do |s|
|
|
4
4
|
s.name = %q{acts_as_serializable}
|
|
5
|
-
s.version = "0.1.
|
|
5
|
+
s.version = "0.1.4"
|
|
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"]
|
|
@@ -20,12 +20,16 @@ Gem::Specification.new do |s|
|
|
|
20
20
|
"acts_as_serializable.gemspec",
|
|
21
21
|
"init.rb",
|
|
22
22
|
"lib/acts_as_serializable.rb",
|
|
23
|
+
"lib/builder/hash_structure.rb",
|
|
24
|
+
"lib/builder/json_format.rb",
|
|
25
|
+
"lib/builder/xml_markup.rb",
|
|
23
26
|
"lib/version.rb",
|
|
24
27
|
"lib/versions.rb",
|
|
25
28
|
"spec/acts_as_serializable_spec.rb",
|
|
26
29
|
"spec/app/serializations/test_rails_model/test_rails_model/version_1_0_0.rb",
|
|
27
30
|
"spec/app/serializations/test_rails_model/test_rails_model/version_1_5.rb",
|
|
28
31
|
"spec/app/serializations/test_rails_model/test_rails_model/version_2_1.rb",
|
|
32
|
+
"spec/builder_patch_spec.rb",
|
|
29
33
|
"spec/serializations/test_model/version_1_0_0.rb",
|
|
30
34
|
"spec/serializations/test_model/version_1_5.rb",
|
|
31
35
|
"spec/serializations/test_model/version_2_1.rb",
|
|
@@ -44,6 +48,7 @@ Gem::Specification.new do |s|
|
|
|
44
48
|
"spec/spec_helper.rb",
|
|
45
49
|
"spec/acts_as_serializable_spec.rb",
|
|
46
50
|
"spec/versions_spec.rb",
|
|
51
|
+
"spec/builder_patch_spec.rb",
|
|
47
52
|
"spec/version_spec.rb",
|
|
48
53
|
"spec/serializations/test_model/version_1_0_0.rb",
|
|
49
54
|
"spec/serializations/test_model/version_2_1.rb",
|
data/lib/acts_as_serializable.rb
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
require 'builder/xmlmarkup'
|
|
2
1
|
require 'jsonbuilder'
|
|
3
2
|
require 'active_support'
|
|
4
3
|
require 'find'
|
|
4
|
+
require File.join(File.dirname(__FILE__), 'builder/xml_markup')
|
|
5
|
+
require File.join(File.dirname(__FILE__), 'builder/json_format')
|
|
6
|
+
require File.join(File.dirname(__FILE__), 'builder/hash_structure')
|
|
5
7
|
|
|
6
8
|
module Serializable
|
|
7
9
|
SERIALIZE_TO_VERSION_REGEXP = /^serialize_to_version_((:?\d+_?)+)$/
|
|
@@ -92,11 +94,11 @@ module Serializable
|
|
|
92
94
|
# This module contains instance methods
|
|
93
95
|
module InstanceMethods
|
|
94
96
|
def to_hash(options = {})
|
|
95
|
-
serialize(Builder::
|
|
97
|
+
serialize(Builder::HashStructure.new, options)
|
|
96
98
|
end
|
|
97
99
|
|
|
98
100
|
def to_json(options = {})
|
|
99
|
-
serialize(Builder::
|
|
101
|
+
serialize(Builder::JsonFormat.new, options)
|
|
100
102
|
end
|
|
101
103
|
|
|
102
104
|
def to_xml(options = {})
|
|
@@ -118,6 +120,10 @@ module Serializable
|
|
|
118
120
|
end
|
|
119
121
|
end
|
|
120
122
|
end
|
|
123
|
+
|
|
124
|
+
def serialize_for(builder, options = {})
|
|
125
|
+
self.send(builder.serialization_method!, options)
|
|
126
|
+
end
|
|
121
127
|
end
|
|
122
128
|
|
|
123
129
|
end
|
|
@@ -107,6 +107,14 @@ describe Serializable, 'when included in a class that has multiple versioned ser
|
|
|
107
107
|
|
|
108
108
|
lambda { klass.to_hash(:version => '0.1.0') }.should raise_error(RuntimeError, "Version 0.1.0 given but no serialization method found")
|
|
109
109
|
end
|
|
110
|
+
|
|
111
|
+
it '#serialize_for should call a to_format methods for a given builder' do
|
|
112
|
+
klass = SerializableObject.new
|
|
113
|
+
|
|
114
|
+
klass.serialize_for(Builder::XmlMarkup.new).should == "This is version 2.1"
|
|
115
|
+
klass.serialize_for(Builder::JsonFormat.new).should == "This is version 2.1"
|
|
116
|
+
klass.serialize_for(Builder::HashStructure.new).should == "This is version 2.1"
|
|
117
|
+
end
|
|
110
118
|
end
|
|
111
119
|
|
|
112
120
|
context 'and a to_format method is called with no version option' do
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
require 'spec/spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Builder::XmlMarkup, 'having been patched' do
|
|
4
|
+
it 'should support #serialization_method' do
|
|
5
|
+
Builder::XmlMarkup.new.serialization_method!.should == :to_xml
|
|
6
|
+
end
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
describe Builder::HashStructure, 'having been patched' do
|
|
10
|
+
it 'should support #serialization_method' do
|
|
11
|
+
Builder::HashStructure.new.serialization_method!.should == :to_hash
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
describe Builder::JsonFormat, 'having been patched' do
|
|
16
|
+
it 'should support #serialization_method' do
|
|
17
|
+
Builder::JsonFormat.new.serialization_method!.should == :to_json
|
|
18
|
+
end
|
|
19
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: birkirb-acts_as_serializable
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Birkir A. Barkarson
|
|
@@ -48,12 +48,16 @@ files:
|
|
|
48
48
|
- acts_as_serializable.gemspec
|
|
49
49
|
- init.rb
|
|
50
50
|
- lib/acts_as_serializable.rb
|
|
51
|
+
- lib/builder/hash_structure.rb
|
|
52
|
+
- lib/builder/json_format.rb
|
|
53
|
+
- lib/builder/xml_markup.rb
|
|
51
54
|
- lib/version.rb
|
|
52
55
|
- lib/versions.rb
|
|
53
56
|
- spec/acts_as_serializable_spec.rb
|
|
54
57
|
- spec/app/serializations/test_rails_model/test_rails_model/version_1_0_0.rb
|
|
55
58
|
- spec/app/serializations/test_rails_model/test_rails_model/version_1_5.rb
|
|
56
59
|
- spec/app/serializations/test_rails_model/test_rails_model/version_2_1.rb
|
|
60
|
+
- spec/builder_patch_spec.rb
|
|
57
61
|
- spec/serializations/test_model/version_1_0_0.rb
|
|
58
62
|
- spec/serializations/test_model/version_1_5.rb
|
|
59
63
|
- spec/serializations/test_model/version_2_1.rb
|
|
@@ -90,6 +94,7 @@ test_files:
|
|
|
90
94
|
- spec/spec_helper.rb
|
|
91
95
|
- spec/acts_as_serializable_spec.rb
|
|
92
96
|
- spec/versions_spec.rb
|
|
97
|
+
- spec/builder_patch_spec.rb
|
|
93
98
|
- spec/version_spec.rb
|
|
94
99
|
- spec/serializations/test_model/version_1_0_0.rb
|
|
95
100
|
- spec/serializations/test_model/version_2_1.rb
|