ar_serialized_array 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/{README.markdown → Readme.md} +16 -6
- data/VERSION +1 -1
- data/ar_serialized_array.gemspec +17 -22
- data/spec/ar_serialized_array_spec.rb +5 -0
- data/spec/setup_test_model.rb +3 -5
- metadata +32 -16
@@ -7,34 +7,44 @@ Serialize an array in one column.
|
|
7
7
|
|
8
8
|
Install
|
9
9
|
=======
|
10
|
-
- As Rails plugin: `
|
10
|
+
- As Rails plugin: `rails plugin install git://github.com/grosser/ar_serialized_array.git `
|
11
11
|
- As gem: ` sudo gem install ar_serialized_array `
|
12
12
|
|
13
13
|
|
14
14
|
Usage
|
15
15
|
=====
|
16
16
|
|
17
|
+
# basic / forms
|
17
18
|
class User < ActiveRecord::Base
|
18
|
-
serialized_array :product_ids, :accessor => :product_ids_as_text
|
19
|
+
serialized_array :product_ids, :accessor => :product_ids_as_text
|
19
20
|
end
|
20
21
|
|
22
|
+
<%= form_for @user do |f| %>
|
23
|
+
<%= f.text_field :product_ids_as_text %>
|
24
|
+
<% end %>
|
25
|
+
|
26
|
+
# set / get
|
21
27
|
User.new.product_ids # []
|
22
28
|
|
23
29
|
user.product_ids_as_text = "1, , 12323 , 23, 1"
|
24
30
|
user.product_ids # [1, 12323, 23]
|
25
31
|
user.product_ids_as_text # "1, 12323, 23"
|
26
32
|
|
27
|
-
|
28
|
-
|
33
|
+
# find ...
|
29
34
|
filled = User.all(:conditions => {:product_ids=>[1,3].to_yaml})
|
30
35
|
empty = User.all(:conditions => {:product_ids=>nil})
|
31
36
|
|
37
|
+
# with cleanup (unique integers)
|
38
|
+
class User < ActiveRecord::Base
|
39
|
+
serialized_array :product_ids, :on_set=>lambda{|x| x.map(&:to_i).uniq }
|
40
|
+
end
|
41
|
+
|
32
42
|
TODO
|
33
43
|
====
|
34
44
|
- add support for `user.product_ids << 1`
|
35
45
|
|
36
46
|
Author
|
37
47
|
======
|
38
|
-
[Michael Grosser](http://
|
39
|
-
|
48
|
+
[Michael Grosser](http://grosser.it)
|
49
|
+
michael@grosser.it
|
40
50
|
Hereby placed under public domain, do what you want, just do not hold me accountable...
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.2
|
data/ar_serialized_array.gemspec
CHANGED
@@ -1,46 +1,41 @@
|
|
1
1
|
# Generated by jeweler
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{ar_serialized_array}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Michael Grosser"]
|
12
|
-
s.date = %q{
|
12
|
+
s.date = %q{2011-01-17}
|
13
13
|
s.email = %q{grosser.michael@gmail.com}
|
14
|
-
s.extra_rdoc_files = [
|
15
|
-
"README.markdown"
|
16
|
-
]
|
17
14
|
s.files = [
|
18
|
-
"
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
15
|
+
"Rakefile",
|
16
|
+
"Readme.md",
|
17
|
+
"VERSION",
|
18
|
+
"ar_serialized_array.gemspec",
|
19
|
+
"init.rb",
|
20
|
+
"lib/ar_serialized_array.rb",
|
21
|
+
"spec/ar_serialized_array_spec.rb",
|
22
|
+
"spec/setup_test_model.rb",
|
23
|
+
"spec/spec_helper.rb"
|
27
24
|
]
|
28
25
|
s.homepage = %q{http://github.com/grosser/ar_serialized_array}
|
29
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
30
26
|
s.require_paths = ["lib"]
|
31
|
-
s.rubygems_version = %q{1.
|
27
|
+
s.rubygems_version = %q{1.4.2}
|
32
28
|
s.summary = %q{Serialize an array in a column, [] when no set, xx_as_text accessors and more.}
|
33
29
|
s.test_files = [
|
34
|
-
"spec/
|
35
|
-
|
36
|
-
|
30
|
+
"spec/ar_serialized_array_spec.rb",
|
31
|
+
"spec/setup_test_model.rb",
|
32
|
+
"spec/spec_helper.rb"
|
37
33
|
]
|
38
34
|
|
39
35
|
if s.respond_to? :specification_version then
|
40
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
41
36
|
s.specification_version = 3
|
42
37
|
|
43
|
-
if Gem::Version.new(Gem::
|
38
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
44
39
|
s.add_runtime_dependency(%q<activerecord>, [">= 0"])
|
45
40
|
else
|
46
41
|
s.add_dependency(%q<activerecord>, [">= 0"])
|
@@ -21,6 +21,11 @@ describe 'ar_serialized_array' do
|
|
21
21
|
UserPlain.find(user.id).product_ids.should == []
|
22
22
|
end
|
23
23
|
|
24
|
+
it "stores nil when nil is saved" do
|
25
|
+
user = UserPlain.create!(:product_ids => nil)
|
26
|
+
UserPlain.first(:conditions => {:id => user.id, :product_ids => nil}).should == user
|
27
|
+
end
|
28
|
+
|
24
29
|
it "stores empty arrays as NULL" do
|
25
30
|
user = UserPlain.create!(:product_ids => [])
|
26
31
|
UserPlain.first(:conditions => {:id => user.id, :product_ids => nil}).should == user
|
data/spec/setup_test_model.rb
CHANGED
@@ -1,10 +1,8 @@
|
|
1
1
|
# connect
|
2
|
-
ActiveRecord::Base.
|
2
|
+
ActiveRecord::Base.establish_connection(
|
3
3
|
:adapter => "sqlite3",
|
4
|
-
:database => ":memory:"
|
5
|
-
|
6
|
-
|
7
|
-
ActiveRecord::Base.establish_connection(:test)
|
4
|
+
:database => ":memory:"
|
5
|
+
)
|
8
6
|
|
9
7
|
# create tables
|
10
8
|
ActiveRecord::Schema.define(:version => 1) do
|
metadata
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ar_serialized_array
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 31
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 2
|
10
|
+
version: 0.1.2
|
5
11
|
platform: ruby
|
6
12
|
authors:
|
7
13
|
- Michael Grosser
|
@@ -9,30 +15,34 @@ autorequire:
|
|
9
15
|
bindir: bin
|
10
16
|
cert_chain: []
|
11
17
|
|
12
|
-
date:
|
18
|
+
date: 2011-01-17 00:00:00 +01:00
|
13
19
|
default_executable:
|
14
20
|
dependencies:
|
15
21
|
- !ruby/object:Gem::Dependency
|
16
22
|
name: activerecord
|
17
|
-
|
18
|
-
|
19
|
-
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
20
26
|
requirements:
|
21
27
|
- - ">="
|
22
28
|
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
23
32
|
version: "0"
|
24
|
-
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
25
35
|
description:
|
26
36
|
email: grosser.michael@gmail.com
|
27
37
|
executables: []
|
28
38
|
|
29
39
|
extensions: []
|
30
40
|
|
31
|
-
extra_rdoc_files:
|
32
|
-
|
41
|
+
extra_rdoc_files: []
|
42
|
+
|
33
43
|
files:
|
34
|
-
- README.markdown
|
35
44
|
- Rakefile
|
45
|
+
- Readme.md
|
36
46
|
- VERSION
|
37
47
|
- ar_serialized_array.gemspec
|
38
48
|
- init.rb
|
@@ -45,30 +55,36 @@ homepage: http://github.com/grosser/ar_serialized_array
|
|
45
55
|
licenses: []
|
46
56
|
|
47
57
|
post_install_message:
|
48
|
-
rdoc_options:
|
49
|
-
|
58
|
+
rdoc_options: []
|
59
|
+
|
50
60
|
require_paths:
|
51
61
|
- lib
|
52
62
|
required_ruby_version: !ruby/object:Gem::Requirement
|
63
|
+
none: false
|
53
64
|
requirements:
|
54
65
|
- - ">="
|
55
66
|
- !ruby/object:Gem::Version
|
67
|
+
hash: 3
|
68
|
+
segments:
|
69
|
+
- 0
|
56
70
|
version: "0"
|
57
|
-
version:
|
58
71
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
59
73
|
requirements:
|
60
74
|
- - ">="
|
61
75
|
- !ruby/object:Gem::Version
|
76
|
+
hash: 3
|
77
|
+
segments:
|
78
|
+
- 0
|
62
79
|
version: "0"
|
63
|
-
version:
|
64
80
|
requirements: []
|
65
81
|
|
66
82
|
rubyforge_project:
|
67
|
-
rubygems_version: 1.
|
83
|
+
rubygems_version: 1.4.2
|
68
84
|
signing_key:
|
69
85
|
specification_version: 3
|
70
86
|
summary: Serialize an array in a column, [] when no set, xx_as_text accessors and more.
|
71
87
|
test_files:
|
72
|
-
- spec/spec_helper.rb
|
73
|
-
- spec/setup_test_model.rb
|
74
88
|
- spec/ar_serialized_array_spec.rb
|
89
|
+
- spec/setup_test_model.rb
|
90
|
+
- spec/spec_helper.rb
|