sql_enum 0.1.12 → 0.1.13

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b2a6661434eee78f0a3506bc98acd2b2f42888d8
4
- data.tar.gz: 4c93283aaa4f3b6da308f93568e8fe2787558808
3
+ metadata.gz: ce90a2e4897fcd727d61edf003d995101a46ac2c
4
+ data.tar.gz: 66bba70c732b919b3f144d21e71ba67925e40b1e
5
5
  SHA512:
6
- metadata.gz: bea60e1ca17fd35ba9de34d612e28dbee017252374ef44abb0bfb6f7b5fc410764bd72e3922e06f853d62d8fb86159857d6d6bec9a3a1ea8ddd3355d1e8e63ed
7
- data.tar.gz: 444eed4098f7cfc18e9e49812f3690af2ddd5c92348cf10b6ef9f65c6aeb759cdcf0e7d207e5ec1c8bbf9f46270ceb0871c485e3ef8ff9fabf9158c0362a6402
6
+ metadata.gz: eb04fcc1b92f9d95b7933fbee610b6fa7a5165110dbe734e12ffb72dc023154ecbe80b27beeb8da3c636468801a68052c79337d69b68ae32b2ef2078d5a6ab54
7
+ data.tar.gz: 0f0046362ce7cad3ef82a3fe28c301416d67c8e12c206bc98c0c44626c2735df53f8219ebdf1411312b19799effd6b1c6aebd603e4b9ce9012b6e4b49e66d82d
data/README.md CHANGED
@@ -1,8 +1,6 @@
1
1
  # SqlEnum
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/sql_enum`. To experiment with that code, run `bin/console` for an interactive prompt.
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
- TODO: Write usage instructions here
23
+ ### Migrations
26
24
 
27
- ## Development
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
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
38
+ Or add an enum column:
39
+ ```ruby
40
+ add_column :users, :status, :enum, limit: [:active, :pending, :inactive], default: :active
41
+ ```
30
42
 
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
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/fzf/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.
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/fzf/sql_enum/blob/master/CODE_OF_CONDUCT.md).
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[0][0]
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)
@@ -1,3 +1,3 @@
1
1
  module SqlEnum
2
- VERSION = "0.1.12"
2
+ VERSION = "0.1.13"
3
3
  end
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.12
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-02 00:00:00.000000000 Z
11
+ date: 2018-03-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord