array_enum 1.0.0 → 1.0.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
  SHA256:
3
- metadata.gz: d25d5a0511d3b6c7021f78de6061f7c58ee539fd83ad333c2d4d8df2a875837c
4
- data.tar.gz: a4f5db8fd703a3eb0da62bd3bb391aa8875acc9e57e333507fd0a9f9f5a547bf
3
+ metadata.gz: afc3f9133c5efe0de0320c4b83e650969ab9b647b29b242f2d44dfb58d2a726f
4
+ data.tar.gz: 9a9ee4607992a52138f6fea70e0eb329554b50e675b37f8e700305b04ff161b9
5
5
  SHA512:
6
- metadata.gz: 241bc38ae4922c19ca4c242e9970dc40d52e8cd3b7d27815604d5bfec07a1ffb82276dc7c31446393af542e119caabb039202c3880fb1c0a98265d1c61e1a909
7
- data.tar.gz: a4942e835080837b810f8830a536b1d3408bae747cb5e2315952bb3ea132064e021c50177dc614598032e5a81e0291c437b6afd605089bd49194208b4f9f1edf
6
+ metadata.gz: 3f96c19d50fac52b7bc2041d4983c9880807944226074132ce3c16b3a7ad99a1f00648f501d5535b8edaba1a932216ff0fb6196531dae7c9d09e3eb0bb06f6b9
7
+ data.tar.gz: 43e71fc9ba6e47fd70b4fadad42d6b901d03f5e92238201e6e157338212db3d710ffcbffbb10fa8be0cf5be444a4c584de6c09d2272d42ace912d32087224321
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- array_enum (1.0.0)
4
+ array_enum (1.0.1)
5
5
  activemodel
6
6
 
7
7
  GEM
@@ -20,10 +20,10 @@ GEM
20
20
  tzinfo (~> 1.1)
21
21
  arel (9.0.0)
22
22
  concurrent-ruby (1.1.4)
23
- i18n (1.4.0)
23
+ i18n (1.5.1)
24
24
  concurrent-ruby (~> 1.0)
25
25
  minitest (5.11.3)
26
- pg (1.1.3)
26
+ pg (1.1.4)
27
27
  rake (12.3.2)
28
28
  thread_safe (0.3.6)
29
29
  tzinfo (1.2.5)
@@ -1,3 +1,3 @@
1
1
  module ArrayEnum
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
data/lib/array_enum.rb CHANGED
@@ -3,12 +3,17 @@ require "array_enum/subset_validator"
3
3
  require "array_enum/railtie" if defined?(Rails)
4
4
 
5
5
  module ArrayEnum
6
+ MISSING_VALUE_MESSAGE = "%{value} is not a valid value for %{attr}".freeze
7
+ private_constant :MISSING_VALUE_MESSAGE
8
+
6
9
  def array_enum(definitions)
7
10
  definitions.each do |attr_name, mapping|
8
11
  attr_symbol = attr_name.to_sym
9
12
 
10
13
  define_singleton_method("with_#{attr_name}".to_sym) do |values|
11
- db_values = Array(values).map { |value| mapping.fetch(value.to_s) }
14
+ db_values = Array(values).map do |value|
15
+ mapping[value.to_s] || raise(ArgumentError, MISSING_VALUE_MESSAGE % {value: value, attr: attr_name})
16
+ end
12
17
  where("#{attr_name} @> ARRAY[:db_values]", db_values: db_values)
13
18
  end
14
19
 
@@ -17,7 +22,9 @@ module ArrayEnum
17
22
  end
18
23
 
19
24
  define_method("#{attr_name}=".to_sym) do |values|
20
- self[attr_symbol] = Array(values).map { |value| mapping.fetch(value.to_s) }.uniq
25
+ self[attr_symbol] = Array(values).map do |value|
26
+ mapping[value.to_s] || raise(ArgumentError, MISSING_VALUE_MESSAGE % {value: value, attr: attr_name})
27
+ end.uniq
21
28
  end
22
29
  end
23
30
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: array_enum
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wojciech Wnętrzak
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-01-02 00:00:00.000000000 Z
11
+ date: 2019-01-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel