enummer 1.0.0 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +32 -4
- data/lib/enummer/enummer_type.rb +2 -1
- data/lib/enummer/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: da7e1c544817a7e7b874a4ca20372880f20d7cafe6cc5bb663e2224cd99d7ff2
|
4
|
+
data.tar.gz: 3d18b5a7b106387dc8e76631f0b84204a7d11520f5dbb36b70bd8aa403b9569c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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
|
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`.
|
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
|
data/lib/enummer/enummer_type.rb
CHANGED
@@ -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?
|
data/lib/enummer/version.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2022-03-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|