enummer 1.0.0 → 1.0.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: adf5116258e6b0e0e5e3b4fc962f97228c26369c41c200a8af07dccd67f8d48e
4
- data.tar.gz: ea4399838cf8e5cf8be9b23629b88af16c5355f0684d645a7f27db1d94fa642d
3
+ metadata.gz: da7e1c544817a7e7b874a4ca20372880f20d7cafe6cc5bb663e2224cd99d7ff2
4
+ data.tar.gz: 3d18b5a7b106387dc8e76631f0b84204a7d11520f5dbb36b70bd8aa403b9569c
5
5
  SHA512:
6
- metadata.gz: 328f419c099db1f1845c9e851fc7f85d7e26728d20ac2d400161ca8f0ba27738e835361499bb3e34f78b4be06b940cc1126d952d48a59cb9d287c6cd2d5cc9af
7
- data.tar.gz: e119a0af64fa3318df0cfe09ff927c6e15780f592c13163565a6ce33cce7e61246a0395e97c86e7323de1829411efb5e25714959e6da98dbfcffe37824a1a6fd
6
+ metadata.gz: d16b48b263ca8ecf943e301993283ce356e3cf12961bd66839ce5a2400a3069197beeb4c75d24b2f7565a7c31fb1fe741e3a8c9a65f72d2b3d08549bf5ee3966
7
+ data.tar.gz: 2b4d0c8c13b4133299c16e29034233c98fd1446c477f48bdc1acc6fc62db687da4ed8df47db6354475fab593043bf9e8ce0f11ca9bbc4e41796d62d678d69ab4
data/README.md CHANGED
@@ -1,11 +1,13 @@
1
1
  # Enummer
2
2
 
3
- [![Gem](https://img.shields.io/gem/v/enummer?color=green)](https://rubygems.org/gems/enummer)
3
+ [![Gem](https://img.shields.io/gem/v/enummer?color=%2330336b)](https://rubygems.org/gems/enummer)
4
4
  [![Codecov](https://img.shields.io/codecov/c/github/shkm/enummer/main)](https://app.codecov.io/gh/shkm/enummer)
5
- [![Licence](https://img.shields.io/github/license/shkm/enummer)](https://github.com/shkm/enummer/blob/main/MIT-LICENSE)
6
- [![Documentation](https://img.shields.io/badge/yard-docs-informational)](https://www.rubydoc.info/github/shkm/enummer/main)
5
+ [![Licence](https://img.shields.io/github/license/shkm/enummer?color=%2395afc0)](https://github.com/shkm/enummer/blob/main/MIT-LICENSE)
6
+ [![Documentation](https://img.shields.io/badge/yard-docs-%23686de0)](https://www.rubydoc.info/github/shkm/enummer/main)
7
7
 
8
- Enummer is a lightweight answer for adding enums with multiple values to Rails, with a similar syntax to Rails' built-in `enum`. At the moment it officially supports only PostgreSQL and recent Rails versions, though YMMV on another DBMS.
8
+ Enummer is a lightweight answer for adding enums with multiple values to Rails, with a similar syntax to Rails' built-in `enum`.
9
+
10
+ Enummer officially supports Ruby versions 2.7, 3.0 and 3.1 with SQLite, PostgreSQL, and MariaDB.
9
11
 
10
12
  ## Installation
11
13
  Add `gem "enummer"` to your Gemfile and `bundle`.
@@ -44,6 +46,21 @@ User.execute
44
46
  User.not_execute
45
47
  ```
46
48
 
49
+ Additionally, a `with_<name>` scope will be generated which returns all records that match all given options. E.g.:
50
+
51
+ ```ruby
52
+ user1 = User.create!(permissions: %i[read write execute])
53
+ user2 = User.create!(permissions: %i[read write])
54
+ user3 = User.create!(permissions: %i[read])
55
+
56
+ # .where(permissions: ...) will generate an `IN` query, returning all records that have *any*
57
+ # of those permissions.
58
+ User.where(permissions: %i[read write]) # => [user1, user2, user3]
59
+
60
+ # .with_permissions will return only users that have at least all of the given set of permissions
61
+ User.with_permissions(%i[read write]) # => [user1, user2]
62
+ ```
63
+
47
64
  ### Getter methods
48
65
 
49
66
  Simply calling the instance method for the column will return an array of options. Question mark methods are also provided.
@@ -85,6 +102,17 @@ lol stop
85
102
  ## Contributing
86
103
  Make an issue / PR and we'll see.
87
104
 
105
+ ### Development
106
+
107
+ ```bash
108
+ $ cd enummer
109
+ $ bundle install
110
+ $ cd test/dummy
111
+ $ RAILS_ENV=test DATABASE_URL=sqlite3:dummy_test rails db:setup
112
+ $ cd ../..
113
+ $ RAILS_ENV=test DATABASE_URL=sqlite3:dummy_test bin/test
114
+ ```
115
+
88
116
  ## Alternatives
89
117
  - [flag_shih_tzu](https://github.com/pboling/flag_shih_tzu)
90
118
  - Lots of booleans
@@ -22,13 +22,14 @@ module Enummer
22
22
  def serialize(value)
23
23
  return unless value
24
24
 
25
- Array.wrap(value).sum { |value_name| @bit_pairs.fetch(value_name, 0) }
25
+ Array.wrap(value).sum { |value_name| @bit_pairs.fetch(value_name.to_sym, 0) }
26
26
  end
27
27
 
28
28
  # @param [Numeric] value Numeric representation of values
29
29
  # @return [Array<Symbol>] Current value represented as symbols
30
30
  def deserialize(value)
31
31
  return [] unless value
32
+ return [] if value.to_i.zero?
32
33
 
33
34
  @bit_pairs.each_with_object([]) do |(pair_name, pair_value), value_names|
34
35
  next if (value & pair_value).zero?
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Enummer
4
- VERSION = "1.0.0"
4
+ VERSION = "1.0.3"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: enummer
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jamie Schembri
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-02-04 00:00:00.000000000 Z
11
+ date: 2022-03-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails