safe-hash-enum 0.4.4 → 0.4.5
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 +4 -4
- data/README.md +10 -3
- data/lib/enum/base.rb +1 -1
- data/lib/enum/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f3d0a446cc2c0ed1557281434982bb76b03705b164e37d36192579c77ad0ebfa
|
|
4
|
+
data.tar.gz: d2244782d1f0d6a5a572758e378acd2647a736f4744262f00fe5e07206ff24c8
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9490216122e2b2c8e2fde9d294795e226ba7ffa2238b547372f2a5351897183d064da1cc8fdb13b77258fb1b2092d9e82ccf2df5d6144eb853da27eceb97bc06
|
|
7
|
+
data.tar.gz: 5cc9dd5e1a628dcbed7c1a6e07271c864668a2cac672ddc265d2bc1511d4568ad3bf1bc232d5866e005cab6ab4b02783eb3120ca96b161209865a091b148c6be
|
data/README.md
CHANGED
|
@@ -27,15 +27,22 @@ class Side < Enum::Base
|
|
|
27
27
|
end
|
|
28
28
|
```
|
|
29
29
|
|
|
30
|
-
Now get a safely defined
|
|
30
|
+
Now get a safely defined key with the `enum` method with its `Symbol` or `String` type as argument. If there is no such key, `Enum::TokenNotFoundError` exception will be raised. And this is the **safety** - you will be noticed about the problem and fix it by introducing a new hash or fixing the source of the invalid hash. While others implementations of enums in Ruby (that I know) just silently ignore invalid values returning `nil` this one will raise the exception **always**. Example of usage:
|
|
31
31
|
|
|
32
32
|
```ruby
|
|
33
|
-
Side.enum(:left) # =>
|
|
34
|
-
Side.enum('left') # =>
|
|
33
|
+
Side.enum(:left) # => :left
|
|
34
|
+
Side.enum('left') # => :left
|
|
35
35
|
Side.enum(:invalid) # => Enum::TokenNotFoundError: token 'invalid'' not found in Side
|
|
36
36
|
Side.enum('invalid') # => Enum::TokenNotFoundError: token 'invalid'' not found in Side
|
|
37
37
|
```
|
|
38
38
|
|
|
39
|
+
To get the real enum, the hash representing the enum, use `real_enum` method :
|
|
40
|
+
|
|
41
|
+
```ruby
|
|
42
|
+
Side.real_enum(:left) # => {:left => "my_left"}
|
|
43
|
+
Side.real_enum('left') # => {:left => "my_left"}
|
|
44
|
+
```
|
|
45
|
+
|
|
39
46
|
Get value of hash by token (String or Symbol):
|
|
40
47
|
|
|
41
48
|
```ruby
|
data/lib/enum/base.rb
CHANGED
data/lib/enum/version.rb
CHANGED