classy_enum 3.1.1 → 3.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml CHANGED
@@ -1,8 +1,8 @@
1
1
  language: ruby
2
2
  rvm:
3
3
  - 1.8.7
4
- - 1.9.2
5
4
  - 1.9.3
5
+ - 2.0.0
6
6
  gemfile:
7
7
  - gemfiles/Gemfile.rails-3.0.x
8
8
  - gemfiles/Gemfile.rails-3.1.x
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # ClassyEnum Changelog
2
2
 
3
+ ## 3.1.2
4
+
5
+ * Allow enum property to be assigned using enum class. Previously it
6
+ could only be assigned with an instance, string or symbol.
7
+
8
+ @alarm.priority = Priority::Medium
9
+ @alarm.priority.medium? # => true
10
+
3
11
  ## 3.1.1
4
12
 
5
13
  * Fixes a regression with Formtastic support. ClassyEnumm::Base.build now
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2010 Peter Brown
1
+ Copyright (c) 2010-2013 Peter Brown
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -13,7 +13,6 @@ ClassyEnum is a Ruby on Rails gem that adds class-based enumerator functionality
13
13
  * [Serializing as JSON](https://github.com/beerlington/classy_enum#serializing-as-json)
14
14
  * [Special Cases](https://github.com/beerlington/classy_enum#special-cases)
15
15
  * [Built-in Model Validation](https://github.com/beerlington/classy_enum#model-validation)
16
- * [Using Enums Outside of ActiveRecord](https://github.com/beerlington/classy_enum#working-with-classyenum-outside-of-activerecord)
17
16
  * [Formtastic Support](https://github.com/beerlington/classy_enum#formtastic-support)
18
17
 
19
18
  ## Rails & Ruby Versions Supported
@@ -297,19 +296,6 @@ end
297
296
  @alarm.valid? # => true
298
297
  ```
299
298
 
300
- ## Working with ClassyEnum outside of ActiveRecord
301
-
302
- While ClassyEnum was designed to be used directly with ActiveRecord, it can also be used outside of it. Here are some examples based on the enum class defined earlier in this document.
303
-
304
- Instantiate an enum member subclass *Priority::Low*
305
-
306
- ```ruby
307
- # These statements are all equivalent
308
- low = Priority.find(:low)
309
- low = Priority.find('low')
310
- low = Priority::Low.new
311
- ```
312
-
313
299
  ## Formtastic Support
314
300
 
315
301
  Built-in Formtastic support has been removed as of 2.0. It is still
@@ -322,4 +308,4 @@ Note: ClassyEnum respects the `:allow_blank` and `:allow_nil` options and will i
322
308
 
323
309
  ## Copyright
324
310
 
325
- Copyright (c) 2012 [Peter Brown](https://github.com/beerlington). See LICENSE for details.
311
+ Copyright (c) 2010-2013 [Peter Brown](https://github.com/beerlington). See LICENSE for details.
@@ -42,9 +42,14 @@ module ClassyEnum
42
42
  )
43
43
  end
44
44
 
45
- # Define setter method that accepts either string or symbol for member
45
+ # Define setter method that accepts string, symbol, instance or class for member
46
46
  define_method "#{attribute}=" do |value|
47
- value = value.to_s unless value.nil?
47
+ if value.class == Class && value < ClassyEnum::Base
48
+ value = value.new
49
+ elsif value.present?
50
+ value = value.to_s
51
+ end
52
+
48
53
  super(value)
49
54
  end
50
55
  end
@@ -1,3 +1,3 @@
1
1
  module ClassyEnum
2
- VERSION = "3.1.1"
2
+ VERSION = "3.1.2"
3
3
  end
@@ -43,7 +43,7 @@ describe Dog do
43
43
  specify { Dog.new(:breed => '').should_not be_valid }
44
44
 
45
45
  context "with valid breed options" do
46
- [:golden_retriever, 'golden_retriever', Breed::GoldenRetriever.new].each do |option|
46
+ [:golden_retriever, 'golden_retriever', Breed::GoldenRetriever.new, Breed::GoldenRetriever].each do |option|
47
47
  subject { Dog.new(:breed => option) }
48
48
  it { should be_valid }
49
49
  its(:breed) { should be_a(Breed::GoldenRetriever) }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: classy_enum
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.1
4
+ version: 3.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-21 00:00:00.000000000 Z
12
+ date: 2013-01-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -126,7 +126,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
126
126
  version: '0'
127
127
  segments:
128
128
  - 0
129
- hash: 2229881947389413323
129
+ hash: -961904907621879072
130
130
  required_rubygems_version: !ruby/object:Gem::Requirement
131
131
  none: false
132
132
  requirements:
@@ -135,7 +135,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
135
135
  version: '0'
136
136
  segments:
137
137
  - 0
138
- hash: 2229881947389413323
138
+ hash: -961904907621879072
139
139
  requirements: []
140
140
  rubyforge_project:
141
141
  rubygems_version: 1.8.24