ar-serialize-helpers 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/.rspec +1 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +47 -0
- data/Rakefile +13 -0
- data/ar-serialize-helpers.gemspec +20 -0
- data/lib/ar-serialize-helpers/all.rb +3 -0
- data/lib/ar-serialize-helpers/integer.rb +11 -0
- data/lib/ar-serialize-helpers/json.rb +12 -0
- data/lib/ar-serialize-helpers/version.rb +3 -0
- data/lib/ar-serialize-helpers.rb +4 -0
- data/spec/ar-serialize-helpers/integer_spec.rb +31 -0
- data/spec/ar-serialize-helpers/json_spec.rb +52 -0
- data/spec/spec_helper.rb +1 -0
- metadata +104 -0
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--colour
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 EmberAds Ltd <team@emberads.com>
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# Ar::Serialize::Helpers
|
2
|
+
|
3
|
+
Collection of helpers for ActiveRecord's `serialize` method in Rails >= 3.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'ar-serialize-helpers'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install ar-serialize-helpers
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
You need to require the individual helper classes you wish to use. You can either do this in an initializer
|
22
|
+
|
23
|
+
require "ar-serialize-helpers/json"
|
24
|
+
|
25
|
+
or in the Gemfile
|
26
|
+
|
27
|
+
gem "ar-serialize-helpers", :require => "ar-serialize-helpers/json"
|
28
|
+
# Or for multiple modules
|
29
|
+
gem "ar-serialize-helpers", :require => ["ar-serialize-helpers/json", "ar-serialize-helpers/integer"]
|
30
|
+
|
31
|
+
Then pass an instance of the class to the `serialize` call in the model definition
|
32
|
+
|
33
|
+
class MyModel < ActiveRecord::Base
|
34
|
+
serialize :my_column, ARSerializeHelpers::JSON.new
|
35
|
+
end
|
36
|
+
|
37
|
+
## Contributing
|
38
|
+
|
39
|
+
1. Fork it
|
40
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
41
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
42
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
43
|
+
5. Create new Pull Request
|
44
|
+
|
45
|
+
## License
|
46
|
+
|
47
|
+
See LICENSE
|
data/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
require "bundler/gem_tasks"
|
3
|
+
begin
|
4
|
+
require 'rspec/core/rake_task'
|
5
|
+
RSpec::Core::RakeTask.new(:spec)
|
6
|
+
rescue LoadError => e
|
7
|
+
task "spec" do
|
8
|
+
puts "RSpec not loaded - make sure it's installed and you're using bundle exec"
|
9
|
+
exit 1
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
task :default => :spec
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/ar-serialize-helpers/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Caius Durling"]
|
6
|
+
gem.email = ["caius@emberads.com"]
|
7
|
+
gem.description = %q{Helpers for ActiveRecord's serialize in rails 3}
|
8
|
+
gem.summary = %q{Helpers for ActiveRecord's serialize in rails 3}
|
9
|
+
gem.homepage = "http://github.com/EmberAds/ar-serialize-helpers"
|
10
|
+
|
11
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
12
|
+
gem.files = `git ls-files`.split("\n")
|
13
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
14
|
+
gem.name = "ar-serialize-helpers"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = ARSerializeHelpers::VERSION
|
17
|
+
|
18
|
+
gem.add_development_dependency "json"
|
19
|
+
gem.add_development_dependency "rspec"
|
20
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "ar-serialize-helpers/integer"
|
3
|
+
|
4
|
+
describe ARSerializeHelpers::Integer do
|
5
|
+
before { @ints = ARSerializeHelpers::Integer.new }
|
6
|
+
|
7
|
+
describe "#dump" do
|
8
|
+
it "should dump integer successfully" do
|
9
|
+
@ints.dump(5).should be == 500
|
10
|
+
end
|
11
|
+
it "should dump float successfully" do
|
12
|
+
@ints.dump(0.58).should be == 58
|
13
|
+
end
|
14
|
+
it "should dump string successfully" do
|
15
|
+
@ints.dump("0.58").should be == 58
|
16
|
+
end
|
17
|
+
it "should not dump nil" do
|
18
|
+
@ints.dump(nil).should be_nil
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "#load" do
|
23
|
+
it "should load integer successfully" do
|
24
|
+
@ints.load(58).should be == 0.58
|
25
|
+
end
|
26
|
+
it "should parse nil to nil" do
|
27
|
+
@ints.load(nil).should be_nil
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "json"
|
3
|
+
require "ar-serialize-helpers/json"
|
4
|
+
|
5
|
+
module JSONSpecHelpers
|
6
|
+
extend self
|
7
|
+
|
8
|
+
# helperz
|
9
|
+
def ruby_to_json
|
10
|
+
{
|
11
|
+
true => "true",
|
12
|
+
1 => "1",
|
13
|
+
1.0 => "1.0",
|
14
|
+
"string" => %{"string"},
|
15
|
+
:symbol => %{"symbol"},
|
16
|
+
{"foo" => "bar"} => %@{"foo":"bar"}@,
|
17
|
+
[1,2,3] => "[1,2,3]"
|
18
|
+
}
|
19
|
+
end
|
20
|
+
|
21
|
+
def json_to_ruby
|
22
|
+
ruby_to_json.reject {|k,v| k == :symbol }.invert
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe ARSerializeHelpers::JSON do
|
27
|
+
before { @js = ARSerializeHelpers::JSON.new }
|
28
|
+
|
29
|
+
describe "#dump" do
|
30
|
+
JSONSpecHelpers.ruby_to_json.each do |ruby, json_str|
|
31
|
+
it "should dump #{ruby.class} to json successfully" do
|
32
|
+
@js.dump(ruby).should be == json_str
|
33
|
+
end
|
34
|
+
end
|
35
|
+
it "should not dump nil" do
|
36
|
+
@js.dump(nil).should be_nil # rather than "null" - JSON.parse("null") will throw an error y'see
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "#load" do
|
41
|
+
JSONSpecHelpers.json_to_ruby.each do |json_str, ruby|
|
42
|
+
it "should load #{ruby.class} from json successfully" do
|
43
|
+
# Have to wrap in an array so JSON can parse the primitive types
|
44
|
+
@js.load("[#{json_str}]").should == [ruby]
|
45
|
+
end
|
46
|
+
end
|
47
|
+
it "should parse nil to nil" do
|
48
|
+
@js.load(nil).should be_nil
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "ar-serialize-helpers"
|
metadata
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ar-serialize-helpers
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 1
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
version: 1.0.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Caius Durling
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2012-01-20 00:00:00 +00:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: json
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 0
|
30
|
+
version: "0"
|
31
|
+
type: :development
|
32
|
+
version_requirements: *id001
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: rspec
|
35
|
+
prerelease: false
|
36
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
37
|
+
none: false
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
segments:
|
42
|
+
- 0
|
43
|
+
version: "0"
|
44
|
+
type: :development
|
45
|
+
version_requirements: *id002
|
46
|
+
description: Helpers for ActiveRecord's serialize in rails 3
|
47
|
+
email:
|
48
|
+
- caius@emberads.com
|
49
|
+
executables: []
|
50
|
+
|
51
|
+
extensions: []
|
52
|
+
|
53
|
+
extra_rdoc_files: []
|
54
|
+
|
55
|
+
files:
|
56
|
+
- .gitignore
|
57
|
+
- .rspec
|
58
|
+
- Gemfile
|
59
|
+
- LICENSE
|
60
|
+
- README.md
|
61
|
+
- Rakefile
|
62
|
+
- ar-serialize-helpers.gemspec
|
63
|
+
- lib/ar-serialize-helpers.rb
|
64
|
+
- lib/ar-serialize-helpers/all.rb
|
65
|
+
- lib/ar-serialize-helpers/integer.rb
|
66
|
+
- lib/ar-serialize-helpers/json.rb
|
67
|
+
- lib/ar-serialize-helpers/version.rb
|
68
|
+
- spec/ar-serialize-helpers/integer_spec.rb
|
69
|
+
- spec/ar-serialize-helpers/json_spec.rb
|
70
|
+
- spec/spec_helper.rb
|
71
|
+
has_rdoc: true
|
72
|
+
homepage: http://github.com/EmberAds/ar-serialize-helpers
|
73
|
+
licenses: []
|
74
|
+
|
75
|
+
post_install_message:
|
76
|
+
rdoc_options: []
|
77
|
+
|
78
|
+
require_paths:
|
79
|
+
- lib
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
segments:
|
86
|
+
- 0
|
87
|
+
version: "0"
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
segments:
|
94
|
+
- 0
|
95
|
+
version: "0"
|
96
|
+
requirements: []
|
97
|
+
|
98
|
+
rubyforge_project:
|
99
|
+
rubygems_version: 1.3.7
|
100
|
+
signing_key:
|
101
|
+
specification_version: 3
|
102
|
+
summary: Helpers for ActiveRecord's serialize in rails 3
|
103
|
+
test_files: []
|
104
|
+
|