HelperClasses 0.2.0 → 0.2.1

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
  SHA1:
3
- metadata.gz: 93e502dfc1275307448cbb1a400fb2e9f66cc9bb
4
- data.tar.gz: 9a11df7ce26d9d05413b1fc26c56943adec234b7
3
+ metadata.gz: 3b208cc914a604115d2fc6d6d3f9b7d76ed5c0aa
4
+ data.tar.gz: b2d52052bceeeba6bfcdbda794f1c706cf8529ab
5
5
  SHA512:
6
- metadata.gz: 8dc8b0468193eb16e9b776b17951f9cfd353b6f84624edb65817bb9ec0b1ae3f9a84a58d7de96f9ecb9e784983e592b49fe55928579e33bc6fb4a5b69594aa15
7
- data.tar.gz: 93af48558a982873408929fd5a57ac57e633ee5180dcd22aa461d8b44db3d61723bdeb88f52e15e163240a92fd13542d634597d58d1a8ed8d97cf29b0fdb3dcf
6
+ metadata.gz: 17553d25124e09719b439fc8febb3d51c6b1d4dd86349a9c1797f180221809ae25ac9695fb100da8b926bbf21fde8b7d332f0ae0408364967dfa07b618b872cb
7
+ data.tar.gz: d56495c03e90a4ab551ea9ad80d99625cde1d41673c11db234bca4b41720509a68d66c1e0646b9b4c5b6f2aea01a0acb5ecf2733d82314a331dbec69c621e6f5
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'HelperClasses'
3
- s.version = '0.2.0'
4
- s.date = '2015-04-06'
3
+ s.version = '0.2.1'
4
+ s.date = '2015-05-12'
5
5
  s.summary = 'Hash._accessor Array.to_sym and DPuts'
6
6
  s.description = 'Added accessors to Hash, to_sym to Array and a nice debugging-interface called DPuts'
7
7
  s.authors = ['Linus Gasser']
@@ -8,7 +8,7 @@ module HelperClasses
8
8
 
9
9
  @mutex = Mutex.new
10
10
  @silent = false
11
- @show_time = 60
11
+ @show_time = false
12
12
  @terminal_width = 160
13
13
  @log_file = false
14
14
 
@@ -23,25 +23,29 @@ module HelperClasses
23
23
  show = now.to_i != $dputs_time.to_i
24
24
  when /min/
25
25
  show = (now.to_i / 60).floor != ($dputs_time.to_i / 60).floor
26
+ when /hour/
27
+ show = (now.to_i / 3600).floor != ($dputs_time.to_i / 3600).floor
28
+ end
29
+ if show
30
+ puts "\n *** It is now: " +
31
+ Time.now.strftime('%Y-%m-%d %H:%M:%S')
32
+ $dputs_time = now
26
33
  end
27
- show and puts "\n *** It is now: " +
28
- Time.now.strftime("%Y-%m-%d %H:%M:%S")
29
- $dputs_time = now
30
34
  end
31
35
  DPuts.mutex.synchronize do
32
- width = DPuts.terminal_width
33
- width -= 30.0
34
- file, func = call.split(" ")
36
+ width = DPuts.terminal_width.to_i || 160
37
+ width = [width - 30.0, 10].max
38
+ file, func = call.split(' ')
35
39
  file = file[/^.*\/([^.]*)/, 1]
36
- who = (":" + n.to_s + ":" + file.to_s +
37
- func.to_s).ljust(30, ["X", "x", "*", "-", ".", " "][n])
40
+ who = (':' + n.to_s + ':' + file.to_s +
41
+ func.to_s).ljust(30, ['X', 'x', '*', '-', '.', ' '][n])
38
42
  lines = []
39
43
  pos = 0
40
44
  while (pos < s.length)
41
45
  len = width
42
46
  if s.length - pos > width
43
47
  len = s.rindex(/[, .;=&>]/, pos + width)
44
- len and len = len - pos + 1
48
+ len = len ? len - pos + 1 : width
45
49
  if len < width / 2
46
50
  len = width
47
51
  end
@@ -49,9 +53,9 @@ module HelperClasses
49
53
  lines.push s.slice(pos, len)
50
54
  pos += len
51
55
  end
52
- puts who + " " + lines.shift.to_s
56
+ puts who + ' ' + lines.shift.to_s
53
57
  lines.each { |l|
54
- puts " " * (32) + l
58
+ puts ' ' * (32) + l
55
59
  }
56
60
  end
57
61
  end
@@ -73,7 +77,7 @@ module HelperClasses
73
77
 
74
78
  def dputs(n, &s)
75
79
  n *= -1 if ($DPUTS_FUNCS and $DPUTS_FUNCS.index(dputs_getcaller))
76
- if !self.class.const_defined?(:DEBUG_LVL) or
80
+ if !self.class.const_defined?(:DEBUG_LVL) or
77
81
  self.class.const_get(:DEBUG_LVL) >= n
78
82
  s = yield s
79
83
  dputs_out(n, s, caller(0)[1])
@@ -94,11 +98,14 @@ module HelperClasses
94
98
  def log_msg(mod, msg)
95
99
  dputs(1) { "Info from #{mod}: #{msg}" }
96
100
  return if not DPuts.log_file
97
- File.open(DPuts.log_file, "a") { |f|
101
+ File.open(DPuts.log_file, 'a') { |f|
98
102
  str = Time.now.strftime("%a %y.%m.%d-%H:%M:%S #{mod}: #{msg}")
99
103
  f.puts str
100
104
  }
101
105
  end
102
106
 
107
+ def dlog_msg(mod, msg)
108
+ ddputs(1){"Info from #{mod}: #{msg}"}
109
+ end
103
110
  end
104
111
  end
@@ -22,15 +22,32 @@ module HelperClasses
22
22
  run_bool("which #{cmd} > /dev/null 2>&1")
23
23
  end
24
24
 
25
- def rescue_all(msg = nil)
25
+ def rescue_all(msg = 'Error')
26
26
  begin
27
27
  yield
28
28
  rescue Exception => e
29
- msg and dputs(0) { msg }
29
+ dputs(0) { "#{Time.now.strftime('%a %y.%m.%d-%H:%M:%S')} - #{msg}" }
30
30
  dputs(0) { "#{e.inspect}" }
31
31
  dputs(0) { "#{e.to_s}" }
32
32
  e.backtrace.each { |l| dputs(0) { l } }
33
33
  end
34
34
  end
35
+
36
+ def iptables(*args)
37
+ if !@iptables_cmd
38
+ if System.exists?('iptables')
39
+ @iptables_cmd = 'iptables'
40
+ @iptables_wait = (System.run_str('iptables --help') =~ /\s-w\s/) ? '-w' : ''
41
+ else
42
+ @iptables_cmd = ''
43
+ end
44
+ end
45
+
46
+ if @iptables_cmd != ''
47
+ System.run_str("#{@iptables_cmd} #{@iptables_wait} #{args.join(' ')}")
48
+ else
49
+ return ''
50
+ end
51
+ end
35
52
  end
36
53
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: HelperClasses
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Linus Gasser
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-06 00:00:00.000000000 Z
11
+ date: 2015-05-12 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Added accessors to Hash, to_sym to Array and a nice debugging-interface
14
14
  called DPuts