iron-enum 1.0.3 → 1.0.4

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.
@@ -1,3 +1,7 @@
1
+ == 1.0.4 / 2013-06-21
2
+
3
+ * Same as 1.0.4, but add support to model attributes as well (doh)
4
+
1
5
  == 1.0.3 / 2013-06-21
2
6
 
3
7
  * Minor bugfix to allow better handling of setting an enum attr with a blank string as if it were setting to nil
@@ -1 +1 @@
1
- 1.0.3
1
+ 1.0.4
@@ -41,7 +41,8 @@ module Enum
41
41
  #
42
42
  # User.with_user_type(UserType::MEMBER) => scope returning a relation selecting User instances where user_type's value == UserType::MEMBER
43
43
  #
44
- # In addition, enum attributes will show up in #inspect output as e.g. UserType::GUEST instead of 0.
44
+ # In addition, enum attributes will show up in #inspect output as e.g. UserType::GUEST instead of 0. Enum attributes will also generate an
45
+ # automatic inclusion validation to ensure that the attribute never ends up being an invalid value.
45
46
  module AttrSupport
46
47
 
47
48
  # Call with enum_attr :field => Enum
@@ -109,6 +110,7 @@ module Enum
109
110
  # Override default setter to allow setting an enum attribute via key
110
111
  class_eval <<-eos, __FILE__, __LINE__ + 1
111
112
  def #{attr_field}=(val)
113
+ val = nil if val.is_a?(String) && val.empty?
112
114
  write_attribute(:#{attr_field}, #{enum_klass}.value(val))
113
115
  end
114
116
  eos
@@ -91,5 +91,13 @@ describe Enum do
91
91
  @test.should be_valid
92
92
  end
93
93
 
94
+ it 'should support string values' do
95
+ @test.enum_field = '2'
96
+ @test.enum_field.should == 2
97
+ @test.enum_field = ''
98
+ @test.enum_field.should be_nil
99
+ expect { @test.enum_field = '1notreally' }.to raise_error
100
+ end
101
+
94
102
  end
95
103
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iron-enum
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: