toolrack 0.12.0 → 0.16.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: b6017a232adad200e31c0e260e6c6a02b0a28024bdb966d105d3f5102b2e458a
4
- data.tar.gz: 9e5000fc3e174e3d25421e35c45ebff61b5c7c0c8439e6d1b800c2f220e69b2d
3
+ metadata.gz: dc4910a1f5cea30a6abb8a4327b82587249209a8cce6830aa9e1df7e2bdf32ff
4
+ data.tar.gz: 41d80a9716fff1a2dd1ff12ec4eb1e03496bbdc709c757a54f80c767c7c61eb7
5
5
  SHA512:
6
- metadata.gz: abd273b83b3d2b20f05875ac4e17c190fa19799d7fb0038974038eb00cc5dcae3aeae1bc91db2b0ee0950dbe523be44f77618113b2e0d79b3a630a39678fec6d
7
- data.tar.gz: 8e867b4b64cbc256bd6af290b1b987d1dbfd7ae92772665f6fbdb3ac58f96adeec9a0bdc756010ffe03a117ddda68d91224091ae03a8877c39f9c28926840fae
6
+ metadata.gz: 4bc935dac9779c3d705228b289fb4c3c114ca9b52c1bb7d6713c4950380b3158cc4c4c9b09b96c0c86e59dc476aa91a30b0e5503acd71fd66051f9198db5fc49
7
+ data.tar.gz: fee94264c22adc4bf922c6fbef169e816c83ae72433e8f90ae060e05c5f52715054b23ffbb79d1bd29959084cf17e8e4afc9ab63bb8e8031b2fd91472feae6b3
@@ -0,0 +1,28 @@
1
+
2
+
3
+ module Antrapol
4
+ module ToolRack
5
+ module CliUtils
6
+ include Antrapol::ToolRack::ConditionUtils
7
+
8
+ class CliUtilsError < StandardError; end
9
+
10
+ def which(app)
11
+ if not_empty?(app)
12
+ path = `which #{app}`
13
+ path.strip if not_empty?(path)
14
+ else
15
+ raise CliUtilsError, "Given appication to look for full path (which) is empty"
16
+ end
17
+ end
18
+
19
+
20
+ def self.included(klass)
21
+ klass.class_eval <<-END
22
+ extend Antrapol::ToolRack::CliUtils
23
+ END
24
+ end
25
+
26
+ end
27
+ end
28
+ end
@@ -48,6 +48,12 @@ module Antrapol
48
48
  end
49
49
  alias_method :is_str_bool?, :is_string_boolean?
50
50
 
51
+ def self.included(klass)
52
+ klass.class_eval <<-END
53
+ extend Antrapol::ToolRack::ConditionUtils
54
+ END
55
+ end
56
+
51
57
  end # ConditionUtils
52
58
  end # MyToolRack
53
59
  end # Antrapol
@@ -11,7 +11,7 @@ module Antrapol
11
11
  # val - variable/object that shall be tested for emptiness
12
12
  # message - message to be thrown if it is true
13
13
  # error - exception object to be thrown
14
- def raise_if_empty(val, message, error = Antrapol::ToolRack::Error)
14
+ def raise_if_empty(val, message, error = StandardError)
15
15
  raise_error(message,error) if is_empty?(val)
16
16
  end # raise_if_empty
17
17
  alias_method :raise_if_empty?, :raise_if_empty
@@ -19,7 +19,7 @@ module Antrapol
19
19
  #
20
20
  # raise_if_false
21
21
  #
22
- def raise_if_false(bool, message, error = Antrapol::ToolRack::Error)
22
+ def raise_if_false(bool, message, error = StandardError)
23
23
  if not bool
24
24
  raise_error(message,error)
25
25
  end
@@ -29,16 +29,16 @@ module Antrapol
29
29
  #
30
30
  # raise_if_true
31
31
  #
32
- def raise_if_true(bool, message, error = Antrapol::ToolRack::Error)
32
+ def raise_if_true(bool, message, error = StandardError)
33
33
  raise_if_false(!bool, message, error)
34
34
  end # raise_if_true
35
35
  alias_method :raise_if_true?, :raise_if_true
36
36
 
37
37
  protected
38
- def raise_error(message, error = Antrapol::ToolRack::Error)
38
+ def raise_error(message, error = StandardError)
39
39
  if error.nil?
40
40
  if @default_exception.nil?
41
- raise Antrapol::ToolRack::Error, message
41
+ raise StandardError, message
42
42
  else
43
43
  raise @default_exception, message
44
44
  end
@@ -0,0 +1,115 @@
1
+
2
+
3
+
4
+ module Antrapol
5
+ module ToolRack
6
+ module HashConfig
7
+ include ConditionUtils
8
+
9
+ class HashConfigError < StandardError; end
10
+
11
+ def hcdeli=(deli)
12
+ @hcdeli = deli
13
+ end
14
+ def hcdeli
15
+ if is_empty?(@hcdeli)
16
+ @hcdeli = "."
17
+ end
18
+ @hcdeli
19
+ end
20
+
21
+ def hcset(key, value)
22
+ raise HashConfigError, "Nil key is not supported" if is_empty?(key)
23
+
24
+ keys = transform_keys(key)
25
+ root = hcConf
26
+ keys.each do |k|
27
+ if root.is_a?(Hash)
28
+ if not root.keys.include?(k)
29
+ root[k] = { }
30
+ end
31
+
32
+ if k == keys[-1]
33
+ root[k] = value
34
+ else
35
+ root = root[k]
36
+ end
37
+
38
+ else
39
+ raise HashConfigError, "The key '#{k}' currently not tie to a hash. It is an #{root.class} object of value '#{root}'. There is no way to add another value to key '#{key}'. Try to change it to Hash object instead."
40
+ end
41
+ end
42
+ root
43
+ end
44
+
45
+ def hcget(key, defVal = nil)
46
+ if key.nil?
47
+ return nil
48
+ else
49
+ keys = transform_keys(key)
50
+ node = hcConf
51
+ keys.each do |k|
52
+ if node.keys.include?(k)
53
+ node = node[k]
54
+ else
55
+ node = nil
56
+ break
57
+ end
58
+ end
59
+ node.nil? ? defVal : node
60
+ end
61
+ end
62
+
63
+ def hcinclude?(key)
64
+ if key.nil?
65
+ return false
66
+ else
67
+ keys = transform_keys(key)
68
+ node = hcConf
69
+ keys.each do |k|
70
+ if node.is_a?(Hash)
71
+ if node.keys.include?(k)
72
+ node = node[k]
73
+ else
74
+ node = nil
75
+ break
76
+ end
77
+ else
78
+ node = nil
79
+ end
80
+ end
81
+ not node.nil?
82
+ end
83
+ end
84
+
85
+ private
86
+ def split_key(key)
87
+ if not_empty?(key)
88
+ key.split(hcdeli)
89
+ else
90
+ [key]
91
+ end
92
+ end
93
+
94
+ def transform_keys(key)
95
+ case key
96
+ when String
97
+ split_key(key)
98
+ when Array
99
+ key
100
+ else
101
+ [key]
102
+ end
103
+ end
104
+
105
+ def hcConf
106
+ if @hcConf.nil?
107
+ @hcConf = { }
108
+ end
109
+ @hcConf
110
+ end
111
+
112
+ end
113
+ end
114
+ end
115
+
@@ -0,0 +1,22 @@
1
+
2
+
3
+ module Antrapol
4
+ module ToolRack
5
+ class NullOutput
6
+
7
+ def method_missing(mtd, *args, &block)
8
+ # sink-holed all methods call
9
+ logger.tdebug :nullOut, "#{mtd} / #{args} / #{block ? "with block" : "no block"}"
10
+ end
11
+
12
+ private
13
+ def logger
14
+ if @logger.nil?
15
+ @logger = Tlogger.new
16
+ end
17
+ @logger
18
+ end
19
+
20
+ end
21
+ end
22
+ end
@@ -1,6 +1,6 @@
1
1
  module Antrapol
2
2
  module ToolRack
3
- VERSION = "0.12.0"
3
+ VERSION = "0.16.0"
4
4
  end
5
5
  end
6
6
 
@@ -0,0 +1,47 @@
1
+
2
+ require_relative 'condition_utils'
3
+
4
+ module Antrapol
5
+ module ToolRack
6
+ module VersionUtils
7
+ include Antrapol::ToolRack::ConditionUtils
8
+
9
+ class VersionUtilsError < StandardError; end
10
+
11
+ def is_version_equal?(*args)
12
+ res = true
13
+ target = Gem::Version.new(args.first)
14
+ args.each do |a|
15
+ subj = Gem::Version.new(a)
16
+ res = (subj == target)
17
+ break if not res
18
+ target = subj
19
+ end
20
+
21
+ res
22
+ end
23
+
24
+ def possible_versions(ver)
25
+ raise VersionUtilsError, "Given version to extrapolate is empty" if is_empty?(ver)
26
+ vv = ver.to_s.split('.')
27
+ tv = vv.clone
28
+ res = []
29
+ cnt = 0
30
+ (0...vv.length).each do |i|
31
+ tv = vv.clone
32
+ tv[i] = tv[i].to_i+1
33
+
34
+ j = i
35
+ loop do
36
+ break if j >= (vv.length-1)
37
+ j += 1
38
+ tv[j] = 0
39
+ end
40
+ res << tv.join(".")
41
+ end
42
+ res
43
+ end
44
+
45
+ end
46
+ end
47
+ end
data/lib/toolrack.rb CHANGED
@@ -12,7 +12,10 @@ require_relative 'toolrack/process_utils'
12
12
  require_relative 'toolrack/runtime_utils'
13
13
  require_relative 'toolrack/data_conversion_utils'
14
14
  require_relative 'toolrack/password_utils'
15
- require_relative 'toolrack/mixin_helper'
15
+ require_relative 'toolrack/hash_config'
16
+ require_relative 'toolrack/cli_utils'
17
+ require_relative 'toolrack/null_output'
18
+ require_relative 'toolrack/version_utils'
16
19
 
17
20
  module Antrapol
18
21
  module ToolRack
@@ -26,6 +29,7 @@ module TR
26
29
  Antrapol::ToolRack
27
30
  end
28
31
 
32
+ # aliases
29
33
  ToolRack = Antrapol::ToolRack
30
34
  #TR = ToolRack
31
35
 
@@ -35,6 +39,8 @@ TR::DataConvUtils = ToolRack::DataConvUtils
35
39
  ToolRack::CondUtils = ToolRack::ConditionUtils
36
40
  TR::CondUtils = ToolRack::ConditionUtils
37
41
 
42
+ TR::ProcessUtils = ToolRack::ProcessUtils
43
+
38
44
  ToolRack::PassUtils = ToolRack::PasswordUtils
39
45
  TR::PassUtils = ToolRack::PasswordUtils
40
46
 
@@ -44,5 +50,12 @@ TR::ExpUtils = ToolRack::ExpUtils
44
50
  ToolRack::RTUtils = ToolRack::RuntimeUtils
45
51
  TR::RTUtils = ToolRack::RTUtils
46
52
 
47
- TR::MixinHelper = ToolRack::MixinHelper
53
+ TR::HashConfig = ToolRack::HashConfig
54
+
55
+ TR::CliUtils = ToolRack::CliUtils
56
+
57
+ TR::NullOut = ToolRack::NullOutput
58
+
59
+ TR::VerUtils = ToolRack::VersionUtils
60
+ TR::VUtils = TR::VerUtils
48
61
 
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.12.0
4
+ version: 0.16.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-23 00:00:00.000000000 Z
11
+ date: 2021-10-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tlogger
@@ -83,16 +83,19 @@ files:
83
83
  - bin/console
84
84
  - bin/setup
85
85
  - lib/toolrack.rb
86
+ - lib/toolrack/cli_utils.rb
86
87
  - lib/toolrack/condition_utils.rb
87
88
  - lib/toolrack/data_conversion_utils.rb
88
89
  - lib/toolrack/exception_utils.rb
89
90
  - lib/toolrack/global.rb
90
- - lib/toolrack/mixin_helper.rb
91
+ - lib/toolrack/hash_config.rb
92
+ - lib/toolrack/null_output.rb
91
93
  - lib/toolrack/password_utils.rb
92
94
  - lib/toolrack/process_utils.rb
93
95
  - lib/toolrack/runtime_utils.rb
94
96
  - lib/toolrack/utils.rb
95
97
  - lib/toolrack/version.rb
98
+ - lib/toolrack/version_utils.rb
96
99
  - process_test/backtick_test.rb
97
100
  - process_test/pty_test.rb
98
101
  - process_test/shell_test.rb
@@ -103,7 +106,7 @@ licenses: []
103
106
  metadata:
104
107
  homepage_uri: https://github.com/chrisliaw/toolrack
105
108
  source_code_uri: https://github.com/chrisliaw/toolrack
106
- post_install_message:
109
+ post_install_message:
107
110
  rdoc_options: []
108
111
  require_paths:
109
112
  - lib
@@ -119,7 +122,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
119
122
  version: '0'
120
123
  requirements: []
121
124
  rubygems_version: 3.2.22
122
- signing_key:
125
+ signing_key:
123
126
  specification_version: 4
124
127
  summary: Collection of simple utilities but I find it increase clarity
125
128
  test_files: []
@@ -1,27 +0,0 @@
1
-
2
-
3
- module Antrapol
4
- module ToolRack
5
- module MixinHelper
6
-
7
- module ClassMethods
8
- def mixin(cls)
9
- self.class_eval "include #{cls}"
10
- end
11
-
12
- def class_method(&block)
13
- class_eval <<-END
14
- module ClassMethods
15
- end
16
- END
17
- ClassMethods.class_eval(&block)
18
- end
19
- end # module ClassMethods
20
-
21
- def self.included(klass)
22
- klass.extend(ClassMethods)
23
- end
24
-
25
- end
26
- end
27
- end