spark_components 1.3.2 → 1.4.0

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: a1c1b5a00060124a21b830e051e3671599e9b6e76454946074dcd8bad037b0ad
4
- data.tar.gz: e46556296c8b22e4d8b65a9a29f14ab8505392553d8dcf640aa576cd6a29312d
3
+ metadata.gz: 704f5cb250fa2871cd46c09bba22444ccff15f0a65628ba9d1f775074c834c9d
4
+ data.tar.gz: 4f02e1ceafb246bfb47c9e71b5b85d5071135c2a42755aee1b242fce8ff6ee32
5
5
  SHA512:
6
- metadata.gz: 4361c1d798e4fbfaba12bbbbe78ea9eb9c1f28b5d86aa3844fa358818da67613ca7abfaaab4ba772475c6bc9fd4f14415d9cac1517ff2c0eb86de56513c95d4b
7
- data.tar.gz: d039b381910e4b7246765c7fcfbb684f6e1cf1abcd6ec4fd95aa429425205a33eba696883cbe534199bc65d36f50c3cff4d8a2599ee04b007fa649f0b781af47
6
+ metadata.gz: 3fb2ec83c0d223310322b5fb65dbe243338ee2010f9270960aaeb448c37927bcdae7b19369b14f7a4edbd9de79026ca424664587d6d782f7b5a36ab4d8baaa23
7
+ data.tar.gz: 346da75ed6aeaceefac656133870c4834149be7a7d048ed90e9a507b2da12ea24e50337f5189b0d457df9f1c760830ffd5b7fa543d7dcfeb5dd36350932972ec
@@ -66,13 +66,21 @@ module SparkComponents
66
66
  @tag_attrs ||= SparkComponents::Attributes::Tag.new
67
67
  end
68
68
 
69
- def self.validates_choice(name, choices)
70
- validates(name,
71
- inclusion: {
72
- presence: true,
73
- in: choices,
74
- message: "\"%{value}\" is not a valid option. Options include: #{choices.join(', ')}"
75
- })
69
+ def self.validates_choice(name, choices, required: true)
70
+ choices = [choices] unless choices.is_a?(Array)
71
+ supported_choices = choices.map { |c| c.is_a?(String) ? c.to_sym : c.to_s }.concat(choices)
72
+
73
+ unless required
74
+ # Allow nil if option is not required
75
+ supported_choices.unshift(nil)
76
+ # Add `nil` to the error messsages list of valid options
77
+ choices.push("nil")
78
+ end
79
+
80
+ choices = choices.to_sentence(last_word_connector: ", or ")
81
+ message = "\"%<value>s\" is not valid. Options for #{name} include: #{choices}"
82
+
83
+ validates(name, inclusion: { in: supported_choices, message: message })
76
84
  end
77
85
 
78
86
  # rubocop:disable Metrics/AbcSize
@@ -8,8 +8,8 @@ module SparkComponents
8
8
  app.config.assets.paths << SparkComponents.components_path if app.config.respond_to?(:assets)
9
9
  end
10
10
 
11
- initializer 'components.autoload', :before => :set_autoload_paths do |app|
12
- app.config.autoload_paths << File.join(app.root, 'app/components')
11
+ initializer "components.autoload", before: :set_autoload_paths do |app|
12
+ app.config.autoload_paths << File.join(app.root, "app/components")
13
13
  end
14
14
 
15
15
  initializer "components.view_helpers" do
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SparkComponents
4
- VERSION = "1.3.2"
4
+ VERSION = "1.4.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spark_components
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.2
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandon Mathis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-09-04 00:00:00.000000000 Z
11
+ date: 2019-09-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails