jqr-typed_serialize 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG ADDED
@@ -0,0 +1,2 @@
1
+ v0.0.2. Fixing a bug where typed_serialize would always return a new Hash.
2
+ v0.0.1. Initial release.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008 Elijah Miller
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Manifest ADDED
@@ -0,0 +1,9 @@
1
+ CHANGELOG
2
+ init.rb
3
+ install.rb
4
+ lib/typed_serialize.rb
5
+ LICENSE
6
+ Manifest
7
+ Rakefile
8
+ README.rdoc
9
+ uninstall.rb
data/README.rdoc ADDED
@@ -0,0 +1,32 @@
1
+ = Typed Serialize
2
+
3
+ Typed serialize makes sure your serialized attribute is always the specified
4
+ type. This is especially nice for serialized hashes and new models.
5
+
6
+ == Example
7
+
8
+ class User < ActiveRecord::Base
9
+ typed_serialize :settings, Hash
10
+ end
11
+
12
+ User.new.settings # => {}
13
+
14
+ u = User.new
15
+ u.settings[:theme] = 1
16
+ u.settings # => { :theme => 1 }
17
+
18
+ == Install
19
+
20
+ As a Rails plugin:
21
+
22
+ ./script/plugin install git://github.com/jqr/typed_serialize.git
23
+
24
+ Prefer gems? Add this to your environment.rb and run the following command.
25
+
26
+ config.gem 'jqr-typed_serialize', :lib => 'typed_serialize', :source => 'http://gems.github.com'
27
+
28
+ $ rake gems:install
29
+
30
+
31
+ Homepage:: http://github.com/jqr/typed_serialize
32
+ License:: Copyright (c) 2008 Elijah Miller <mailto:elijah.miller@gmail.com>, released under the MIT license
data/Rakefile ADDED
@@ -0,0 +1,22 @@
1
+ require 'spec/rake/spectask'
2
+
3
+ require 'echoe'
4
+ Echoe.new 'typed_serialize' do |p|
5
+ p.description = "Typed serialize makes sure your serialized attribute is always the specified type."
6
+ # p.url = "http://typed_serialize.rubyforge.org"
7
+ p.author = "Elijah Miller"
8
+ p.email = "elijah.miller@gmail.com"
9
+ p.retain_gemspec = true
10
+ p.need_tar_gz = false
11
+ p.extra_deps = [
12
+ ]
13
+ p.ignore_pattern = ['spec/test.sqlite3']
14
+ end
15
+
16
+ desc 'Default: run specs'
17
+ task :default => :spec
18
+ Spec::Rake::SpecTask.new do |t|
19
+ t.spec_files = FileList["spec/**/*_spec.rb"]
20
+ end
21
+
22
+ task :test => :spec
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require 'typed_serialize'
data/install.rb ADDED
@@ -0,0 +1 @@
1
+ # Install hook code here
@@ -0,0 +1,16 @@
1
+ class ActiveRecord::Base
2
+ def self.typed_serialize(attr_name, class_name = Object)
3
+ serialize(attr_name, class_name)
4
+
5
+ if class_name != Object
6
+ define_method(attr_name) do
7
+ expected_class = self.class.serialized_attributes[attr_name.to_s]
8
+ if (value = super).is_a?(expected_class)
9
+ value
10
+ else
11
+ self.send("#{attr_name}=", expected_class.new)
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,34 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{typed_serialize}
5
+ s.version = "0.0.2"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Elijah Miller"]
9
+ s.date = %q{2009-01-16}
10
+ s.description = %q{Typed serialize makes sure your serialized attribute is always the specified type.}
11
+ s.email = %q{elijah.miller@gmail.com}
12
+ s.extra_rdoc_files = ["CHANGELOG", "lib/typed_serialize.rb", "LICENSE", "README.rdoc"]
13
+ s.files = ["CHANGELOG", "init.rb", "install.rb", "lib/typed_serialize.rb", "LICENSE", "Manifest", "Rakefile", "README.rdoc", "uninstall.rb", "typed_serialize.gemspec"]
14
+ s.has_rdoc = true
15
+ s.homepage = %q{}
16
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Typed_serialize", "--main", "README.rdoc"]
17
+ s.require_paths = ["lib"]
18
+ s.rubyforge_project = %q{typed_serialize}
19
+ s.rubygems_version = %q{1.3.1}
20
+ s.summary = %q{Typed serialize makes sure your serialized attribute is always the specified type.}
21
+
22
+ if s.respond_to? :specification_version then
23
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
24
+ s.specification_version = 2
25
+
26
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
27
+ s.add_development_dependency(%q<echoe>, [">= 0"])
28
+ else
29
+ s.add_dependency(%q<echoe>, [">= 0"])
30
+ end
31
+ else
32
+ s.add_dependency(%q<echoe>, [">= 0"])
33
+ end
34
+ end
data/uninstall.rb ADDED
@@ -0,0 +1 @@
1
+ # Uninstall hook code here
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jqr-typed_serialize
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Elijah Miller
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-01-16 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: echoe
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: "0"
23
+ version:
24
+ description: Typed serialize makes sure your serialized attribute is always the specified type.
25
+ email: elijah.miller@gmail.com
26
+ executables: []
27
+
28
+ extensions: []
29
+
30
+ extra_rdoc_files:
31
+ - CHANGELOG
32
+ - lib/typed_serialize.rb
33
+ - LICENSE
34
+ - README.rdoc
35
+ files:
36
+ - CHANGELOG
37
+ - init.rb
38
+ - install.rb
39
+ - lib/typed_serialize.rb
40
+ - LICENSE
41
+ - Manifest
42
+ - Rakefile
43
+ - README.rdoc
44
+ - uninstall.rb
45
+ - typed_serialize.gemspec
46
+ has_rdoc: true
47
+ homepage: ""
48
+ post_install_message:
49
+ rdoc_options:
50
+ - --line-numbers
51
+ - --inline-source
52
+ - --title
53
+ - Typed_serialize
54
+ - --main
55
+ - README.rdoc
56
+ require_paths:
57
+ - lib
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: "0"
63
+ version:
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: "1.2"
69
+ version:
70
+ requirements: []
71
+
72
+ rubyforge_project: typed_serialize
73
+ rubygems_version: 1.2.0
74
+ signing_key:
75
+ specification_version: 2
76
+ summary: Typed serialize makes sure your serialized attribute is always the specified type.
77
+ test_files: []
78
+