eac_ruby_utils 0.61.0 → 0.62.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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c935490ddb854abc0f1aa8e473a020d6636aca5805a1312849cc3be308140798
|
4
|
+
data.tar.gz: '00932149f86866358f22288a3e4aa434d59b4164140ce76dda55b9f88d310bd1'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
7
|
-
|
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
|
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.
|
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-
|
11
|
+
date: 2021-03-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|