serialist 1.1.0 → 1.2.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
@@ -39,15 +39,11 @@ Now in version 1.0.0, fully tested.
39
39
 
40
40
  == Install the gem!
41
41
 
42
- $ sudo gem install serialist
42
+ sudo gem install serialist
43
43
 
44
44
  == Try the demo!
45
-
46
- $ sudo gem install sqlite3-ruby
47
- $ rails -m http://github.com/bbenezech/serialist/raw/master/installation-template.txt serialist-example
48
- $ cd serialist-example
49
- $ ./script/server
50
- open localhost:3000 and create an article
45
+
46
+ rails -m http://github.com/bbenezech/serialist/raw/master/installation-template.txt serialist-example
51
47
 
52
48
  == Or simply generate a migration for your existing rails app!
53
49
 
@@ -81,7 +77,7 @@ Then hook Serialist into your ActiveRecord model :
81
77
 
82
78
  Allows you to serialize only the desired keys. ex :
83
79
 
84
- $ ./script/console
80
+ ./script/console
85
81
  >> Article.create!
86
82
  => 'foo cannot be blank'
87
83
  >> a = Article.new
@@ -108,7 +104,7 @@ Allows you to serialize only the desired keys. ex :
108
104
 
109
105
  Allows you to serialize anything. ex :
110
106
 
111
- $ ./script/console
107
+ ./script/console
112
108
  >> Article.create!
113
109
  => 'foo cannot be blank'
114
110
  >> a = Article.new
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.0
1
+ 1.2.0
@@ -20,28 +20,35 @@ module Serialist
20
20
  @serialist_options.each do |field|
21
21
  cols = self.columns.map{|c|c.name.to_s}
22
22
  raise Exception.new("Column #{field} already exist for #{self.name}") if cols.include?(field.to_s)
23
- define_access_methods(field)
23
+ define_access_method(field.to_s)
24
+ define_access_method(field.to_s + "?")
25
+ define_access_method(field.to_s + "=")
24
26
  end
25
27
  end
26
28
  end
27
29
 
28
- def define_access_methods(field)
30
+ def define_access_method(method)
29
31
  serialist_field = self.serialist_field
30
- define_method field.to_s do
31
- return nil unless (slug = self.send(serialist_field))
32
- slug[field.to_sym]
33
- end
34
- define_method field.to_s + "?" do |*param|
35
- return false unless (slug = self.send(serialist_field))
36
- if param.empty?
37
- ![nil, false, "false", :false, "0"].include?(slug[field.to_sym])
38
- else
39
- slug[field.to_sym] == param.first
32
+ case method.last
33
+ when "?"
34
+ define_method method do |*param|
35
+ return false unless (slug = self.send(serialist_field))
36
+ if param.empty?
37
+ ![nil, false, "false", :false, "0"].include?(slug[method[0..-2].to_sym])
38
+ else
39
+ slug[method[0..-2].to_sym] == param.first
40
+ end
41
+ end
42
+ when "="
43
+ define_method method do |param|
44
+ self.send(serialist_field.to_s + "=", Hash.new) unless self.send(serialist_field)
45
+ self.send(serialist_field)[method[0..-2].to_sym] = param
46
+ end
47
+ else
48
+ define_method method do
49
+ return nil unless (slug = self.send(serialist_field))
50
+ slug[method.to_sym]
40
51
  end
41
- end
42
- define_method field.to_s + "=" do |param|
43
- self.send(serialist_field.to_s + "=", Hash.new) unless self.send(serialist_field)
44
- self.send(serialist_field)[field.to_sym] = param
45
52
  end
46
53
  end
47
54
 
@@ -59,7 +66,8 @@ module Serialist
59
66
  attributes.stringify_keys!
60
67
  attributes.each do |k, v|
61
68
  unless k.include?("(") || respond_to?(k)
62
- self.class.define_access_methods(k)
69
+ self.class.define_access_method(k + "=") unless respond_to?("#{k}=") # for mass-affectation
70
+ self.class.define_access_method(k) # for validation
63
71
  end
64
72
  end
65
73
  super
@@ -69,7 +77,7 @@ module Serialist
69
77
  begin
70
78
  super
71
79
  rescue NoMethodError
72
- self.class.define_access_methods(method.to_s.chomp("=").chomp("?"))
80
+ self.class.define_access_method(method.to_s)
73
81
  self.send(method, *args, &block)
74
82
  end
75
83
  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 = "1.1.0"
8
+ s.version = "1.2.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-10-29}
12
+ s.date = %q{2010-01-29}
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 = [
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: 1.1.0
4
+ version: 1.2.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-10-29 00:00:00 +01:00
12
+ date: 2010-01-29 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies: []
15
15