symbolic_enum 1.1.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +5 -3
- data/lib/symbolic_enum.rb +4 -4
- data/lib/symbolic_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: 7279c54af613063bd4f8b4407970a0fd87080a7e
|
4
|
+
data.tar.gz: a9f1a26bad8480a37862405f8942e84f383141fd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 99f4a542fd2b5c931db7199abbb1d247185d867cef27927fc89fab422a780b9e77549e9259ef1de7561ec0f4d59bcc0a0228b6bfb5f169c970b191df8f69df6e
|
7
|
+
data.tar.gz: 2a38a00c17debd02f9df4068d0bd3644286a71dd1d1a44249a2bbcf6c0ae684d23c68167df0807f8a911173574ca3143e1df11909491f3c3e478d16ab0261a6c
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,10 @@
|
|
1
|
-
#
|
1
|
+
# symbolic_enum
|
2
2
|
|
3
|
-
|
3
|
+
`symbolic_enum` is an alternate implementation of [Rails enums](http://api.rubyonrails.org/classes/ActiveRecord/Enum.html), which changes the following:
|
4
4
|
|
5
|
-
|
5
|
+
* The getters return symbols instead of strings.
|
6
|
+
* Option to mark the field as an array. This assumes that the underlying database column is an integer array.
|
7
|
+
* Option to disable scopes and/or setters.
|
6
8
|
|
7
9
|
## Installation
|
8
10
|
|
data/lib/symbolic_enum.rb
CHANGED
@@ -59,13 +59,13 @@ module SymbolicEnum
|
|
59
59
|
|
60
60
|
if is_array
|
61
61
|
define_method("#{ field }=") do |value|
|
62
|
-
raise ArgumentError.new("can only assign a valid array of enums") unless value.nil? || value.is_a?(Array) && value.map(&:class).
|
63
|
-
self[field] = value.nil? ? nil : value.map{|s| mapping[s] }
|
62
|
+
raise ArgumentError.new("can only assign a valid array of enums") unless value.nil? || (value.is_a?(Array) && value.map(&:class).to_set.subset?([String, Symbol].to_set) && value.map(&:to_sym).to_set.subset?(mapping.keys.to_set))
|
63
|
+
self[field] = value.nil? ? nil : value.map{|s| mapping[s.to_sym] }
|
64
64
|
end
|
65
65
|
else
|
66
66
|
define_method("#{ field }=") do |value|
|
67
|
-
raise ArgumentError.new("can only assign a valid enum") unless value.nil? || mapping.keys.include?(value)
|
68
|
-
self[field] = mapping[value]
|
67
|
+
raise ArgumentError.new("can only assign a valid enum") unless value.nil? || ((value.is_a?(Symbol) || value.is_a?(String)) && mapping.keys.include?(value.to_sym))
|
68
|
+
self[field] = value.nil? ? nil : mapping[value.to_sym]
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: symbolic_enum
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ajith Hussain
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-12-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|