time_block 0.0.4 → 0.1.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: 1f28e03f24679b200a951719f22b947ff78118fd
4
- data.tar.gz: d8957de296fa34a5409a4f93ca956279726cc2c1
3
+ metadata.gz: 624ed86cb990310569fd1d59b14938c9a1c0a0a3
4
+ data.tar.gz: b06f5c3c3a72201701d88908adfb393289729698
5
5
  SHA512:
6
- metadata.gz: b5268e38b822c9aad007ae5a8dc2ab5959bba9554da5d1466ab29dcfe669d7ba20112aeded0d2bf07c4c5409b16ff0f7f246333b36f38b22a06811a7c85722e3
7
- data.tar.gz: 6658811d2186855e182683c4291c23f2785b75fcdaffa08beeb9d04ed6cc3e8bf2dd539e4ace4e4d0383132bb8680c0a2817096625aacf1ddf914e4e87fa0ca4
6
+ metadata.gz: d8d654a9b381ed006c3fd08b8452c2777a0065f25d75a552d0712609894cbe2f373ce854603f9e73bc4cc803ba7fe5595236449b50b29adc6bc4fbf5d87be2d8
7
+ data.tar.gz: 9e6bfb15e061ba1281d763dcc1459f19ca622310c3032f83ad65acd9cd3ae6a44b593fee5a6ae42f0e475b318039819bd83acd6d9fc5649fb6ab822d34aa7ecb
data/.rubocop.yml ADDED
@@ -0,0 +1,26 @@
1
+ AllCops:
2
+ Exclude: []
3
+ TargetRubyVersion: 2.3
4
+
5
+ Bundler/OrderedGems:
6
+ Enabled: false
7
+
8
+ Metrics/BlockLength:
9
+ Exclude:
10
+ - '*.gemspec'
11
+ - 'spec/**/*'
12
+
13
+ Metrics/LineLength:
14
+ Max: 130
15
+ Exclude:
16
+ - '*.gemspec'
17
+ - 'spec/**/*'
18
+
19
+ Metrics/MethodLength:
20
+ Max: 120
21
+
22
+ Metrics/AbcSize:
23
+ Enabled: false
24
+
25
+ Style/Documentation:
26
+ Enabled: false
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  # Specify your gem's dependencies in time_block.gemspec
data/Rakefile CHANGED
@@ -1,2 +1,3 @@
1
- require "bundler/gem_tasks"
1
+ # frozen_string_literal: true
2
2
 
3
+ require 'bundler/gem_tasks'
data/bin/timeblock CHANGED
@@ -1,14 +1,15 @@
1
1
  #!/usr/bin/env ruby
2
2
  # encoding: UTF-8
3
+ # frozen_string_literal: true
3
4
 
4
5
  # resolve bin path, ignoring symlinks
5
- require "pathname"
6
+ require 'pathname'
6
7
  bin_file = Pathname.new(__FILE__).realpath
7
8
 
8
9
  # add self to libpath
9
- $:.unshift File.expand_path("../../lib", bin_file)
10
+ $LOAD_PATH.unshift File.expand_path('../../lib', bin_file)
10
11
 
11
12
  # start up the CLI
12
- require "time_block/cli"
13
+ require 'time_block/cli'
13
14
 
14
- TimeBlock::CLI.start(*ARGV)
15
+ TimeBlock::CLI.run
@@ -1,27 +1,31 @@
1
- class TimeBlock::Agent
2
- def initialize(time)
3
- fail 'No terminal-notifier, please install it, brew install terminal-notifier' unless terminal_notifier_exist?
4
- @time = time
5
- end
1
+ # frozen_string_literal: true
6
2
 
7
- def run
8
- pre_callback
9
- sleep @time
10
- post_callback
11
- end
3
+ module TimeBlock
4
+ class Agent
5
+ def initialize(time)
6
+ raise 'No terminal-notifier, please install it, brew install terminal-notifier' unless terminal_notifier_exist?
7
+ @time = time
8
+ end
12
9
 
13
- private
10
+ def run
11
+ pre_callback
12
+ sleep @time
13
+ post_callback
14
+ end
14
15
 
15
- def terminal_notifier_exist?
16
- `which terminal-notifier`
17
- $? == 0
18
- end
16
+ private
19
17
 
20
- def pre_callback
21
- `terminal-notifier -message #{"Time is starting !!!".dump} -title "TimeBlock - #{@time}s" -sound "default"`
22
- end
18
+ def terminal_notifier_exist?
19
+ `which terminal-notifier`
20
+ $CHILD_STATUS.zero?
21
+ end
22
+
23
+ def pre_callback
24
+ `terminal-notifier -message #{'Time is starting !!!'.dump} -title "TimeBlock - #{@time}s" -sound "default"`
25
+ end
23
26
 
24
- def post_callback
25
- `terminal-notifier -message #{"Time is out dude !!!".dump} -title "TimeBlock - #{@time}s" -sound "default"`
27
+ def post_callback
28
+ `terminal-notifier -message #{'Time is out dude !!!'.dump} -title "TimeBlock - #{@time}s" -sound "default"`
29
+ end
26
30
  end
27
31
  end
@@ -1,15 +1,96 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dante'
2
4
  require 'time_block'
3
5
  require 'time_block/agent'
6
+ require 'getoptlong'
7
+
8
+ module TimeBlock
9
+ class CLI
10
+ class << self
11
+ class UnsupportedCommand < StandardError; end
12
+
13
+ def run
14
+ parse_args
15
+ set_defaults
16
+ execute
17
+ end
18
+
19
+ private
20
+
21
+ def execute
22
+ send(@command)
23
+ end
24
+
25
+ def restart
26
+ stop
27
+ start
28
+ end
29
+
30
+ def start
31
+ Dante::Runner
32
+ .new('timeblock')
33
+ .execute(daemonize: true, pid_path: pid_path, log_path: log_path) do |_opts|
34
+ TimeBlock::Agent.new(@time).run
35
+ end
36
+ end
37
+
38
+ def stop
39
+ Dante::Runner
40
+ .new('timeblock')
41
+ .execute(kill: true, pid_path: pid_path)
42
+ end
43
+
44
+ def pid_path
45
+ '/tmp/timeblock.pid'
46
+ end
47
+
48
+ def log_path
49
+ '/tmp/timeblock.log'
50
+ end
51
+
52
+ def set_defaults
53
+ @time ||= 60
54
+ @verbose ||= false
55
+ end
56
+
57
+ def parse_args
58
+ opts = GetoptLong.new(['--help', '-h', GetoptLong::NO_ARGUMENT],
59
+ ['--time', '-t', GetoptLong::REQUIRED_ARGUMENT],
60
+ ['--verbose', '-v', GetoptLong::NO_ARGUMENT])
61
+ @time = nil
62
+ @verboes = nil
63
+ opts.each do |opt, arg|
64
+ case opt
65
+ when '--help'
66
+ print_help
67
+ exit(0)
68
+ when '--time'
69
+ @time = arg.to_i
70
+ when '--verbose'
71
+ @verbose = true
72
+ end
73
+ end
74
+
75
+ @command = ARGV.shift
76
+ return if supported_commands?(@command)
77
+ raise UnsupportedCommand, "Unsupported command detected, #{@command}"
78
+ end
79
+
80
+ def supported_commands?(cmd)
81
+ cmd.nil? || %w[stop start restart].include?(cmd)
82
+ end
83
+
84
+ def print_help
85
+ puts <<~EOF
86
+ heartbeat [OPTION]
87
+ --help, -h:
88
+ show help
89
+ --time [time], -i [time]:
90
+ interval, e.g: 60 (in seconds)
4
91
 
5
- class TimeBlock::CLI
6
- def self.start(*args)
7
- time = args.shift.strip.to_i
8
- Dante::Runner.new('timeblock').execute(daemonize: true, pid_path: '/tmp/timeblock.pid', log_path: '/tmp/timblock.log') do |opts|
9
- TimeBlock::Agent.new(time).run
92
+ EOF
93
+ end
10
94
  end
11
- rescue => e
12
- puts e.message
13
- exit(1)
14
95
  end
15
96
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module TimeBlock
2
- VERSION = "0.0.4"
4
+ VERSION = '0.1.0'
3
5
  end
data/lib/time_block.rb CHANGED
@@ -1,4 +1,6 @@
1
- require "time_block/version"
1
+ # frozen_string_literal: true
2
+
3
+ require 'time_block/version'
2
4
 
3
5
  module TimeBlock
4
6
  end
data/time_block.gemspec CHANGED
@@ -1,26 +1,29 @@
1
1
  # coding: utf-8
2
+ # frozen_string_literal: true
3
+
2
4
  lib = File.expand_path('../lib', __FILE__)
3
5
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
6
  require 'time_block/version'
5
7
 
6
8
  Gem::Specification.new do |spec|
7
- spec.name = "time_block"
9
+ spec.name = 'time_block'
8
10
  spec.version = TimeBlock::VERSION
9
- spec.authors = ["Faizal Zakaria"]
10
- spec.email = ["phaibusiness@gmail.com"]
11
- spec.summary = %q{Time block}
12
- spec.description = %q{Notifier to notify you when your time block is ended}
13
- spec.homepage = ""
14
- spec.license = "MIT"
15
- spec.executables = "timeblock"
11
+ spec.authors = ['Faizal Zakaria']
12
+ spec.email = ['phaibusiness@gmail.com']
13
+ spec.summary = 'Time block'
14
+ spec.description = 'Notifier to notify you when your time block is ended'
15
+ spec.homepage = ''
16
+ spec.license = 'MIT'
17
+ spec.executables = 'timeblock'
16
18
 
17
19
  spec.files = `git ls-files -z`.split("\x0")
18
20
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
21
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
- spec.require_paths = ["lib"]
22
+ spec.require_paths = ['lib']
21
23
 
22
- spec.add_development_dependency "bundler", "~> 1.6"
23
- spec.add_development_dependency "rake"
24
- spec.add_runtime_dependency "terminal-notifier"
25
- spec.add_dependency "dante"
24
+ spec.add_development_dependency 'bundler', '~> 1.6'
25
+ spec.add_development_dependency 'rake'
26
+ spec.add_runtime_dependency 'terminal-notifier'
27
+ spec.add_development_dependency 'rubocop', '~> 0.49'
28
+ spec.add_dependency 'dante'
26
29
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: time_block
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Faizal Zakaria
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-03 00:00:00.000000000 Z
11
+ date: 2017-08-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.49'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.49'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: dante
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -75,6 +89,7 @@ extensions: []
75
89
  extra_rdoc_files: []
76
90
  files:
77
91
  - ".gitignore"
92
+ - ".rubocop.yml"
78
93
  - Gemfile
79
94
  - LICENSE.txt
80
95
  - README.md
@@ -105,7 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
105
120
  version: '0'
106
121
  requirements: []
107
122
  rubyforge_project:
108
- rubygems_version: 2.4.2
123
+ rubygems_version: 2.6.11
109
124
  signing_key:
110
125
  specification_version: 4
111
126
  summary: Time block