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 CHANGED
@@ -1,3 +1,7 @@
1
+ # 1.1.0
2
+
3
+ - Create `getter?` methods for attributes with default boolean values
4
+
1
5
  # 1.0.2
2
6
 
3
7
  - Allow attributes to be set during initialization
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- has_serialized (1.0.2)
4
+ has_serialized (1.1.0)
5
5
  activerecord (~> 3.0)
6
6
 
7
7
  GEM
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: /Users/dev/src/has_serialized
3
3
  specs:
4
- has_serialized (1.0.2)
4
+ has_serialized (1.1.0)
5
5
  activerecord (~> 3.0)
6
6
 
7
7
  GEM
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: /Users/dev/src/has_serialized
3
3
  specs:
4
- has_serialized (1.0.2)
4
+ has_serialized (1.1.0)
5
5
  activerecord (~> 3.0)
6
6
 
7
7
  GEM
@@ -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.keys.each do |k|
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 = "set_default_#{serialized}"
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
@@ -1,3 +1,3 @@
1
1
  module HasSerialized
2
- VERSION = '1.0.2'
2
+ VERSION = '1.1.0'
3
3
  end
@@ -1,3 +1,3 @@
1
1
  class Page < ActiveRecord::Base
2
- has_serialized :dynamic_attributes, gunslinger: true, lowmen: true, jake: true
2
+ has_serialized :dynamic_attributes, gunslinger: true, lowmen: true, jake: true, ka_tet: 'none'
3
3
  end
@@ -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.2
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: 2106480265213777068
122
+ hash: 3198233213287663380
123
123
  required_rubygems_version: !ruby/object:Gem::Requirement
124
124
  none: false
125
125
  requirements: