toolrack 0.9.1 → 0.11.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: 571e36485e6a124ee83052bd40d53b1612973e3f7636bf8432ae5d4d4f641f35
4
- data.tar.gz: 7042d576dec084cc3eccbbb49e74c2ff8e7175d4e69c3ddb2fe9027b7a65d0cd
3
+ metadata.gz: fc054121dfe0f58514fbb1144367c1de27e117feda1d888efd1aaa3063d6dea5
4
+ data.tar.gz: c8cda5ca33e463fb6aeae51e9e41e13cdd8aaf13b61c650bcd503d91739ae0dc
5
5
  SHA512:
6
- metadata.gz: 32a5ebec97858317a3a500db4e2bd315a80e67bee888b302fc45ff0aacd46749b77c25b9485d3faf6588fe0efbb1a72041a731366809dd8471fe73c1aa16437e
7
- data.tar.gz: e76ec4875a11dbf84634e527a665492ec9665f55747ba6aaf5007b28cb92bd1ba682072c3186b218b87a8954f4623d64908ce0b4a406573b521fb62f36128b25
6
+ metadata.gz: 9c410161466247551ac55f1b27e86b03e9a3416940158afc0fc59e3e7fbead8b0e6d0524f36aa9d2b5cc0a24b60a537b45642c438c488cd7f5f04ec719d38fe0
7
+ data.tar.gz: 0d7acf5ed32ef580fa73833ccb05f6de4c0b691544a8596e019126058344608222c7eb9bf9df7a89b4ce3fc720ab62d3e803e3423c50e603074e20ceca823725
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Toolrack
2
2
 
3
- Toolrack just the collection of utilities that helps in my code clarity
3
+ Toolrack just the collection of utilities that helps in my code clarity and assistance since those utils too small to be a gem on its own.
4
4
 
5
5
  ## Installation
6
6
 
@@ -40,10 +40,21 @@ class EditController
40
40
  # enable instance method to access those uitilities
41
41
  include ToolRack::ConditionUtils
42
42
  include ToolRack::ExceptionUtils
43
+ include ToolRack::PasswordUtils
44
+ include ToolRack::RuntimeUtils
45
+ include ToolRack::DataConversionUtils
46
+
47
+ # there is also shortcut since I write it so often
48
+ include TR::CondUtils
49
+ include TR::ExpUtils
50
+ include TR::PassUtils
51
+ include TR::RTUtils
52
+ include TR::DataConvUtils
43
53
  end
44
54
  ```
45
55
 
46
- Currently it has 3 modules:
56
+ Currently it has 5 modules:
57
+
47
58
  * Condition Utilities
48
59
  * is\_empty?(obj) - I found that I've type the condition if not (x.nil? and x.empty?) too frequent that I think this is very best to turn this into a function. The empty test shall take the following test in sequence:
49
60
  * First test is x.nil?. If it is return true
@@ -77,6 +88,45 @@ Currently it has 3 modules:
77
88
  * raise\_if\_false(obj, message, error) - As the name implied
78
89
  * raise\_if\_true(obj, message, error) - As the name implied
79
90
 
80
-
81
-
91
+ * Runtime utils - Tired rewriting this in other project. Detect if the running system is on which operating system / runtime. The function is pretty self descriptive
92
+ * RuntimeUtils.on\_windows?
93
+ * RuntimeUtils.on\_mac?
94
+ * RuntimeUtils.on\_linux?
95
+ * RuntimeUtils.on\_ruby?
96
+ * RuntimeUtils.on\_jruby?
97
+
98
+ * Password utils - Generate random password with designated complexity
99
+ * generate\_random\_password(length, options = { complexity: \<value\>, enforce\_quality: \<true/false\> })
100
+ * length - length of the required generated password
101
+ * options[:complexity]:
102
+ * 1 - lowercase alphabet
103
+ * 2 - lower + upper case alphabet [alpha]
104
+ * 3 - lower + upper + number [alpha numeric]
105
+ * 4 - lower + upper + number + symbol
106
+ * options[:enforce\_quality]
107
+ * true - generated password is guaranteed to contain the required complexity. E.g. if complexity 4 is required, the password MUST contain lower, upper, number and symbol as its output or a new password that comply to the complexity shall be regenerated. This process is repeated until the required complexity is achieved
108
+ * false - The rules of the complexity is relexed. E.g. if complexity 4 is requested, the output might not have symbol in it.
109
+ * gen\_rand\_pass(length, options = { }) & gen\_pass(length, options = { })
110
+ * Alias for method generate\_random\_password
111
+
112
+ * all\_lowercase\_alpha?(str)
113
+ * all\_uppercase\_alpha?(str)
114
+ * all\_alpha?(str)
115
+ * all\_number?(str)
116
+ * all\_symbol?(str)
117
+ * all\_alpha\_numeric?(str)
118
+ * all\_alpha\_numeric\_and\_symbol?(str)
119
+ * All methods above starts with all_\* is to check for strict compliance to the required output. E.g. if all\_alpha?(str) is used, the input str MUST be all alpha to get a true status
120
+
121
+ * has\_lowercase\_alpha?(str)
122
+ * has\_uppercase\_alpha?(str)
123
+ * has\_alpha?(str)
124
+ * has\_number?(str)
125
+ * has\_symbol?(str)
126
+ * has\_alpha\_numeric?(str)
127
+ * has\_alpha\_numeric\_or\_symbol?(str)
128
+ * All methods above start with has_\* is just to check if the given str contains the required specification. E.g string 'abcdE' will still get true status if pass to has\_lowercase\_alpha?(str). But value 1234 or '1234' or '$%^&' pass to has\_lowercase\_alpha?(str) shall return false.
129
+
130
+
131
+ Check out the rspec folder for usage
82
132
 
@@ -1,18 +1,3 @@
1
- # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
2
- # Version 2, December 2004
3
- #
4
- # Copyright (C) 2021 Chris Liaw <chrisliaw@antrapol.com>
5
- # Author: Chris Liaw <chrisliaw@antrapol.com>
6
- #
7
- # Everyone is permitted to copy and distribute verbatim or modified
8
- # copies of this license document, and changing it is allowed as long
9
- # as the name is changed.
10
- #
11
- # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
12
- # TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
13
- #
14
- # 0. You just DO WHAT THE FUCK YOU WANT TO.
15
-
16
1
 
17
2
  require 'securerandom'
18
3
 
@@ -20,6 +5,8 @@ module Antrapol
20
5
  module ToolRack
21
6
  module PasswordUtils
22
7
  include Antrapol::ToolRack::ConditionUtils
8
+
9
+ class PasswordUtilsError < StandardError; end
23
10
 
24
11
  # complexity
25
12
  # 1 : lowercase alphabet
@@ -27,7 +14,8 @@ module Antrapol
27
14
  # 3 : lower + upper + number
28
15
  # 4 : lower + upper + number + symbol
29
16
  def generate_random_password(length = 12, opts = { complexity: 4, enforce_quality: true })
30
-
17
+
18
+
31
19
  length = 12 if is_empty?(length)
32
20
  length = length.to_i
33
21
  length = 12 if length <= 0
@@ -36,6 +24,9 @@ module Antrapol
36
24
 
37
25
  if not_empty?(opts)
38
26
  complexity = opts[:complexity] || 4
27
+
28
+ raise PasswordUtilsError, "Password length too short but complexity too high. Not able generate the password with required complexity." if length <= complexity
29
+
39
30
  enforce_quality = opts[:enforce_quality] || true
40
31
  end
41
32
 
@@ -125,7 +116,7 @@ module Antrapol
125
116
  s = str.split("")
126
117
  lalpha = ('a'..'z').to_a
127
118
 
128
- (s.difference(lalpha).length == 0)
119
+ (s-lalpha).length == 0
129
120
  end
130
121
 
131
122
  def has_lowercase_alpha?(str)
@@ -143,7 +134,7 @@ module Antrapol
143
134
  s = str.split("")
144
135
  ualpha = ('A'..'Z').to_a
145
136
 
146
- s.difference(ualpha).length == 0
137
+ (s-ualpha).length == 0
147
138
  end
148
139
 
149
140
  def has_uppercase_alpha?(str)
@@ -166,8 +157,8 @@ module Antrapol
166
157
 
167
158
  alpha = [lalpha, ualpha].flatten
168
159
 
169
- t1 = (alpha.difference(s).length == 0)
170
- t2 = (alpha.difference(s).length == 0)
160
+ t1 = (alpha-s).length == 0
161
+ t2 = (alpha-s).length == 0
171
162
 
172
163
  t3 = (s & num).length > 0
173
164
  t4 = (s & sym).length > 0
@@ -206,7 +197,7 @@ module Antrapol
206
197
  s = str.split("")
207
198
  num = ('0'..'9').to_a
208
199
 
209
- !(s.difference(num).length > 0)
200
+ !((s-num).length > 0)
210
201
 
211
202
  end
212
203
 
@@ -215,7 +206,7 @@ module Antrapol
215
206
 
216
207
  s = str.split("")
217
208
  sym = ('!'..'?').to_a
218
- !(s.difference(sym).length > 0)
209
+ !((s-sym).length > 0)
219
210
 
220
211
  end
221
212
 
@@ -238,7 +229,7 @@ module Antrapol
238
229
  ualpha = ('A'..'Z').to_a
239
230
  num = ('0'..'9').to_a
240
231
  sym = ('!'..'?').to_a
241
- sym = sym.difference(num)
232
+ sym = sym-num
242
233
 
243
234
  t1 = ((s & lalpha).length > 0)
244
235
  t2 = ((s & ualpha).length > 0)
@@ -270,7 +261,7 @@ module Antrapol
270
261
  ualpha = ('A'..'Z').to_a
271
262
  num = ('0'..'9').to_a
272
263
  sym = ('!'..'?').to_a
273
- sym = sym.difference(num)
264
+ sym = sym-num
274
265
 
275
266
  t1 = ((s & lalpha).length > 0)
276
267
  t2 = ((s & ualpha).length > 0)
@@ -288,7 +279,7 @@ module Antrapol
288
279
  ualpha = ('A'..'Z').to_a
289
280
  num = ('0'..'9').to_a
290
281
  sym = ('!'..'?').to_a
291
- sym = sym.difference(num)
282
+ sym = sym-num
292
283
 
293
284
  t1 = ((s & lalpha).length > 0)
294
285
  t2 = ((s & ualpha).length > 0)
@@ -1,6 +1,6 @@
1
1
  module Antrapol
2
2
  module ToolRack
3
- VERSION = "0.9.1"
3
+ VERSION = "0.11.0"
4
4
  end
5
5
  end
6
6
 
data/lib/toolrack.rb CHANGED
@@ -17,13 +17,30 @@ module Antrapol
17
17
  module ToolRack
18
18
  class Error < StandardError; end
19
19
  # Your code goes here...
20
-
21
20
  end
22
21
  end
23
22
 
23
+ # try to get rid of constant redefined warning
24
+ module TR
25
+ Antrapol::ToolRack
26
+ end
27
+
24
28
  ToolRack = Antrapol::ToolRack
25
- ToolRack::DataConv = Antrapol::ToolRack::DataConversionUtils
29
+ #TR = ToolRack
30
+
31
+ ToolRack::DataConvUtils = Antrapol::ToolRack::DataConversionUtils
32
+ TR::DataConvUtils = ToolRack::DataConvUtils
33
+
26
34
  ToolRack::CondUtils = ToolRack::ConditionUtils
35
+ TR::CondUtils = ToolRack::ConditionUtils
36
+
27
37
  ToolRack::PassUtils = ToolRack::PasswordUtils
38
+ TR::PassUtils = ToolRack::PasswordUtils
39
+
40
+ ToolRack::ExpUtils = ToolRack::ExceptionUtils
41
+ TR::ExpUtils = ToolRack::ExpUtils
42
+
43
+ ToolRack::RTUtils = ToolRack::RuntimeUtils
44
+ TR::RTUtils = ToolRack::RTUtils
28
45
 
29
46
 
data/toolrack.gemspec CHANGED
@@ -30,4 +30,5 @@ Gem::Specification.new do |spec|
30
30
  spec.add_dependency "base58"
31
31
 
32
32
  spec.add_development_dependency "devops_helper", "~> 0.1.0"
33
+ spec.add_development_dependency "rspec"
33
34
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: toolrack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.1
4
+ version: 0.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-09-09 00:00:00.000000000 Z
11
+ date: 2021-09-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tlogger
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: 0.1.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  description: Just collections of utilities
56
70
  email:
57
71
  - chrisliaw@antrapol.com
@@ -88,7 +102,7 @@ licenses: []
88
102
  metadata:
89
103
  homepage_uri: https://github.com/chrisliaw/toolrack
90
104
  source_code_uri: https://github.com/chrisliaw/toolrack
91
- post_install_message:
105
+ post_install_message:
92
106
  rdoc_options: []
93
107
  require_paths:
94
108
  - lib
@@ -103,8 +117,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
103
117
  - !ruby/object:Gem::Version
104
118
  version: '0'
105
119
  requirements: []
106
- rubygems_version: 3.2.22
107
- signing_key:
120
+ rubygems_version: 3.0.9
121
+ signing_key:
108
122
  specification_version: 4
109
123
  summary: Collection of simple utilities but I find it increase clarity
110
124
  test_files: []