eac_ruby_utils 0.61.0 → 0.62.0

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: 9a49138197a3fe16cb9a5e1f22326be1240a10f568c3ddc913e9c6f2a7501475
4
- data.tar.gz: e218f41a27514ca27c634619ae7eecc3fe4d7442ba546a9c24f584d437ecfe77
3
+ metadata.gz: c935490ddb854abc0f1aa8e473a020d6636aca5805a1312849cc3be308140798
4
+ data.tar.gz: '00932149f86866358f22288a3e4aa434d59b4164140ce76dda55b9f88d310bd1'
5
5
  SHA512:
6
- metadata.gz: f3000972a617e1f15500506c4e61909c50418dd9794c6516154962dd5f55b1173b612aa9d1bf0c23dbaee205ccc01abd93b1349f80147c53bc4f3640bb7739e6
7
- data.tar.gz: 9a021a5edb6bb22208d22cfc45fd17a486f9cd6c919a8a9495b2afe3b75a51b238172fd350f6977edd02669f7e77beab1ed7e53f7070bd36ebfa058dc52273a4
6
+ metadata.gz: fe63c4031d9240b8bc18dfa3b4ff39edac9465c1056971feadeb9338f8c2e4a59836fdafc5268c35dcc4158348c84c50da255b7b4e320554f56e73300b83e4e6
7
+ data.tar.gz: ecb86c9203690924b8263e5934f093bbf53e2218bf9b2019ccb188afc896e3ffcc21abd8565c1641bc1ab94936f909870f80413e232161092076b4163c53bab4
@@ -7,11 +7,19 @@ module EacRubyUtils
7
7
  class << self
8
8
  VARIABLE_NAME_PATTERN = /[_a-z][_a-z0-9]*/i.freeze
9
9
 
10
- def variableize(string)
10
+ # Convert a string to a variable format: first character as a lowercase letter or underscore
11
+ # and other as a lowercase letter, underscore or numbers.
12
+ # @param string [String] The source string.
13
+ # @param validate [Boolean] Affect the outcome when the result builded is not in a valid
14
+ # variable format. If `true`, it raises a {ArgumentError}. If `false`, return `nil`.
15
+ # @return [String, nil]
16
+ # @raise [ArgumentError]
17
+ def variableize(string, validate = true)
11
18
  r = ::ActiveSupport::Inflector.transliterate(string).gsub(/[^_a-z0-9]/i, '_')
12
19
  .gsub(/_+/, '_').gsub(/_\z/, '').gsub(/\A_/, '').downcase
13
20
  m = VARIABLE_NAME_PATTERN.match(r)
14
21
  return r if m
22
+ return nil unless validate
15
23
 
16
24
  raise ::ArgumentError, "Invalid variable name \"#{r}\" was generated " \
17
25
  "from string \"#{string}\""
@@ -54,8 +54,9 @@ module EacRubyUtils
54
54
  end
55
55
 
56
56
  def value_validate!(value, error_class = ::StandardError)
57
- value_valid?(value) ||
58
- raise(error_class, "Invalid value: \"#{value}\" (Valid: #{values_to_s})")
57
+ return value if value_valid?(value)
58
+
59
+ raise(error_class, "Invalid value: \"#{value}\" (Valid: #{values_to_s})")
59
60
  end
60
61
 
61
62
  def values_to_s
@@ -2,7 +2,9 @@
2
2
 
3
3
  module Kernel
4
4
  # Raise exception with text "Not yet implemented".
5
- def nyi
6
- raise "Not yet implemented (Called in #{caller.first})"
5
+ def nyi(message = nil)
6
+ s = "Not yet implemented (Called in #{caller.first})"
7
+ s += ": #{message}" if message
8
+ raise s
7
9
  end
8
10
  end
@@ -3,7 +3,9 @@
3
3
  require 'eac_ruby_utils/inflector'
4
4
 
5
5
  class String
6
- def variableize
7
- ::EacRubyUtils::Inflector.variableize(self)
6
+ # Shortcut to `EacRubyUtils::Inflector.variableize(self, ...)`.
7
+ # @see EacRubyUtils::Inflector.variableize
8
+ def variableize(validate = true)
9
+ ::EacRubyUtils::Inflector.variableize(self, validate)
8
10
  end
9
11
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacRubyUtils
4
- VERSION = '0.61.0'
4
+ VERSION = '0.62.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eac_ruby_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.61.0
4
+ version: 0.62.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Esquilo Azul Company
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-17 00:00:00.000000000 Z
11
+ date: 2021-03-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport