typed_serialize 0.1.0
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/CHANGELOG +7 -0
- data/LICENSE +20 -0
- data/Manifest +10 -0
- data/README.rdoc +32 -0
- data/Rakefile +22 -0
- data/init.rb +1 -0
- data/install.rb +1 -0
- data/lib/typed_serialize.rb +14 -0
- data/typed_serialize.gemspec +30 -0
- data/uninstall.rb +1 -0
- metadata +72 -0
data/CHANGELOG
ADDED
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
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,14 @@
|
|
1
|
+
class ActiveRecord::Base
|
2
|
+
def self.typed_serialize(attr_name, class_name)
|
3
|
+
serialize(attr_name, class_name)
|
4
|
+
|
5
|
+
define_method(attr_name) do
|
6
|
+
expected_class = self.class.serialized_attributes[attr_name.to_s]
|
7
|
+
if (value = super).is_a?(expected_class)
|
8
|
+
value
|
9
|
+
else
|
10
|
+
send("#{attr_name}=", expected_class.new)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{typed_serialize}
|
5
|
+
s.version = "0.1.0"
|
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-12-01}
|
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", "typed_serialize.gemspec", "uninstall.rb"]
|
14
|
+
s.homepage = %q{}
|
15
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Typed_serialize", "--main", "README.rdoc"]
|
16
|
+
s.require_paths = ["lib"]
|
17
|
+
s.rubyforge_project = %q{typed_serialize}
|
18
|
+
s.rubygems_version = %q{1.3.5}
|
19
|
+
s.summary = %q{Typed serialize makes sure your serialized attribute is always the specified type.}
|
20
|
+
|
21
|
+
if s.respond_to? :specification_version then
|
22
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
23
|
+
s.specification_version = 3
|
24
|
+
|
25
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
26
|
+
else
|
27
|
+
end
|
28
|
+
else
|
29
|
+
end
|
30
|
+
end
|
data/uninstall.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Uninstall hook code here
|
metadata
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: typed_serialize
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Elijah Miller
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-12-01 00:00:00 -05:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Typed serialize makes sure your serialized attribute is always the specified type.
|
17
|
+
email: elijah.miller@gmail.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- CHANGELOG
|
24
|
+
- lib/typed_serialize.rb
|
25
|
+
- LICENSE
|
26
|
+
- README.rdoc
|
27
|
+
files:
|
28
|
+
- CHANGELOG
|
29
|
+
- init.rb
|
30
|
+
- install.rb
|
31
|
+
- lib/typed_serialize.rb
|
32
|
+
- LICENSE
|
33
|
+
- Manifest
|
34
|
+
- Rakefile
|
35
|
+
- README.rdoc
|
36
|
+
- typed_serialize.gemspec
|
37
|
+
- uninstall.rb
|
38
|
+
has_rdoc: true
|
39
|
+
homepage: ""
|
40
|
+
licenses: []
|
41
|
+
|
42
|
+
post_install_message:
|
43
|
+
rdoc_options:
|
44
|
+
- --line-numbers
|
45
|
+
- --inline-source
|
46
|
+
- --title
|
47
|
+
- Typed_serialize
|
48
|
+
- --main
|
49
|
+
- README.rdoc
|
50
|
+
require_paths:
|
51
|
+
- lib
|
52
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: "0"
|
57
|
+
version:
|
58
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: "1.2"
|
63
|
+
version:
|
64
|
+
requirements: []
|
65
|
+
|
66
|
+
rubyforge_project: typed_serialize
|
67
|
+
rubygems_version: 1.3.5
|
68
|
+
signing_key:
|
69
|
+
specification_version: 3
|
70
|
+
summary: Typed serialize makes sure your serialized attribute is always the specified type.
|
71
|
+
test_files: []
|
72
|
+
|