classy_enum 4.0.0 → 4.0.1.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +12 -0
- data/lib/classy_enum/active_record.rb +2 -2
- data/lib/classy_enum/version.rb +1 -1
- data/spec/classy_enum/active_record_spec.rb +21 -0
- data/spec/spec_helper.rb +1 -0
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e979d4b03dc2cb8459da434c579f38aca41dfe9f
|
4
|
+
data.tar.gz: 88a383a5a3afe04fb35fcc3c41ff5618ca2aca0d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5d53d1be8df63e19beb763cda458cd4303c1f25e3fa308c402573d51403766b2699239ff5b1abca0f9b00e513958d4bfd3228205324f0e46ba9e3ee6ae72f303
|
7
|
+
data.tar.gz: dda8018abaacc1aba9e11673b1efd250979ef0971293cda9b6b615a0af610e8e7045c6ac2bc2cd99ae5e1470b170b3399f59441fd9e37e294ff17a33c15dabb1
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -19,6 +19,18 @@ This README is also available in a [user-friendly DocumentUp format](http://beer
|
|
19
19
|
|
20
20
|
The gem is hosted at [rubygems.org](https://rubygems.org/gems/classy_enum)
|
21
21
|
|
22
|
+
Despite [RailsGuides](http://guides.rubyonrails.org/configuring.html#rails-general-configuration)
|
23
|
+
claiming that all directories under app will be autoloaded,
|
24
|
+
I've had [reports](https://github.com/beerlington/classy_enum/issues/50)
|
25
|
+
of this not being the case with newer versions of Ruby and Rails.
|
26
|
+
|
27
|
+
You may need to add the enums path to **config/application.rb**:
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
# Make sure classy_enum enums get loaded
|
31
|
+
config.autoload_paths += %W(#{config.root}/app/enums)
|
32
|
+
```
|
33
|
+
|
22
34
|
## Upgrading?
|
23
35
|
|
24
36
|
See the [wiki](https://github.com/beerlington/classy_enum/wiki/Upgrading) for notes about upgrading from previous versions.
|
@@ -75,7 +75,7 @@ module ClassyEnum
|
|
75
75
|
|
76
76
|
# Define getter method that returns a ClassyEnum instance
|
77
77
|
define_method attribute do
|
78
|
-
enum.build(read_attribute(attribute), owner: self)
|
78
|
+
enum.build(read_attribute(attribute) || super(), owner: self)
|
79
79
|
end
|
80
80
|
|
81
81
|
# Define setter method that accepts string, symbol, instance or class for member
|
@@ -109,7 +109,7 @@ module ClassyEnum
|
|
109
109
|
# database and make it searchable.
|
110
110
|
if default.present?
|
111
111
|
after_initialize do
|
112
|
-
value = read_attribute(attribute)
|
112
|
+
value = read_attribute(attribute) || send(attribute)
|
113
113
|
|
114
114
|
if (value.blank? && !(allow_blank || allow_nil)) || (value.nil? && !allow_nil)
|
115
115
|
send("#{attribute}=", default)
|
data/lib/classy_enum/version.rb
CHANGED
@@ -9,6 +9,7 @@ ActiveRecord::Schema.define(version: 1) do
|
|
9
9
|
t.string :color
|
10
10
|
t.string :name
|
11
11
|
t.integer :age
|
12
|
+
t.text :properties
|
12
13
|
end
|
13
14
|
|
14
15
|
create_table :cats, force: true do |t|
|
@@ -273,6 +274,26 @@ describe Dog, 'with invalid default value' do
|
|
273
274
|
end
|
274
275
|
end
|
275
276
|
|
277
|
+
class Bark < ClassyEnum::Base; end
|
278
|
+
class Bark::Quiet < Bark; end;
|
279
|
+
class Bark::Loud < Bark; end;
|
280
|
+
|
281
|
+
class StoreDog < Dog
|
282
|
+
store :properties, accessors: [:bark]
|
283
|
+
classy_enum_attr :bark
|
284
|
+
end
|
285
|
+
|
286
|
+
describe StoreDog, rails_3: :broken do
|
287
|
+
subject { StoreDog.new(bark: :loud) }
|
288
|
+
it { should be_valid }
|
289
|
+
|
290
|
+
it 'persists the enum in a store accessor' do
|
291
|
+
subject.save!
|
292
|
+
subject.reload
|
293
|
+
subject.bark.should be_a(Bark::Loud)
|
294
|
+
end
|
295
|
+
end
|
296
|
+
|
276
297
|
class Cat < ActiveRecord::Base
|
277
298
|
include ClassyEnum::ActiveRecord
|
278
299
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: classy_enum
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.0.
|
4
|
+
version: 4.0.1.beta1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Brown
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-07-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -124,12 +124,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
124
124
|
version: '0'
|
125
125
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
126
126
|
requirements:
|
127
|
-
- - "
|
127
|
+
- - ">"
|
128
128
|
- !ruby/object:Gem::Version
|
129
|
-
version:
|
129
|
+
version: 1.3.1
|
130
130
|
requirements: []
|
131
131
|
rubyforge_project:
|
132
|
-
rubygems_version: 2.4.
|
132
|
+
rubygems_version: 2.4.6
|
133
133
|
signing_key:
|
134
134
|
specification_version: 4
|
135
135
|
summary: A class based enumerator utility for Ruby on Rails
|