time_block 0.1.0 → 0.2.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
  SHA1:
3
- metadata.gz: 624ed86cb990310569fd1d59b14938c9a1c0a0a3
4
- data.tar.gz: b06f5c3c3a72201701d88908adfb393289729698
3
+ metadata.gz: 1a964dbdb28c131ce8b552e6cba90787838888e8
4
+ data.tar.gz: 9a7e9dd402665a1b0e7e79257f37be835ea225a4
5
5
  SHA512:
6
- metadata.gz: d8d654a9b381ed006c3fd08b8452c2777a0065f25d75a552d0712609894cbe2f373ce854603f9e73bc4cc803ba7fe5595236449b50b29adc6bc4fbf5d87be2d8
7
- data.tar.gz: 9e6bfb15e061ba1281d763dcc1459f19ca622310c3032f83ad65acd9cd3ae6a44b593fee5a6ae42f0e475b318039819bd83acd6d9fc5649fb6ab822d34aa7ecb
6
+ metadata.gz: c9ec9329e1faf1145ae66915b51b3ee855a1cbc510ac3f513c2c7c81b1834bf94b99eb215f194414474b552a9e570c5368e29cd1c019756277f89a48e505d2a8
7
+ data.tar.gz: a7bb8be9b2b0c237f3d4cf6da65ef4cc9048fdb69d40b4e343785e9d4c51c9904d4146f12afbf3665f7fa639aa33ad6ff23c3def32516c76f68e883377845de7
@@ -1,9 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'English'
4
+
3
5
  module TimeBlock
4
6
  class Agent
7
+
8
+ class MissingPackageError < StandardError; end
9
+
5
10
  def initialize(time)
6
- raise 'No terminal-notifier, please install it, brew install terminal-notifier' unless terminal_notifier_exist?
11
+ raise MissingPackageError.new('No terminal-notifier, please install it, brew install terminal-notifier') unless terminal_notifier_exist?
7
12
  @time = time
8
13
  end
9
14
 
@@ -17,7 +22,7 @@ module TimeBlock
17
22
 
18
23
  def terminal_notifier_exist?
19
24
  `which terminal-notifier`
20
- $CHILD_STATUS.zero?
25
+ $CHILD_STATUS.success?
21
26
  end
22
27
 
23
28
  def pre_callback
@@ -11,9 +11,11 @@ module TimeBlock
11
11
  class UnsupportedCommand < StandardError; end
12
12
 
13
13
  def run
14
- parse_args
14
+ parse_args!
15
15
  set_defaults
16
16
  execute
17
+ rescue UnsupportedCommand => e
18
+ puts e.message
17
19
  end
18
20
 
19
21
  private
@@ -28,6 +30,7 @@ module TimeBlock
28
30
  end
29
31
 
30
32
  def start
33
+ puts "Time #{@time}s ..."
31
34
  Dante::Runner
32
35
  .new('timeblock')
33
36
  .execute(daemonize: true, pid_path: pid_path, log_path: log_path) do |_opts|
@@ -54,7 +57,7 @@ module TimeBlock
54
57
  @verbose ||= false
55
58
  end
56
59
 
57
- def parse_args
60
+ def parse_args!
58
61
  opts = GetoptLong.new(['--help', '-h', GetoptLong::NO_ARGUMENT],
59
62
  ['--time', '-t', GetoptLong::REQUIRED_ARGUMENT],
60
63
  ['--verbose', '-v', GetoptLong::NO_ARGUMENT])
@@ -67,6 +70,11 @@ module TimeBlock
67
70
  exit(0)
68
71
  when '--time'
69
72
  @time = arg.to_i
73
+ if arg.chars.last == 'm'
74
+ @time *= 60
75
+ elsif arg.chars.last == 'h'
76
+ @time *= 60 * 24
77
+ end
70
78
  when '--verbose'
71
79
  @verbose = true
72
80
  end
@@ -78,7 +86,7 @@ module TimeBlock
78
86
  end
79
87
 
80
88
  def supported_commands?(cmd)
81
- cmd.nil? || %w[stop start restart].include?(cmd)
89
+ %w[stop start restart].include?(cmd)
82
90
  end
83
91
 
84
92
  def print_help
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TimeBlock
4
- VERSION = '0.1.0'
4
+ VERSION = '0.2.0'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: time_block
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Faizal Zakaria