pg_activerecord_enum 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +7 -7
- data/lib/pg_activerecord_enum.rb +2 -2
- data/lib/pg_activerecord_enum/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 86899f2fd76d82fd51e37a540b7548211d07d167
|
4
|
+
data.tar.gz: 469fb6907906238115839004d2f5c667ddf127dc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cf1b2dfb1b84d758e4a54db7ead10e447e3443364c682e6d46e13fc311b6a96de0c120a1c394a835630aaed883dcd2226a42406cfeb54cbbd1329d3477d69c20
|
7
|
+
data.tar.gz: 7572c4c9b29ecb5e86b5172927a9d616e433e869ec130b441e868b4b6409fba97147f3cdee913810d804774b0ed8d1a68b90d675672e5bd11f2b9571911abf86
|
data/README.md
CHANGED
@@ -48,7 +48,7 @@ Or for existing table:
|
|
48
48
|
```ruby
|
49
49
|
class CreateFruits < ActiveRecord::Migration[5.1]
|
50
50
|
def change
|
51
|
-
add_enum :fruits, :color, values: %i[red green yellow], allow_blank: true
|
51
|
+
add_enum :fruits, :color, values: %i[red green yellow orange], allow_blank: true
|
52
52
|
end
|
53
53
|
end
|
54
54
|
```
|
@@ -62,19 +62,19 @@ Model:
|
|
62
62
|
```ruby
|
63
63
|
class Fruit < ApplicationRecord
|
64
64
|
pg_enum :fruit_type
|
65
|
-
pg_enum :color
|
65
|
+
pg_enum :color, _prefix: true
|
66
66
|
end
|
67
67
|
```
|
68
68
|
|
69
69
|
```ruby
|
70
70
|
Fruit.banana.count # 0
|
71
71
|
banana = Fruit.banana.create
|
72
|
-
banana.yellow!
|
73
72
|
banana.banana? # true
|
74
|
-
banana.
|
75
|
-
banana.
|
76
|
-
|
77
|
-
|
73
|
+
banana.orange! #
|
74
|
+
banana.orange? # true
|
75
|
+
Fruit.orange.count # 1
|
76
|
+
banana.color_orange!
|
77
|
+
banana.color # "orange"
|
78
78
|
```
|
79
79
|
|
80
80
|
In PostgreSQL DB:
|
data/lib/pg_activerecord_enum.rb
CHANGED
@@ -67,9 +67,9 @@ WHERE t.typname = '#{name}'
|
|
67
67
|
"'#{values.join("', '")}'"
|
68
68
|
end
|
69
69
|
|
70
|
-
def pg_enum(name)
|
70
|
+
def pg_enum(name, options = {})
|
71
71
|
enum_values = PgActiveRecordEnum.values_for(name).reject(&:blank?)
|
72
|
-
enum
|
72
|
+
enum({name => enum_values.zip(enum_values).to_h}.merge(options))
|
73
73
|
end
|
74
74
|
end
|
75
75
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pg_activerecord_enum
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- inpego
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-02-
|
11
|
+
date: 2018-02-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|