power_enum 0.4.2 → 0.4.3
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.
data/README.md
CHANGED
@@ -5,7 +5,7 @@ Enumerations for Rails 3.X Done Right.
|
|
5
5
|
## What is this?:
|
6
6
|
|
7
7
|
Power Enum allows you to treat instances of your ActiveRecord models as though they were an enumeration of values.
|
8
|
-
It allows you to cleanly solve many of the problems that the traditional Rails alternatives
|
8
|
+
It allows you to cleanly solve many of the problems that the traditional Rails alternatives handle poorly if at all.
|
9
9
|
It is particularly suitable for scenarios where your Rails application is not the only user of the database, such as
|
10
10
|
when it's used for analytics or reporting.
|
11
11
|
|
@@ -144,6 +144,7 @@ is the equivalent of
|
|
144
144
|
create_table :booking_statuses do |t|
|
145
145
|
t.string :name, :null => false
|
146
146
|
end
|
147
|
+
add_index :booking_statuses, [:name], :unique => true
|
147
148
|
|
148
149
|
In a more complex case:
|
149
150
|
|
@@ -162,6 +163,9 @@ is the equivalent of
|
|
162
163
|
t.boolean :active, :null => false, :default => true
|
163
164
|
t.timestamps
|
164
165
|
end
|
166
|
+
add_index :booking_statuses, [:booking_name], :unique => true
|
167
|
+
|
168
|
+
Notice that a unique index is automatically created.
|
165
169
|
|
166
170
|
##### `remove_enum(enum_name)`
|
167
171
|
|
@@ -49,10 +49,9 @@ module ActiveRecord
|
|
49
49
|
# Returns all the enum values. Caches results after the first time this method is run.
|
50
50
|
def all
|
51
51
|
return @all if @all
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
).collect{|val| val.freeze}.freeze
|
52
|
+
conditions = read_inheritable_attribute(:acts_enumerated_conditions)
|
53
|
+
order = read_inheritable_attribute(:acts_enumerated_order)
|
54
|
+
@all = where(conditions).order(order).collect{|val| val.freeze}.freeze
|
56
55
|
end
|
57
56
|
|
58
57
|
# Returns all the active enum values. See the 'active?' instance method.
|
@@ -1,3 +1,6 @@
|
|
1
|
+
# Copyright (c) 2011 Arthur Shagall
|
2
|
+
# Released under the MIT license. See LICENSE for details.
|
3
|
+
|
1
4
|
module PowerEnum::Schema
|
2
5
|
module SchemaStatements
|
3
6
|
|
@@ -35,6 +38,7 @@ module PowerEnum::Schema
|
|
35
38
|
# create_table :connector_types do |t|
|
36
39
|
# t.string :name, :null => false
|
37
40
|
# end
|
41
|
+
# add_index :connector_types, [:name], :unique => true
|
38
42
|
#
|
39
43
|
# ====== Advanced Enum
|
40
44
|
# create_enum :connector_type, :name_column => :connector,
|
@@ -50,7 +54,9 @@ module PowerEnum::Schema
|
|
50
54
|
# t.boolean :active, :null => false, :default => true
|
51
55
|
# t.timestamps
|
52
56
|
# end
|
57
|
+
# add_index :connector_types, [:connector], :unique => true
|
53
58
|
#
|
59
|
+
# Notice that a unique index is automatically created.
|
54
60
|
def create_enum(enum_name, options = {})
|
55
61
|
enum_table_name = enum_name.pluralize
|
56
62
|
name_column = options[:name_column] || :name
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: power_enum
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -12,11 +12,11 @@ authors:
|
|
12
12
|
autorequire:
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
|
-
date: 2011-09-
|
15
|
+
date: 2011-09-29 00:00:00.000000000Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: rails
|
19
|
-
requirement: &
|
19
|
+
requirement: &17672400 !ruby/object:Gem::Requirement
|
20
20
|
none: false
|
21
21
|
requirements:
|
22
22
|
- - ! '>='
|
@@ -24,10 +24,10 @@ dependencies:
|
|
24
24
|
version: 3.0.0
|
25
25
|
type: :runtime
|
26
26
|
prerelease: false
|
27
|
-
version_requirements: *
|
27
|
+
version_requirements: *17672400
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: jeweler
|
30
|
-
requirement: &
|
30
|
+
requirement: &17671920 !ruby/object:Gem::Requirement
|
31
31
|
none: false
|
32
32
|
requirements:
|
33
33
|
- - ! '>='
|
@@ -35,10 +35,10 @@ dependencies:
|
|
35
35
|
version: '0'
|
36
36
|
type: :development
|
37
37
|
prerelease: false
|
38
|
-
version_requirements: *
|
38
|
+
version_requirements: *17671920
|
39
39
|
- !ruby/object:Gem::Dependency
|
40
40
|
name: rspec
|
41
|
-
requirement: &
|
41
|
+
requirement: &17671420 !ruby/object:Gem::Requirement
|
42
42
|
none: false
|
43
43
|
requirements:
|
44
44
|
- - ! '>='
|
@@ -46,10 +46,10 @@ dependencies:
|
|
46
46
|
version: '0'
|
47
47
|
type: :development
|
48
48
|
prerelease: false
|
49
|
-
version_requirements: *
|
49
|
+
version_requirements: *17671420
|
50
50
|
- !ruby/object:Gem::Dependency
|
51
51
|
name: sqlite3
|
52
|
-
requirement: &
|
52
|
+
requirement: &17670900 !ruby/object:Gem::Requirement
|
53
53
|
none: false
|
54
54
|
requirements:
|
55
55
|
- - ! '>='
|
@@ -57,10 +57,10 @@ dependencies:
|
|
57
57
|
version: '0'
|
58
58
|
type: :development
|
59
59
|
prerelease: false
|
60
|
-
version_requirements: *
|
60
|
+
version_requirements: *17670900
|
61
61
|
- !ruby/object:Gem::Dependency
|
62
62
|
name: genspec
|
63
|
-
requirement: &
|
63
|
+
requirement: &17670200 !ruby/object:Gem::Requirement
|
64
64
|
none: false
|
65
65
|
requirements:
|
66
66
|
- - ! '>='
|
@@ -68,12 +68,12 @@ dependencies:
|
|
68
68
|
version: '0'
|
69
69
|
type: :development
|
70
70
|
prerelease: false
|
71
|
-
version_requirements: *
|
71
|
+
version_requirements: *17670200
|
72
72
|
description: ! 'Power Enum allows you to treat instances of your ActiveRecord models
|
73
73
|
as though they were an enumeration of values.
|
74
74
|
|
75
75
|
It allows you to cleanly solve many of the problems that the traditional Rails alternatives
|
76
|
-
|
76
|
+
handle poorly if at all.
|
77
77
|
|
78
78
|
It is particularly suitable for scenarios where your Rails application is not the
|
79
79
|
only user of the database, such as
|