rails_attr_enum 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rails_attr_enum.rb +1 -1
- data/lib/rails_attr_enum/version.rb +1 -1
- data/test/dummy/app/models/user.rb +21 -1
- data/test/dummy/db/development.sqlite3 +0 -0
- data/test/dummy/log/development.log +10 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 594e470d58bf61cf2a5a268d001ffd9350ed350d
|
4
|
+
data.tar.gz: 2c06a6695f1830ddd243128fd7ccd40d5e963ced
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d14af5e3c4f4b2b79dc8b7c966e3df7677d3a5b59b026f84005ee1b8a89ea0b24e573fcc90dd6e1f790facc99b0625f6b21eb2633a9798f8f504e5e0764f302d
|
7
|
+
data.tar.gz: 8a94f8c39d9c41c6675c9de3f6cadee2e9814876c51e5df2056c840203b91e4341ba19d0638cb3920edad9e8274da4faee0252173be174965a58c9d634911e10
|
data/lib/rails_attr_enum.rb
CHANGED
@@ -11,7 +11,7 @@ module RailsAttrEnum
|
|
11
11
|
if block_given?
|
12
12
|
add_attr_enum_through_block(attr_name, &block)
|
13
13
|
else
|
14
|
-
if keys.first.is_a?(Hash)
|
14
|
+
if keys.first.is_a?(Hash) && keys.first.size > 1
|
15
15
|
add_attr_enum_through_block(attr_name) do
|
16
16
|
keys.first.each { |k, v| add k => v }
|
17
17
|
end
|
@@ -1,5 +1,25 @@
|
|
1
1
|
class User < ActiveRecord::Base
|
2
2
|
extend RailsAttrEnum
|
3
3
|
|
4
|
-
attr_enum :role, :admin, :author, :editor
|
4
|
+
# attr_enum :role, :admin, :author, :editor, :user
|
5
|
+
# attr_enum :role, :admin, { author: 2 }, :editor, { user: 10 }
|
6
|
+
|
7
|
+
attr_enum :role, { admin: { value: 10, label: 'ADMIN' } },
|
8
|
+
{ author: 'Author Role' },
|
9
|
+
:editor,
|
10
|
+
{ user: { label: 'ID10T', value: 45 } }
|
11
|
+
|
12
|
+
# attr_enum :role, {
|
13
|
+
# admin: 'ADMIN',
|
14
|
+
# author: 'AUTHOR',
|
15
|
+
# editor: 'EDITOR',
|
16
|
+
# user: 'ID10T'
|
17
|
+
# }
|
18
|
+
|
19
|
+
# attr_enum :role do
|
20
|
+
# add admin: 1
|
21
|
+
# add :author
|
22
|
+
# add editor: 42
|
23
|
+
# add user: 7
|
24
|
+
# end
|
5
25
|
end
|
Binary file
|
@@ -22,3 +22,13 @@ Migrating to CreateUsers (20131023212242)
|
|
22
22
|
[1m[36mUser Load (0.2ms)[0m [1mSELECT "users".* FROM "users" ORDER BY "users"."id" ASC LIMIT 1[0m
|
23
23
|
[1m[35mUser Load (0.3ms)[0m SELECT "users".* FROM "users" ORDER BY "users"."id" ASC LIMIT 1
|
24
24
|
[1m[36mUser Load (0.2ms)[0m [1mSELECT "users".* FROM "users"[0m
|
25
|
+
[1m[36mUser Load (0.7ms)[0m [1mSELECT "users".* FROM "users"[0m
|
26
|
+
[1m[35m (0.1ms)[0m begin transaction
|
27
|
+
[1m[36mSQL (17.1ms)[0m [1mDELETE FROM "users" WHERE "users"."id" = ?[0m [["id", 1]]
|
28
|
+
[1m[35m (1.4ms)[0m commit transaction
|
29
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
30
|
+
[1m[35mSQL (0.4ms)[0m DELETE FROM "users" WHERE "users"."id" = ? [["id", 2]]
|
31
|
+
[1m[36m (1.1ms)[0m [1mcommit transaction[0m
|
32
|
+
[1m[35m (0.1ms)[0m begin transaction
|
33
|
+
[1m[36mSQL (0.3ms)[0m [1mDELETE FROM "users" WHERE "users"."id" = ?[0m [["id", 3]]
|
34
|
+
[1m[35m (1.2ms)[0m commit transaction
|