birkirb-acts_as_serializable 0.1.1 → 0.1.2

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 ADDED
@@ -0,0 +1,2 @@
1
+ coverage*
2
+ pkg
data/README.rdoc CHANGED
@@ -68,7 +68,27 @@ Use versioned serialization methods:
68
68
 
69
69
  Use classes containing versioned serialization methods:
70
70
 
71
- WIP
71
+ Given a model in app/models:
72
+
73
+ class Person < ActiveRecord::Base
74
+ acts_as_serializable
75
+ end
76
+
77
+ And a serialization in app/serializations/person
78
+
79
+ module Serializable
80
+ module Person
81
+ class Version_1_1_0
82
+ def self.serialize(person, builder, options)
83
+ builder.person do
84
+ builder.name(person.name)
85
+ end
86
+ end
87
+ end
88
+ end
89
+ end
90
+
91
+ Person.new(:name => "Birkir").to_xml => "<person><name>Birkir</name></person>"
72
92
 
73
93
  == Copyright
74
94
 
data/Rakefile CHANGED
@@ -1,5 +1,25 @@
1
1
  require 'rake'
2
2
 
3
+ begin
4
+ require 'jeweler'
5
+ Jeweler::Tasks.new do |s|
6
+ s.name = %q{acts_as_serializable}
7
+ s.authors = ["Birkir A. Barkarson"]
8
+ s.description = %q{Easy versioning of serialization methods}
9
+ s.summary = s.description
10
+ s.email = %q{birkirb@stoicviking.net}
11
+ s.has_rdoc = true
12
+ s.homepage = %q{http://github.com/birkirb/acts_as_serializable}
13
+ s.rubyforge_project = %q{serializable}
14
+ s.rubygems_version = %q{1.3.1}
15
+ #s.required_rubygems_version = "1.3.1"
16
+ s.add_dependency(%q<jsonbuilder>, [">= 0.0.6"])
17
+ s.add_dependency(%q<activesupport>, [">= 1.2"])
18
+ end
19
+ rescue LoadError
20
+ puts "Jeweler, or one of its dependencies, is not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
21
+ end
22
+
3
23
  begin
4
24
  require 'spec/rake/spectask'
5
25
 
@@ -15,27 +35,27 @@ rescue LoadError
15
35
  end
16
36
  end
17
37
 
18
- begin
19
- require 'cucumber'
20
- require 'cucumber/rake/task'
38
+ # begin
39
+ # require 'cucumber'
40
+ # require 'cucumber/rake/task'
21
41
 
22
42
 
23
- desc "Run Cucumber feature tests"
24
- Cucumber::Rake::Task.new(:features) do |t|
25
- t.cucumber_opts = "--format pretty"
26
- end
43
+ # desc "Run Cucumber feature tests"
44
+ # Cucumber::Rake::Task.new(:features) do |t|
45
+ # t.cucumber_opts = "--format pretty"
46
+ # end
27
47
 
28
- rescue LoadError
29
- desc 'Cucumber rake task not available'
30
- task :features do
31
- abort 'Cucumber rake task is not available. Be sure to install cucumber as a gem or plugin'
32
- end
33
- end
48
+ # rescue LoadError
49
+ # desc 'Cucumber rake task not available'
50
+ # task :features do
51
+ # abort 'Cucumber rake task is not available. Be sure to install cucumber as a gem or plugin'
52
+ # end
53
+ # end
34
54
 
35
55
  begin
36
56
  require 'spec/rake/spectask'
37
- require 'cucumber'
38
- require 'cucumber/rake/task'
57
+ # require 'cucumber'
58
+ # require 'cucumber/rake/task'
39
59
  require 'spec/rake/verify_rcov'
40
60
 
41
61
  task :test do
@@ -47,12 +67,12 @@ begin
47
67
  namespace :rcov do
48
68
  rm "coverage.data" if File.exist?("coverage.data")
49
69
 
50
- desc "Run Features with RCov"
51
- Cucumber::Rake::Task.new(:features) do |t|
52
- t.rcov = true
53
- t.rcov_opts = %w{ --exclude osx\/objc,gems\/,spec\/,features\/ --aggregate coverage.data}
54
- t.rcov_opts << %[-o "coverage"]
55
- end
70
+ # desc "Run Features with RCov"
71
+ # Cucumber::Rake::Task.new(:features) do |t|
72
+ # t.rcov = true
73
+ # t.rcov_opts = %w{ --exclude osx\/objc,gems\/,spec\/,features\/ --aggregate coverage.data}
74
+ # t.rcov_opts << %[-o "coverage"]
75
+ # end
56
76
 
57
77
  Spec::Rake::SpecTask.new(:spec) do |t|
58
78
  t.spec_opts = ["-f specdoc", "-c"]
@@ -64,7 +84,7 @@ begin
64
84
  desc "Run both specs and features to generate aggregated coverage"
65
85
  task :all do |t|
66
86
  Rake::Task["rcov:spec"].invoke
67
- Rake::Task["rcov:features"].invoke
87
+ # Rake::Task["rcov:features"].invoke
68
88
  end
69
89
 
70
90
  RCov::VerifyTask.new(:verify => 'rcov:all') do |t|
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.2
@@ -0,0 +1,71 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{acts_as_serializable}
5
+ s.version = "0.1.2"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Birkir A. Barkarson"]
9
+ s.date = %q{2009-06-11}
10
+ s.description = %q{Easy versioning of serialization methods}
11
+ s.email = %q{birkirb@stoicviking.net}
12
+ s.extra_rdoc_files = [
13
+ "README.rdoc"
14
+ ]
15
+ s.files = [
16
+ ".gitignore",
17
+ "README.rdoc",
18
+ "Rakefile",
19
+ "VERSION",
20
+ "acts_as_serializable.gemspec",
21
+ "init.rb",
22
+ "lib/acts_as_serializable.rb",
23
+ "lib/version.rb",
24
+ "lib/versions.rb",
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",
29
+ "spec/serializations/test_model/version_1_0_0.rb",
30
+ "spec/serializations/test_model/version_1_5.rb",
31
+ "spec/serializations/test_model/version_2_1.rb",
32
+ "spec/spec_helper.rb",
33
+ "spec/version_spec.rb",
34
+ "spec/versions_spec.rb"
35
+ ]
36
+ s.has_rdoc = true
37
+ s.homepage = %q{http://github.com/birkirb/acts_as_serializable}
38
+ s.rdoc_options = ["--charset=UTF-8"]
39
+ s.require_paths = ["lib"]
40
+ s.rubyforge_project = %q{serializable}
41
+ s.rubygems_version = %q{1.3.1}
42
+ s.summary = %q{Easy versioning of serialization methods}
43
+ s.test_files = [
44
+ "spec/spec_helper.rb",
45
+ "spec/acts_as_serializable_spec.rb",
46
+ "spec/versions_spec.rb",
47
+ "spec/version_spec.rb",
48
+ "spec/serializations/test_model/version_1_0_0.rb",
49
+ "spec/serializations/test_model/version_2_1.rb",
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"
54
+ ]
55
+
56
+ if s.respond_to? :specification_version then
57
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
58
+ s.specification_version = 2
59
+
60
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
61
+ s.add_runtime_dependency(%q<jsonbuilder>, [">= 0.0.6"])
62
+ s.add_runtime_dependency(%q<activesupport>, [">= 1.2"])
63
+ else
64
+ s.add_dependency(%q<jsonbuilder>, [">= 0.0.6"])
65
+ s.add_dependency(%q<activesupport>, [">= 1.2"])
66
+ end
67
+ else
68
+ s.add_dependency(%q<jsonbuilder>, [">= 0.0.6"])
69
+ s.add_dependency(%q<activesupport>, [">= 1.2"])
70
+ end
71
+ end
data/init.rb CHANGED
@@ -1 +1,2 @@
1
- require 'lib/acts_as_serializable'
1
+ require 'acts_as_serializable'
2
+ ActiveRecord::Base.send(:include, Serializable)
@@ -2,8 +2,6 @@ require 'builder/xmlmarkup'
2
2
  require 'jsonbuilder'
3
3
  require 'active_support'
4
4
  require 'find'
5
- require 'versions'
6
- require 'version'
7
5
 
8
6
  module Serializable
9
7
  SERIALIZE_TO_VERSION_REGEXP = /^serialize_to_version_((:?\d+_?)+)$/
@@ -19,6 +17,12 @@ module Serializable
19
17
  extend Serializable::SingletonMethods
20
18
  @serialization_versions = Versions.new
21
19
  find_local_serialization_methods
20
+ if defined?(RAILS_ROOT)
21
+ # Rails plugin usage
22
+ scan_rails_app_paths.each do |path|
23
+ find_project_serialization_classes(path)
24
+ end
25
+ end
22
26
  end
23
27
  end
24
28
 
@@ -73,6 +77,16 @@ module Serializable
73
77
  EOV
74
78
  @serialization_versions << Version.new(method_version)
75
79
  end
80
+
81
+ def scan_rails_app_paths
82
+ project_paths = Array.new
83
+ $LOAD_PATH.each do |path|
84
+ if path.match(/#{Regexp.escape(RAILS_ROOT)}.*\/app$/)
85
+ project_paths << path
86
+ end
87
+ end
88
+ project_paths
89
+ end
76
90
  end
77
91
 
78
92
  # This module contains instance methods
@@ -38,6 +38,14 @@ class TestModel
38
38
  find_project_serialization_classes(File.join(File.dirname(__FILE__)))
39
39
  end
40
40
 
41
+ ::RAILS_ROOT = File.join(File.dirname(__FILE__))
42
+ $LOAD_PATH.push(File.join(::RAILS_ROOT, 'app'))
43
+
44
+ class TestRailsModel
45
+ include Serializable
46
+ acts_as_serializable
47
+ end
48
+
41
49
  describe Serializable, 'if included in a class, then that class' do
42
50
 
43
51
  it 'should respond to #to_xml(options)' do
@@ -164,5 +172,13 @@ describe Serializable, 'when included in a class that has multiple serialization
164
172
 
165
173
  klass.to_xml.should == "This is version 1.5.0 for TestModel"
166
174
  end
175
+
176
+ it 'should auto find version classes for Rails applications' do
177
+ klass = TestRailsModel.new
178
+
179
+ 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"
181
+ klass.to_hash(:version => '2.1.0').should == "This is version 2.1 for TestRailsModel"
182
+ end
167
183
  end
168
184
  end
@@ -0,0 +1,9 @@
1
+ module Serializable
2
+ module TestRailsModel
3
+ class Version_1_0_0
4
+ def self.serialize(test_model, builder, options)
5
+ "This is version 1.0.0 for #{test_model.class.name}"
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Serializable
2
+ module TestRailsModel
3
+ class Version_1_5
4
+ def self.serialize(test_model, builder, options)
5
+ "This is version 1.5.0 for #{test_model.class.name}"
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Serializable
2
+ module TestRailsModel
3
+ class Version_2_1
4
+ def self.serialize(test_model, builder, options)
5
+ "This is version 2.1 for #{test_model.class.name}"
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Serializable
2
+ module TestModel
3
+ class Version_1_0_0
4
+ def self.serialize(test_model, builder, options)
5
+ "This is version 1.0.0 for #{test_model.class.name}"
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Serializable
2
+ module TestModel
3
+ class Version_1_5
4
+ def self.serialize(test_model, builder, options)
5
+ "This is version 1.5.0 for #{test_model.class.name}"
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Serializable
2
+ module TestModel
3
+ class Version_2_1
4
+ def self.serialize(test_model, builder, options)
5
+ "This is version 2.1 for #{test_model.class.name}"
6
+ end
7
+ end
8
+ end
9
+ 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.1
4
+ version: 0.1.2
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-06 00:00:00 -07:00
12
+ date: 2009-06-11 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -41,28 +41,30 @@ extensions: []
41
41
  extra_rdoc_files:
42
42
  - README.rdoc
43
43
  files:
44
+ - .gitignore
44
45
  - README.rdoc
45
46
  - Rakefile
47
+ - VERSION
48
+ - acts_as_serializable.gemspec
46
49
  - init.rb
47
50
  - lib/acts_as_serializable.rb
48
51
  - lib/version.rb
49
52
  - lib/versions.rb
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
57
+ - spec/serializations/test_model/version_1_0_0.rb
58
+ - spec/serializations/test_model/version_1_5.rb
59
+ - spec/serializations/test_model/version_2_1.rb
60
+ - spec/spec_helper.rb
61
+ - spec/version_spec.rb
62
+ - spec/versions_spec.rb
50
63
  has_rdoc: true
51
64
  homepage: http://github.com/birkirb/acts_as_serializable
52
65
  post_install_message:
53
66
  rdoc_options:
54
- - --title
55
- - acts_as_serializable documentation
56
- - --charset
57
- - utf-8
58
- - --opname
59
- - index.html
60
- - --line-numbers
61
- - --main
62
- - README.rdoc
63
- - --inline-source
64
- - --exclude
65
- - ^(examples)/
67
+ - --charset=UTF-8
66
68
  require_paths:
67
69
  - lib
68
70
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -79,13 +81,19 @@ required_rubygems_version: !ruby/object:Gem::Requirement
79
81
  version:
80
82
  requirements: []
81
83
 
82
- rubyforge_project:
84
+ rubyforge_project: serializable
83
85
  rubygems_version: 1.2.0
84
86
  signing_key:
85
87
  specification_version: 2
86
88
  summary: Easy versioning of serialization methods
87
89
  test_files:
90
+ - spec/spec_helper.rb
88
91
  - spec/acts_as_serializable_spec.rb
89
- - spec/version_spec.rb
90
92
  - spec/versions_spec.rb
91
- - spec/spec_helper.rb
93
+ - spec/version_spec.rb
94
+ - spec/serializations/test_model/version_1_0_0.rb
95
+ - spec/serializations/test_model/version_2_1.rb
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