has_serialized 1.0.2 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +1 -1
- data/gemfiles/activerecord3.0.x.gemfile.lock +1 -1
- data/gemfiles/activerecord3.x.gemfile.lock +1 -1
- data/lib/has_serialized/class_methods.rb +11 -2
- data/lib/has_serialized/version.rb +1 -1
- data/spec/fixtures/page.rb +1 -1
- data/spec/has_serialized_spec.rb +7 -0
- metadata +2 -2
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -8,11 +8,19 @@ module HasSerialized
|
|
8
8
|
# Creates the accessors so that you can assign values like so:
|
9
9
|
# record.my_own_attribute = value
|
10
10
|
# record.my_own_attribute # value
|
11
|
+
# record.my_own_attribute? # if value is true of false
|
11
12
|
def self.serialized_attr_accessor(serialized, accessors)
|
12
|
-
accessors.
|
13
|
+
accessors.each do |k, v|
|
13
14
|
define_method("#{k}") do
|
14
15
|
self[serialized] && self[serialized][k]
|
15
16
|
end
|
17
|
+
|
18
|
+
if !!v == v
|
19
|
+
define_method("#{k}?") do
|
20
|
+
self[serialized] && self[serialized][k]
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
16
24
|
define_method("#{k}=") do |value|
|
17
25
|
self[serialized] ||= {}
|
18
26
|
self[serialized][k] = value
|
@@ -22,7 +30,7 @@ module HasSerialized
|
|
22
30
|
|
23
31
|
# Sets the default value of the serialized field
|
24
32
|
def self.default_serialized_attr(serialized, accessors)
|
25
|
-
method_name =
|
33
|
+
method_name = "set_default_#{serialized}"
|
26
34
|
after_initialize method_name
|
27
35
|
|
28
36
|
define_method(method_name) do
|
@@ -34,6 +42,7 @@ module HasSerialized
|
|
34
42
|
end
|
35
43
|
end
|
36
44
|
end
|
45
|
+
|
37
46
|
end
|
38
47
|
end
|
39
48
|
end
|
data/spec/fixtures/page.rb
CHANGED
data/spec/has_serialized_spec.rb
CHANGED
@@ -26,4 +26,11 @@ describe HasSerialized do
|
|
26
26
|
expect(page.lowmen).to be_true
|
27
27
|
expect(page.jake).to eq(false)
|
28
28
|
end
|
29
|
+
|
30
|
+
it 'should create getters that end with question marks for boolean fields' do
|
31
|
+
page = Page.new(gunslinger: false, jake: true)
|
32
|
+
expect(page.gunslinger?).to be_false
|
33
|
+
expect(page.jake?).to be_true
|
34
|
+
expect(page).to_not respond_to(:ka_tet?)
|
35
|
+
end
|
29
36
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: has_serialized
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -119,7 +119,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
119
119
|
version: '0'
|
120
120
|
segments:
|
121
121
|
- 0
|
122
|
-
hash:
|
122
|
+
hash: 3198233213287663380
|
123
123
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
124
124
|
none: false
|
125
125
|
requirements:
|