enumbler 0.6.3 → 0.6.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 29989e16025afc87b0db8fd70347b21978c683ab44c6ffa2d1f44a22c20fb166
4
- data.tar.gz: 807a16dd6e6ff6e8c95b3f5337acf2f1ea456d07378dc702b8f2672c0b862276
3
+ metadata.gz: 96cdeb24ac43db515f90d6cf857e497281066c7dad0f5c2cf93d3aada54265dc
4
+ data.tar.gz: 13247cd26aa94ad10fe7f739fc8c3690d6e3702c59d77caceb80242a9df722d3
5
5
  SHA512:
6
- metadata.gz: 2c8dbf495025d467ee30172289097169d84d23776320a1624d5e3920f2f66e738f606a15e61e2bbce696051c6d87ec99c811c45b3d9cdcb631f7e3bd1b961409
7
- data.tar.gz: 3a6d12fe63ff37e1274b5ec3ec31023aa08f520f455b44695746a5555a20bc063283fbd6afaf2f9831d740588bcf090426647f052c1bc87e98d829a071a9fc7d
6
+ metadata.gz: 57cf510621d28df43bca6d5e7715e6bd9c1452a7a7457a1fd6ef3ae0f47425927deec6bc16e34dd2ccb94781cdb37f358d62825c8c64aed0294ffcd247fd6a93
7
+ data.tar.gz: 007d1e7c93fcf129ec0b13d037edd045e4e18b9d453a6dadc2381425a73f9b64424a83e4d976b0bd316a593ccf3c5e9d3f986c1cbb2bed35f7a9cb1f4dfc94b5
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- enumbler (0.6.3)
4
+ enumbler (0.6.4)
5
5
  activerecord (>= 5.2.3, < 6.1)
6
6
  activesupport (>= 5.2.3, < 6.1)
7
7
 
@@ -58,12 +58,14 @@ module Enumbler
58
58
  # @param **attributes [Hash] optional: additional attributes and values that
59
59
  # will be saved to the database for this enumble record
60
60
  def enumble(enum, id, label: nil, **attributes)
61
+ raise_error_if_model_does_not_support_attributes(attributes)
62
+
63
+ id = validate_id_is_numeric(enum, id)
64
+
61
65
  @enumbles ||= Enumbler::Collection.new
62
66
  @enumbled_model = self
63
67
  @enumbler_label_column_name ||= :label
64
68
 
65
- raise_error_if_model_does_not_support_attributes(attributes)
66
-
67
69
  enumble = Enumble.new(enum, id, label: label, label_column_name: @enumbler_label_column_name, **attributes)
68
70
 
69
71
  if @enumbles.include?(enumble)
@@ -313,6 +315,15 @@ module Enumbler
313
315
  end
314
316
  end
315
317
 
318
+ # I accidentally forgot to provide an id one time and it was confusing as
319
+ # the last argument became the hash of options. This should help.
320
+ def validate_id_is_numeric(enum, id)
321
+ Integer(id)
322
+ rescue ArgumentError, TypeError
323
+ raise Enumbler::Error,
324
+ "You must provide a numeric primary key, like: `enumble :#{enum}, 1 `"
325
+ end
326
+
316
327
  def raise_error_if_model_does_not_support_attributes(attributes)
317
328
  return if attributes.blank?
318
329
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Enumbler
4
- VERSION = '0.6.3'
4
+ VERSION = '0.6.4'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: enumbler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.3
4
+ version: 0.6.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Damon Timm
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-07-06 00:00:00.000000000 Z
11
+ date: 2020-08-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord