serialist 0.4.0 → 0.5.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/README.rdoc CHANGED
@@ -3,7 +3,7 @@
3
3
  Serialize anything. Why waste time migrating your table for yet another dumb attribute you won't search on?
4
4
  Add one serializable field in your table, and let serialist do the rest.
5
5
 
6
- === Before :
6
+ === Before!
7
7
 
8
8
  class Article < ActiveRecord::Base
9
9
  serialize :preferences
@@ -15,7 +15,7 @@ Add one serializable field in your table, and let serialist do the rest.
15
15
  >> a.preferences[:key]
16
16
  => "value"
17
17
 
18
- === After :
18
+ === After!
19
19
 
20
20
  class Article < ActiveRecord::Base
21
21
  serialist :preferences, [:key, :other_key, :yet_another_key]
@@ -33,17 +33,19 @@ Add one serializable field in your table, and let serialist do the rest.
33
33
  == Try the demo!
34
34
 
35
35
  $ sudo gem install sqlite3-ruby
36
- $ rails -m http://gist.github.com/183689.txt serialist-example
36
+ $ rails -m http://github.com/bbenezech/serialist/raw/master/installation-template.txt serialist-example
37
37
  $ cd serialist-example
38
38
  $ ./script/server
39
- $ GoTo localhost:3000 and create an article
39
+ open localhost:3000 and create an article
40
40
 
41
- == Or generate a migration for your existing programm
41
+ == Or simply generate a migration for your existing rails app!
42
42
 
43
43
  ./script/generate serialist SerialistMigration MyModel my_serialist_attribute
44
+
44
45
  Ex :
45
46
 
46
47
  ./script/generate serialist SerialistMigration Article slug
48
+ rake db:migrate
47
49
 
48
50
  Then hook Serialist into your ActiveRecord model :
49
51
 
@@ -56,19 +58,25 @@ Then hook Serialist into your ActiveRecord model :
56
58
  validates_presence_of :bar
57
59
  # etc.
58
60
 
59
- == Serialist comes in 2 flavors:
61
+ == Serialist comes in TWO flavors!
60
62
 
61
63
  === Specific declaration (safe, use define_method)
62
64
 
63
- serialist :my_serializer_attribute, [:foo, :bar]
65
+ serialist :slug, [:foo, :bar]
64
66
 
65
67
  Allows you to serialize only the desired keys. ex :
66
68
 
67
69
  $ ./script/console
68
70
  >> a = Article.new
69
71
  => #<Article id: nil, title: nil, created_at: nil, updated_at: nil, slug: nil>
72
+ >> a.foo?
73
+ => false
74
+ >> a.foo
75
+ => nil
70
76
  >> a.foo = "hello"
71
77
  => "hello"
78
+ >> a.foo?
79
+ => true
72
80
  >> a.taz = "hello"
73
81
  => NoMethodError: undefined method `taz=' ...
74
82
  >> a
@@ -76,30 +84,44 @@ Allows you to serialize only the desired keys. ex :
76
84
 
77
85
  === Catch-all with method_missing
78
86
 
79
- You should probably choose to load serialist after your other plugins/gems, because ActiveRecord won't fire NoMethodError anymore on Serialisted models, and some plugin may want to catch it to implement their own auto-magic (=== find_all_by_title_and_description kind of magic)
87
+ You should probably choose to load serialist after your other plugins/gems, because ActiveRecord won't fire NoMethodError anymore on Serialisted models, and some plugin may want to catch it to implement their own auto-magic (aka find_all_by_title_and_description magic)
80
88
 
81
89
  # in your model. my_serializer_attribute is the one you specify in the migration
82
90
 
83
- serialist :my_serializer_attribute
91
+ serialist :slug
84
92
 
85
93
  Allows you to serialize anything. ex :
86
94
 
87
95
  $ ./script/console
88
96
  >> a = Article.new
89
97
  => #<Article id: nil, title: nil, created_at: nil, updated_at: nil, slug: nil>
98
+ >> a.foo
99
+ => nil
100
+ >> a.foo?
101
+ => false
90
102
  >> a.foo = "hello"
91
103
  => "hello"
92
104
  >> a.foo?("hello")
93
105
  => true
106
+ >> a.foo?
107
+ => true
94
108
  >> a.foo
95
109
  => "hello"
110
+ >> a.baz?
111
+ => false
112
+ >> a.baz
113
+ => nil
96
114
  >> a
97
115
  => #<Article id: XX, title: nil, created_at: "..", updated_at: "..", slug: {:foo=>"hello"}>
98
116
 
99
- It's not a pure method_missing anyway, I cheated a bit, I use on-demand define_method before mass-assignements.
117
+ == Beware!
118
+
119
+ # Don't use method#2 with Serialist loaded before other ActiveRecord "automagicians" plugins
120
+
121
+ # Watch out for conflict with existing attributes and methods!
100
122
 
101
- == Word of caution:
123
+ # And of course don't serialize attributes you may want to search on, or index on, or use with any other database related stuff.
102
124
 
103
- Other than the specific notice about not using method1 with Serialist loaded before other ActiveRecord "automagicians" plugins, watch out for conflict with existing attributes and methods!
125
+ Copyright (c) 2009 Benoit Bénézech, released under the MIT license
104
126
 
105
- Copyright (c) 2009 Benoit Bénézech, released under the MIT license
127
+ http://rubyonrails.org/images/rails.png
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.0
1
+ 0.5.0
@@ -20,19 +20,19 @@ module Serialist
20
20
  @serialist_options.each do |field|
21
21
  define_method field.to_s do
22
22
  return nil unless (slug = self.send(serialist_field))
23
- slug[field]
23
+ slug[field.to_sym]
24
24
  end
25
25
  define_method field.to_s + "?" do |*param|
26
26
  return false unless (slug = self.send(serialist_field))
27
27
  if param.empty?
28
28
  ![nil, false, "false", :false].include?(slug[field])
29
29
  else
30
- slug[field] == param.first
30
+ slug[field.to_sym] == param.first
31
31
  end
32
32
  end
33
33
  define_method field.to_s + "=" do |param|
34
34
  update_attribute(serialist_field, Hash.new) unless self.send(serialist_field)
35
- self.send(serialist_field)[field] = param
35
+ self.send(serialist_field)[field.to_sym] = param
36
36
  end
37
37
  end
38
38
  end
@@ -55,7 +55,7 @@ module Serialist
55
55
  unless k.include?("(") || respond_to?(:"#{k}=")
56
56
  self.class.send(:define_method, :"#{k}=") do |param|
57
57
  update_attribute(self.class.serialist_field, Hash.new) unless self.send(self.class.serialist_field)
58
- self.send(self.class.serialist_field)[k] = param
58
+ self.send(self.class.serialist_field)[k.to_sym] = param
59
59
  end
60
60
  end
61
61
  end
@@ -67,22 +67,19 @@ module Serialist
67
67
  super
68
68
  rescue NoMethodError
69
69
  slug = self.send(self.class.serialist_field)
70
-
71
70
  case method.to_s.last
72
71
  when "?"
73
72
  slug && slug[method.to_s[0..-2].to_sym] == (args && args.first || "true")
74
-
75
73
  if args.empty?
76
74
  slug && ![nil, false, "false", :false].include?(slug[method.to_s[0..-2].to_sym])
77
75
  else
78
76
  slug && (slug[method.to_s[0..-2].to_sym] == args.first)
79
77
  end
80
-
81
78
  when "="
82
79
  update_attribute(self.class.serialist_field, Hash.new) unless slug
83
80
  self.send(self.class.serialist_field)[method.to_s[0..-2].to_sym] = args.first
84
81
  else
85
- slug && slug[method]
82
+ slug && slug[method.to_sym]
86
83
  end
87
84
  end
88
85
  end
data/serialist.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{serialist}
8
- s.version = "0.4.0"
8
+ s.version = "0.5.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Benoit B\303\251n\303\251zech"]
12
- s.date = %q{2009-09-09}
12
+ s.date = %q{2009-09-16}
13
13
  s.description = %q{Serialize any data, set and fetch it like any column attributes}
14
14
  s.email = %q{benoit.benezech@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -39,7 +39,7 @@ Gem::Specification.new do |s|
39
39
  s.homepage = %q{http://github.com/bbenezech/serialist}
40
40
  s.rdoc_options = ["--charset=UTF-8"]
41
41
  s.require_paths = ["lib"]
42
- s.rubygems_version = %q{1.3.5}
42
+ s.rubygems_version = %q{1.3.4}
43
43
  s.summary = %q{Serialize any data, set and fetch it like any column attributes}
44
44
  s.test_files = [
45
45
  "test/acts_as_serializable_test.rb",
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: serialist
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - "Benoit B\xC3\xA9n\xC3\xA9zech"
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-09-09 00:00:00 +02:00
12
+ date: 2009-09-16 00:00:00 +02:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -65,7 +65,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
65
65
  requirements: []
66
66
 
67
67
  rubyforge_project:
68
- rubygems_version: 1.3.5
68
+ rubygems_version: 1.3.4
69
69
  signing_key:
70
70
  specification_version: 3
71
71
  summary: Serialize any data, set and fetch it like any column attributes