symbolic_enum 1.1.0 → 1.1.1

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: 25b1c38a06b81fb3d48c8dccd8c7d2b0f524b766
4
- data.tar.gz: 9f3ea5c4e31246049191a749f935b32057a6f32c
3
+ metadata.gz: 7279c54af613063bd4f8b4407970a0fd87080a7e
4
+ data.tar.gz: a9f1a26bad8480a37862405f8942e84f383141fd
5
5
  SHA512:
6
- metadata.gz: 8b34f8fa175c5b49ddc1e0d6e4a7d2b884bf22e919e32269cd5182e2d3f47eb027fa6126f046366279c7e87ccccbef5f690eea31d23f6241defc38fcab8b4a4d
7
- data.tar.gz: 90b012ae6e20eebcd93a4d9836be4eca1c35e3112fe63d120911efc99a558851b382f0a692b9fddd8a87b2715718c15da1d82b6de5c57fffd505a249f7e01820
6
+ metadata.gz: 99f4a542fd2b5c931db7199abbb1d247185d867cef27927fc89fab422a780b9e77549e9259ef1de7561ec0f4d59bcc0a0228b6bfb5f169c970b191df8f69df6e
7
+ data.tar.gz: 2a38a00c17debd02f9df4068d0bd3644286a71dd1d1a44249a2bbcf6c0ae684d23c68167df0807f8a911173574ca3143e1df11909491f3c3e478d16ab0261a6c
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- symbolic_enum (1.0.1)
4
+ symbolic_enum (1.1.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -1,8 +1,10 @@
1
- # SymbolicEnum
1
+ # symbolic_enum
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/symbolic_enum`. To experiment with that code, run `bin/console` for an interactive prompt.
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
- TODO: Delete this and the text above, and describe your gem
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).uniq == [Symbol] && value.to_set.subset?(mapping.keys.to_set)
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
 
@@ -1,3 +1,3 @@
1
1
  module SymbolicEnum
2
- VERSION = "1.1.0"
2
+ VERSION = "1.1.1"
3
3
  end
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.0
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-23 00:00:00.000000000 Z
11
+ date: 2017-12-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler