toolrack 0.4.0 → 0.4.1

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: 1a314f6fdcefecc70740c69187204bcdcf16924ee2bf13845831a0f67cf5c357
4
- data.tar.gz: 3127b384041d20294eccc27335f0996825232d69dc3c6ac0c0d6035d0feab9e9
3
+ metadata.gz: 3b1faebd0b9013273d3b9943462bcd01efacde8a688e2fe94743628b3d8c249e
4
+ data.tar.gz: af51abbaf1376b8cf2fadd1df32b6395609ecc237554803c562a661e365e9eb1
5
5
  SHA512:
6
- metadata.gz: 48ce83ab6d84b1aea27f6743d4330f6849bd09da2316f695250ebdab376bc29722cbdc5667ee13e4a7dbe22aa0f95685d4bff959274b7f03339019c50479038f
7
- data.tar.gz: 1be997f86cd433d3a9d02c5ffe2bc5dae517bb3d9ac62fe1e91787ed7a07dc75e2deb6b05d94af0c411a05644fb235859c89434f9791a2f41e65cce1bb353566
6
+ metadata.gz: 4374ec558bed30fff9ee2578169fa832f28668dc43ebeaab5ce3f651f97b6bb8870ba4f2cfb3cf6500ad49e7dc3a64ace2904fad23399e509e13a19b1c1306a9
7
+ data.tar.gz: cd45d0a0f890212298030dc1574fe900ccd13ae6b64bf7d57bce863ec7950e65d34238a6f8dedaabab0fadf04b9bf3e1defa4b2d47912e1285c6dd0756db7c1e
data/.gitignore CHANGED
@@ -6,3 +6,9 @@
6
6
  /pkg/
7
7
  /spec/reports/
8
8
  /tmp/
9
+ *.gem
10
+ *.log
11
+ tags
12
+ Gemfile.lock
13
+ test.ssh
14
+ test.ssh.pub
data/README.md CHANGED
@@ -43,9 +43,10 @@ class EditController
43
43
  end
44
44
  ```
45
45
 
46
- Currently it has only 2 modules:
46
+ Currently it has 3 modules:
47
47
  * Condition Utilities
48
48
  * is_empty?(obj) - I find rather effort intensive to call if not (obj.nil? or obj.empty?) for items that I want to check for validity before process. Hence this method shall test for .nil?. If the object also respond to :empty? it shall be called again. For example integer type does not support .empty?
49
+ * not_empty?(obj) - Reverse of the is\_empty?(obj) above
49
50
 
50
51
  * Exception Utilities
51
52
  * raise_if_empty(obj, message, error) - Extension from the is_empty?() above, usually if it is empty, an exception shall be raised. It is just combined the conditions with raise of exception.
@@ -55,6 +56,12 @@ Currently it has only 2 modules:
55
56
  * raise_if_false(obj, message, error) - As the name implied
56
57
  * raise_if_true(obj, message, error) - As the name implied
57
58
 
59
+ * Process Utilities
60
+ * exec(command, options = { ), &block) - Passing in the command into the method and result is returned to caller. If options is not given shall go to basic execution which is the backtick (\`). If block empty, result of the command is returned to caller. If block is given, result (true or false of the execution of command and any result from STDOUT is call to block provider(e.g. block.call($?, result)
61
+
62
+ # Note on Process Utilities
63
+
64
+ The command is passed as it is to the operating system which includes fatal operation such as "rm -rf". Library at current stage made no filtering on system harmful command hence the caller of the library has to take extra precaution on what command is being passed into the library
58
65
 
59
66
 
60
67
 
@@ -13,11 +13,6 @@ module Antrapol
13
13
  class Error < StandardError; end
14
14
  # Your code goes here...
15
15
 
16
- class GlobalConf
17
- include Singleton
18
-
19
- end
20
-
21
16
  class Logger
22
17
  include Singleton
23
18
  include Antrapol::ToolRack::ConditionUtils
@@ -5,7 +5,9 @@ module Antrapol
5
5
  module ConditionUtils
6
6
 
7
7
  def is_empty?(obj)
8
- if obj.nil?
8
+ if not defined?(obj)
9
+ true
10
+ elsif obj.nil?
9
11
  true
10
12
  elsif obj.respond_to?(:empty?)
11
13
  obj.empty?
@@ -23,7 +23,7 @@ module Antrapol
23
23
  case type
24
24
  when :basic
25
25
  Antrapol::ToolRack::Logger.instance.glogger.debug "Basic execution"
26
- basic_exec(cmd)
26
+ basic_exec(cmd, &block)
27
27
  when :system
28
28
  Antrapol::ToolRack::Logger.instance.glogger.debug "System execution"
29
29
  system_exec(cmd, opts, &block)
@@ -33,7 +33,7 @@ module Antrapol
33
33
  else
34
34
  Antrapol::ToolRack::Logger.instance.glogger.debug "Basic (fallback) execution"
35
35
  # basic
36
- basic_exec(cmd)
36
+ basic_exec(cmd, &block)
37
37
  end
38
38
  end
39
39
 
@@ -41,9 +41,14 @@ module Antrapol
41
41
  # backtick
42
42
  # backtick will only return at the end of the process.
43
43
  # If in the event there is a prompt to user, this should nto be used.
44
- def basic_exec(cmd)
44
+ def basic_exec(cmd, &block)
45
45
  Antrapol::ToolRack::Logger.instance.glogger.debug "Basic shell exec command : #{cmd}"
46
- `#{cmd}`
46
+ res = `#{cmd}`
47
+ if block
48
+ block.call($?, res)
49
+ else
50
+ res
51
+ end
47
52
  end # basic_shell_exec
48
53
 
49
54
  # system
@@ -4,7 +4,7 @@ module Antrapol
4
4
  module ToolRack
5
5
  module RuntimeUtils
6
6
 
7
- def RuntimeUtils.on_window?
7
+ def RuntimeUtils.on_windows?
8
8
  (RbConfig::CONFIG['host_os'] =~ /cygwin|mswin|mingw|bccwin|wince|emx/) != nil
9
9
  end
10
10
 
@@ -0,0 +1,23 @@
1
+
2
+
3
+
4
+ module Antrapol
5
+ module Utils
6
+
7
+ def set_session_exception(exp)
8
+ if not exp.nil?
9
+ @sExp = exp
10
+ end
11
+ end
12
+
13
+ def session_exception
14
+ if not @sExp.nil?
15
+ @sExcp
16
+ else
17
+ Antrapol::ToolRack::Error
18
+ end
19
+ end
20
+ alias_method :session_exception, :s_exp
21
+
22
+ end
23
+ end
@@ -1,6 +1,6 @@
1
1
  module Antrapol
2
2
  module ToolRack
3
- VERSION = "0.4.0"
3
+ VERSION = "0.4.1"
4
4
  end
5
5
  end
6
6
 
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.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-10-15 00:00:00.000000000 Z
11
+ date: 2020-11-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tlogger
@@ -44,6 +44,7 @@ files:
44
44
  - lib/toolrack/exception_utils.rb
45
45
  - lib/toolrack/process_utils.rb
46
46
  - lib/toolrack/runtime_utils.rb
47
+ - lib/toolrack/utils.rb
47
48
  - lib/toolrack/version.rb
48
49
  - process_test/backtick_test.rb
49
50
  - process_test/pty_test.rb