acts_as_serializable 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/acts_as_serializable.rb +7 -0
- data/lib/serializable/xbuilder.rb +5 -2
- data/spec/acts_as_serializable_spec.rb +1 -1
- data/spec/spec_helper.rb +12 -3
- data/spec/version_spec.rb +1 -1
- data/spec/versions_spec.rb +1 -1
- data/spec/xbuilder_spec.rb +61 -0
- metadata +58 -77
- data/acts_as_serializable.gemspec +0 -64
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
data/lib/acts_as_serializable.rb
CHANGED
@@ -3,6 +3,11 @@ require 'active_support'
|
|
3
3
|
require 'find'
|
4
4
|
require 'serializable/version'
|
5
5
|
|
6
|
+
def using_rails_3?
|
7
|
+
# Assume 3 unless we have 2.
|
8
|
+
defined?(Rails) && Rails::VERSION::MAJOR != 2
|
9
|
+
end
|
10
|
+
|
6
11
|
module Serializable
|
7
12
|
SERIALIZE_TO_VERSION_REGEXP = /^serialize_to_version_((:?\d+_?)+)$/
|
8
13
|
SERIALIZED_CLASS_NAME_REGEXP = /\/version_((:?\d+_?)+)\.rb$/
|
@@ -15,6 +20,8 @@ module Serializable
|
|
15
20
|
if defined?(RAILS_ROOT)
|
16
21
|
# Rails plugin usage
|
17
22
|
project_paths = Array.new
|
23
|
+
# The app directory itself is not in $LOAD_PATH in Rails 3
|
24
|
+
project_paths << Rails.root.join('app') if defined?(Rails) && File.exists?(Rails.root.join('app'))
|
18
25
|
$LOAD_PATH.each do |path|
|
19
26
|
if path.match(/#{Regexp.escape(RAILS_ROOT)}.*\/app$/)
|
20
27
|
project_paths << path
|
@@ -1,6 +1,8 @@
|
|
1
1
|
module Serializable
|
2
|
-
|
3
|
-
|
2
|
+
xbuilder_parent = using_rails_3? ? Object : ::ActionView::TemplateHandler
|
3
|
+
|
4
|
+
class XBuilder < xbuilder_parent
|
5
|
+
include ActionView::TemplateHandlers::Compilable unless using_rails_3?
|
4
6
|
|
5
7
|
def compile(template)
|
6
8
|
compiled_code = <<-CODE
|
@@ -21,6 +23,7 @@ module Serializable
|
|
21
23
|
compiled_code
|
22
24
|
end
|
23
25
|
|
26
|
+
alias_method :call, :compile
|
24
27
|
end
|
25
28
|
end
|
26
29
|
|
data/spec/spec_helper.rb
CHANGED
@@ -3,6 +3,15 @@ require 'rubygems'
|
|
3
3
|
::RAILS_ROOT = File.join(File.dirname(__FILE__))
|
4
4
|
$LOAD_PATH.push(File.join(::RAILS_ROOT, 'app'))
|
5
5
|
|
6
|
-
require '
|
7
|
-
require '
|
8
|
-
require '
|
6
|
+
require 'serializable/version'
|
7
|
+
require 'serializable/versions'
|
8
|
+
require 'acts_as_serializable'
|
9
|
+
|
10
|
+
def silence_warnings
|
11
|
+
begin
|
12
|
+
old_verbose, $VERBOSE = $VERBOSE, nil
|
13
|
+
yield
|
14
|
+
ensure
|
15
|
+
$VERBOSE = old_verbose
|
16
|
+
end
|
17
|
+
end
|
data/spec/version_spec.rb
CHANGED
data/spec/versions_spec.rb
CHANGED
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module ActionView
|
4
|
+
class TemplateHandler
|
5
|
+
end
|
6
|
+
|
7
|
+
module TemplateHandlers
|
8
|
+
module Compilable
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class Template
|
13
|
+
def self.register_template_handler(*args)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
module Rails
|
19
|
+
module VERSION
|
20
|
+
def self.set(val)
|
21
|
+
silence_warnings do
|
22
|
+
const_set(:MAJOR, val)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def set_rails(version)
|
29
|
+
Rails::VERSION.set(version)
|
30
|
+
if defined?(Serializable::XBuilder)
|
31
|
+
Serializable.send(:remove_const, "XBuilder")
|
32
|
+
xbuilder_path = $".detect { |lib| lib =~ /xbuilder/ }
|
33
|
+
$".delete(xbuilder_path)
|
34
|
+
end
|
35
|
+
require 'serializable/xbuilder'
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "XBuilder", 'when in Rails' do
|
39
|
+
context 'and Rails is version 2' do
|
40
|
+
it 'should inherit from ActionView::TemplateHandler' do
|
41
|
+
set_rails(2)
|
42
|
+
Serializable::XBuilder.ancestors.include?(ActionView::TemplateHandler).should be_true
|
43
|
+
end
|
44
|
+
it 'should include Compilable' do
|
45
|
+
set_rails(2)
|
46
|
+
Serializable::XBuilder.ancestors.include?(ActionView::TemplateHandlers::Compilable).should be_true
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
context 'and Rails is version 3' do
|
51
|
+
it 'should not inherit from ActionView::TemplateHandler' do
|
52
|
+
set_rails(3)
|
53
|
+
Serializable::XBuilder.ancestors.include?(ActionView::TemplateHandler).should be_false
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'should not include Compilable' do
|
57
|
+
set_rails(3)
|
58
|
+
Serializable::XBuilder.ancestors.include?(ActionView::TemplateHandlers::Compilable).should be_false
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
metadata
CHANGED
@@ -1,83 +1,74 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: acts_as_serializable
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 2
|
9
|
-
- 1
|
10
|
-
version: 0.2.1
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.0
|
5
|
+
prerelease:
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Birkir A. Barkarson
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
dependencies:
|
21
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2012-11-15 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
22
15
|
name: builder
|
23
|
-
|
24
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
25
17
|
none: false
|
26
|
-
requirements:
|
18
|
+
requirements:
|
27
19
|
- - <=
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
hash: 15
|
30
|
-
segments:
|
31
|
-
- 2
|
32
|
-
- 1
|
33
|
-
- 2
|
20
|
+
- !ruby/object:Gem::Version
|
34
21
|
version: 2.1.2
|
35
22
|
type: :runtime
|
36
|
-
version_requirements: *id001
|
37
|
-
- !ruby/object:Gem::Dependency
|
38
|
-
name: jsonbuilder
|
39
23
|
prerelease: false
|
40
|
-
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - <=
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 2.1.2
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: jsonbuilder
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
41
33
|
none: false
|
42
|
-
requirements:
|
43
|
-
- -
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
hash: 27
|
46
|
-
segments:
|
47
|
-
- 0
|
48
|
-
- 1
|
49
|
-
- 0
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
50
37
|
version: 0.1.0
|
51
38
|
type: :runtime
|
52
|
-
version_requirements: *id002
|
53
|
-
- !ruby/object:Gem::Dependency
|
54
|
-
name: activesupport
|
55
39
|
prerelease: false
|
56
|
-
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 0.1.0
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: activesupport
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
57
49
|
none: false
|
58
|
-
requirements:
|
59
|
-
- -
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
|
62
|
-
segments:
|
63
|
-
- 1
|
64
|
-
- 2
|
65
|
-
version: "1.2"
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '1.2'
|
66
54
|
type: :runtime
|
67
|
-
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.2'
|
68
62
|
description: Easy versioning of serialization methods
|
69
63
|
email: birkirb@stoicviking.net
|
70
64
|
executables: []
|
71
|
-
|
72
65
|
extensions: []
|
73
|
-
|
74
|
-
extra_rdoc_files:
|
66
|
+
extra_rdoc_files:
|
75
67
|
- README.rdoc
|
76
|
-
files:
|
68
|
+
files:
|
77
69
|
- README.rdoc
|
78
70
|
- Rakefile
|
79
71
|
- VERSION
|
80
|
-
- acts_as_serializable.gemspec
|
81
72
|
- init.rb
|
82
73
|
- lib/acts_as_serializable.rb
|
83
74
|
- lib/serializable/version.rb
|
@@ -93,39 +84,29 @@ files:
|
|
93
84
|
- spec/spec_helper.rb
|
94
85
|
- spec/version_spec.rb
|
95
86
|
- spec/versions_spec.rb
|
96
|
-
|
87
|
+
- spec/xbuilder_spec.rb
|
97
88
|
homepage: http://github.com/birkirb/acts_as_serializable
|
98
89
|
licenses: []
|
99
|
-
|
100
90
|
post_install_message:
|
101
91
|
rdoc_options: []
|
102
|
-
|
103
|
-
require_paths:
|
92
|
+
require_paths:
|
104
93
|
- lib
|
105
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
94
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
106
95
|
none: false
|
107
|
-
requirements:
|
108
|
-
- -
|
109
|
-
- !ruby/object:Gem::Version
|
110
|
-
|
111
|
-
|
112
|
-
- 0
|
113
|
-
version: "0"
|
114
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - ! '>='
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
115
101
|
none: false
|
116
|
-
requirements:
|
117
|
-
- -
|
118
|
-
- !ruby/object:Gem::Version
|
119
|
-
|
120
|
-
segments:
|
121
|
-
- 0
|
122
|
-
version: "0"
|
102
|
+
requirements:
|
103
|
+
- - ! '>='
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
123
106
|
requirements: []
|
124
|
-
|
125
107
|
rubyforge_project: serializable
|
126
|
-
rubygems_version: 1.
|
108
|
+
rubygems_version: 1.8.23
|
127
109
|
signing_key:
|
128
110
|
specification_version: 3
|
129
111
|
summary: Easy versioning of serialization methods
|
130
112
|
test_files: []
|
131
|
-
|
@@ -1,64 +0,0 @@
|
|
1
|
-
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
-
# -*- encoding: utf-8 -*-
|
5
|
-
|
6
|
-
Gem::Specification.new do |s|
|
7
|
-
s.name = %q{acts_as_serializable}
|
8
|
-
s.version = "0.2.1"
|
9
|
-
|
10
|
-
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
-
s.authors = ["Birkir A. Barkarson"]
|
12
|
-
s.date = %q{2011-09-21}
|
13
|
-
s.description = %q{Easy versioning of serialization methods}
|
14
|
-
s.email = %q{birkirb@stoicviking.net}
|
15
|
-
s.extra_rdoc_files = [
|
16
|
-
"README.rdoc"
|
17
|
-
]
|
18
|
-
s.files = [
|
19
|
-
"README.rdoc",
|
20
|
-
"Rakefile",
|
21
|
-
"VERSION",
|
22
|
-
"acts_as_serializable.gemspec",
|
23
|
-
"init.rb",
|
24
|
-
"lib/acts_as_serializable.rb",
|
25
|
-
"lib/serializable/version.rb",
|
26
|
-
"lib/serializable/versions.rb",
|
27
|
-
"lib/serializable/xbuilder.rb",
|
28
|
-
"spec/acts_as_serializable_spec.rb",
|
29
|
-
"spec/app/serializations/test_rails_model/version_1_0_0.rb",
|
30
|
-
"spec/app/serializations/test_rails_model/version_1_5.rb",
|
31
|
-
"spec/app/serializations/test_rails_model/version_2_1.rb",
|
32
|
-
"spec/serializations/test_model/version_1_0_0.rb",
|
33
|
-
"spec/serializations/test_model/version_1_5.rb",
|
34
|
-
"spec/serializations/test_model/version_2_1.rb",
|
35
|
-
"spec/spec_helper.rb",
|
36
|
-
"spec/version_spec.rb",
|
37
|
-
"spec/versions_spec.rb"
|
38
|
-
]
|
39
|
-
s.homepage = %q{http://github.com/birkirb/acts_as_serializable}
|
40
|
-
s.require_paths = ["lib"]
|
41
|
-
s.rubyforge_project = %q{serializable}
|
42
|
-
s.rubygems_version = %q{1.3.7}
|
43
|
-
s.summary = %q{Easy versioning of serialization methods}
|
44
|
-
|
45
|
-
if s.respond_to? :specification_version then
|
46
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
47
|
-
s.specification_version = 3
|
48
|
-
|
49
|
-
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
50
|
-
s.add_runtime_dependency(%q<builder>, ["<= 2.1.2"])
|
51
|
-
s.add_runtime_dependency(%q<jsonbuilder>, [">= 0.1.0"])
|
52
|
-
s.add_runtime_dependency(%q<activesupport>, [">= 1.2"])
|
53
|
-
else
|
54
|
-
s.add_dependency(%q<builder>, ["<= 2.1.2"])
|
55
|
-
s.add_dependency(%q<jsonbuilder>, [">= 0.1.0"])
|
56
|
-
s.add_dependency(%q<activesupport>, [">= 1.2"])
|
57
|
-
end
|
58
|
-
else
|
59
|
-
s.add_dependency(%q<builder>, ["<= 2.1.2"])
|
60
|
-
s.add_dependency(%q<jsonbuilder>, [">= 0.1.0"])
|
61
|
-
s.add_dependency(%q<activesupport>, [">= 1.2"])
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|