sql_enum 0.1.12 → 0.1.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +33 -9
- data/lib/active_record/enum_override.rb +2 -2
- data/lib/sql_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: ce90a2e4897fcd727d61edf003d995101a46ac2c
|
4
|
+
data.tar.gz: 66bba70c732b919b3f144d21e71ba67925e40b1e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eb04fcc1b92f9d95b7933fbee610b6fa7a5165110dbe734e12ffb72dc023154ecbe80b27beeb8da3c636468801a68052c79337d69b68ae32b2ef2078d5a6ab54
|
7
|
+
data.tar.gz: 0f0046362ce7cad3ef82a3fe28c301416d67c8e12c206bc98c0c44626c2735df53f8219ebdf1411312b19799effd6b1c6aebd603e4b9ce9012b6e4b49e66d82d
|
data/README.md
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
# SqlEnum
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
3
|
+
Enables usage of native sql enums with ActiveRecord
|
6
4
|
|
7
5
|
## Installation
|
8
6
|
|
@@ -22,22 +20,48 @@ Or install it yourself as:
|
|
22
20
|
|
23
21
|
## Usage
|
24
22
|
|
25
|
-
|
23
|
+
### Migrations
|
26
24
|
|
27
|
-
|
25
|
+
Use a part of table definition:
|
26
|
+
```ruby
|
27
|
+
class CreateUsers < ActiveRecord::Migration[5.1]
|
28
|
+
def change
|
29
|
+
create_table :users do |t|
|
30
|
+
t.enum :status, limit: [:active, :pending, :inactive], default: :active
|
31
|
+
|
32
|
+
t.timestamps
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
```
|
28
37
|
|
29
|
-
|
38
|
+
Or add an enum column:
|
39
|
+
```ruby
|
40
|
+
add_column :users, :status, :enum, limit: [:active, :pending, :inactive], default: :active
|
41
|
+
```
|
30
42
|
|
31
|
-
|
43
|
+
### ActiveRecord
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
class User < ActiveRecord::Base
|
47
|
+
sql_enum :status
|
48
|
+
end
|
49
|
+
```
|
50
|
+
|
51
|
+
## TODO
|
52
|
+
|
53
|
+
* Enable passing `null` argument
|
32
54
|
|
33
55
|
## Contributing
|
34
56
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
57
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/1debit/sql_enum. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
36
58
|
|
37
59
|
## License
|
38
60
|
|
61
|
+
Inspiration from [native_enum](https://github.com/iangreenleaf/native_enum)
|
62
|
+
|
39
63
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
40
64
|
|
41
65
|
## Code of Conduct
|
42
66
|
|
43
|
-
Everyone interacting in the SqlEnum project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/
|
67
|
+
Everyone interacting in the SqlEnum project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/1debit/sql_enum/blob/master/CODE_OF_CONDUCT.md).
|
@@ -55,11 +55,11 @@ module ActiveRecord
|
|
55
55
|
end
|
56
56
|
|
57
57
|
def values(name)
|
58
|
-
schema_values(name).scan(/\w+/).reject{|v| v == 'enum'}
|
58
|
+
schema_values(name).to_s.scan(/\w+/).reject{|v| v == 'enum'}
|
59
59
|
end
|
60
60
|
|
61
61
|
def schema_values(name)
|
62
|
-
ActiveRecord::Base.connection.exec_query(schema_values_query(name)).rows
|
62
|
+
ActiveRecord::Base.connection.exec_query(schema_values_query(name)).rows.dig(0,0)
|
63
63
|
end
|
64
64
|
|
65
65
|
def schema_values_query(name)
|
data/lib/sql_enum/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sql_enum
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fletcher Fowler
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-03-
|
11
|
+
date: 2018-03-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|