heart_top 0.1.1 → 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: 3aa2fbbd860bce62565771866f90f7a00c9f6906
4
- data.tar.gz: bc4598692f44e88eb4bf482d0cf42574749b0fe0
3
+ metadata.gz: d3323458320eb456251621f2133e26371244e472
4
+ data.tar.gz: 445a18599febd626d1cae53215f807c1794f3a66
5
5
  SHA512:
6
- metadata.gz: 5d98a8792263913eb4177df37a9203a8a64b252ea81729df79c53c825acd7d17ce16feed050b3ed4da6238c07a0fa8a623c0a0f3d960008668eb8bf85f19182c
7
- data.tar.gz: 79a70980f69b878462a6776238c69cf4ae480469fa6b94fb23cc3da1858670fd2f741b7bbe56a11fb1dc56cb1e4a38bdfc48c4998aa98e9b2a427708a5a1e4de
6
+ metadata.gz: 4dc44252dfe86817e04797ab4f1964cb63c2b5e278f6b21e9bb56835b52d9cb1c6f5aac43ee873f57dcd94baf7ec00513b15967f46d4d39fcbbd44777c1b3995
7
+ data.tar.gz: 35af02250311501ac9538739c7aa63b5375a91a4d6ffcf0e773fbbb7fc17ce21eb5e2dc87d6a3a3261c00bf2ab19b6c12fdb59472d1987df9c9ccb4daf141c24
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,6 +1,8 @@
1
- source "https://rubygems.org"
1
+ # frozen_string_literal: true
2
2
 
3
- git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
3
+ source 'https://rubygems.org'
4
+
5
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
6
 
5
7
  # Specify your gem's dependencies in heart_top.gemspec
6
8
  gemspec
data/Rakefile CHANGED
@@ -1,6 +1,8 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
3
5
 
4
6
  RSpec::Core::RakeTask.new(:spec)
5
7
 
6
- task :default => :spec
8
+ task default: :spec
data/bin/console CHANGED
@@ -1,7 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
- require "bundler/setup"
4
- require "heart_top"
4
+ require 'bundler/setup'
5
+ require 'heart_top'
5
6
 
6
7
  # You can add fixtures and/or initialization code here to make experimenting
7
8
  # with your gem easier. You can also use a different console, if you like.
@@ -10,5 +11,5 @@ require "heart_top"
10
11
  # require "pry"
11
12
  # Pry.start
12
13
 
13
- require "irb"
14
+ require 'irb'
14
15
  IRB.start(__FILE__)
data/bin/hearttop CHANGED
@@ -1,12 +1,13 @@
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
  require 'heart_top'
12
- HeartTop::CLI.run(*ARGV)
13
+ HeartTop::CLI.run
data/heart_top.gemspec CHANGED
@@ -1,32 +1,35 @@
1
1
  # coding: utf-8
2
- lib = File.expand_path("../lib", __FILE__)
2
+ # frozen_string_literal: true
3
+
4
+ lib = File.expand_path('../lib', __FILE__)
3
5
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require "heart_top/version"
6
+ require 'heart_top/version'
5
7
 
6
8
  Gem::Specification.new do |spec|
7
- spec.name = "heart_top"
9
+ spec.name = 'heart_top'
8
10
  spec.version = HeartTop::VERSION
9
- spec.authors = ["Faizal Zakaria"]
10
- spec.email = ["fzakaria@codegarage.co"]
11
+ spec.authors = ['Faizal Zakaria']
12
+ spec.email = ['fzakaria@codegarage.co']
11
13
 
12
- spec.summary = %q{HeartTop pings the heartbeat of your laptop every N seconds}
14
+ spec.summary = 'HeartTop pings the heartbeat of your laptop every N seconds'
13
15
  spec.description = "Have you ever go to free space, coffee shops or some random place to work, \
14
16
  and you need to to toilet for pee, or big business? Then worried what would happen to your laptop? \
15
17
  This tool could be the solution"
16
- spec.homepage = "https://github.com/faizalzakaria/heart_top"
17
- spec.license = "MIT"
18
+ spec.homepage = 'https://github.com/faizalzakaria/heart_top'
19
+ spec.license = 'MIT'
18
20
 
19
21
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
20
22
  f.match(%r{^(test|spec|features)/})
21
23
  end
22
- spec.bindir = "bin"
24
+ spec.bindir = 'bin'
23
25
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
24
- spec.require_paths = ["lib"]
26
+ spec.require_paths = ['lib']
25
27
 
26
- spec.add_development_dependency "bundler", "~> 1.15"
27
- spec.add_development_dependency "rake", "~> 10.0"
28
- spec.add_development_dependency "rspec", "~> 3.0"
29
- spec.add_dependency "terminal-table", "~> 1.8.0"
30
- spec.add_dependency "rainbow", "~> 2.2.2"
31
- spec.add_dependency "dante", "~> 0.2.0"
28
+ spec.add_development_dependency 'bundler', '~> 1.15'
29
+ spec.add_development_dependency 'rake', '~> 10.0'
30
+ spec.add_development_dependency 'rspec', '~> 3.0'
31
+ spec.add_development_dependency 'rubocop', '~> 0.49'
32
+ spec.add_dependency 'terminal-table', '~> 1.8'
33
+ spec.add_dependency 'rainbow', '~> 2.2'
34
+ spec.add_dependency 'dante', '~> 0.2'
32
35
  end
@@ -1,26 +1,30 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'heart_top/plugin'
2
4
 
3
- class HeartTop::Agent
4
- PLUGINS = %i(slack)
5
+ module HeartTop
6
+ class Agent
7
+ PLUGINS = %i[slack].freeze
5
8
 
6
- def initialize(interval: , verbose: )
7
- @interval = interval
8
- @verbose = verbose
9
- end
9
+ def initialize(interval:, verbose:)
10
+ @interval = interval
11
+ @verbose = verbose
12
+ end
10
13
 
11
- def run
12
- while true do
13
- execute_plugins
14
- sleep @interval
14
+ def run
15
+ loop do
16
+ execute_plugins
17
+ sleep @interval
18
+ end
15
19
  end
16
- end
17
20
 
18
- private
21
+ private
19
22
 
20
- def execute_plugins
21
- puts 'executing ...' if @verbose
22
- PLUGINS.each do |plugin|
23
- Object.const_get("HeartTop::Plugin::#{plugin.capitalize}").send('ping')
23
+ def execute_plugins
24
+ puts 'executing ...' if @verbose
25
+ PLUGINS.each do |plugin|
26
+ Object.const_get("HeartTop::Plugin::#{plugin.capitalize}").instance.send('ping')
27
+ end
24
28
  end
25
29
  end
26
30
  end
data/lib/heart_top/cli.rb CHANGED
@@ -1,116 +1,116 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'heart_top/agent'
2
4
  require 'getoptlong'
3
5
  require 'terminal-table'
4
6
  require 'rainbow'
5
7
  require 'dante'
6
8
 
7
- class HeartTop::CLI
8
- attr_accessor :verbose, :interval
9
-
10
- class UnsupportedCommand < StandardError; end
11
-
12
- class << self
13
- def run(*args)
14
- begin
15
- parse_args!(args)
16
- rescue UnsupportedCommand => e
17
- print_error(e.message)
18
- exit
19
- end
20
- set_defaults
21
- print_details
22
- execute!
23
- true
24
- end
25
-
26
- private
27
-
28
- def execute!
29
- send("#@command!")
30
- end
31
-
32
- def pid_path
33
- '/tmp/heartop.pid'
34
- end
35
-
36
- def log_path
37
- '/tmp/hearttop.log'
38
- end
39
-
40
- def start!
41
- options = {
42
- interval: @interval,
43
- verbose: @verbose
44
- }
45
- Dante::Runner
46
- .new('hearttop')
47
- .execute(daemonize: true, pid_path: pid_path, log_path: log_path) do |opts|
48
- HeartTop::Agent.new(options).run
49
- end
50
- end
51
-
52
- def stop!
53
- Dante::Runner
54
- .new('hearttop')
55
- .execute(:kill => true, :pid_path => pid_path)
56
- end
57
-
58
- def set_defaults
59
- @interval ||= 10
60
- @verbose ||= false
61
- end
62
-
63
- def parse_args!(args)
64
- opts = GetoptLong.new([ '--help', '-h', GetoptLong::NO_ARGUMENT ],
65
- [ '--interval', '-i', GetoptLong::REQUIRED_ARGUMENT ],
66
- [ '--verbose', '-v', GetoptLong::NO_ARGUMENT ])
67
- @interval = nil
68
- @verboes = nil
69
- opts.each do |opt, arg|
70
- case opt
71
- when '--help'
72
- print_help
73
- when '--interval'
74
- @interval = arg
75
- when '--verbose'
76
- @verbose = true
77
- end
78
- end
79
- @command = args.last
80
- unless supported_commands?(@command)
81
- raise UnsupportedCommand.new(Rainbow("Unsupported command detected, ").red + Rainbow(@command).green)
82
- end
83
- end
84
-
85
- def supported_commands?(cmd)
86
- %w(stop start).include?(cmd)
87
- end
88
-
89
- def print_details
90
- return unless @verbose
91
- table = Terminal::Table.new do |t|
92
- t << [Rainbow('verbose').green, Rainbow(@verbose).green]
93
- t.add_row [Rainbow('interval').green, Rainbow(@interval).green]
94
- t.add_row [Rainbow('command').green, Rainbow(@command).green]
9
+ module HeartTop
10
+ class CLI
11
+ attr_accessor :verbose, :interval
12
+
13
+ class UnsupportedCommand < StandardError; end
14
+
15
+ class << self
16
+ def run
17
+ begin
18
+ parse_args!
19
+ rescue UnsupportedCommand => e
20
+ print_error(e.message)
21
+ exit
22
+ end
23
+ set_defaults
24
+ print_details
25
+ execute
26
+ end
27
+
28
+ private
29
+
30
+ def execute!
31
+ send("#{@command}!")
32
+ end
33
+
34
+ def pid_path
35
+ '/tmp/heartop.pid'
36
+ end
37
+
38
+ def log_path
39
+ '/tmp/hearttop.log'
40
+ end
41
+
42
+ def start
43
+ options = {
44
+ interval: @interval,
45
+ verbose: @verbose
46
+ }
47
+ Dante::Runner
48
+ .new('hearttop')
49
+ .execute(daemonize: true, pid_path: pid_path, log_path: log_path) do |_opts|
50
+ HeartTop::Agent.new(options).run
51
+ end
95
52
  end
96
- puts table
97
- end
98
53
 
99
- def print_error(msg)
100
- puts Rainbow(msg).red
101
- end
54
+ def stop
55
+ Dante::Runner
56
+ .new('hearttop')
57
+ .execute(kill: true, pid_path: pid_path)
58
+ end
59
+
60
+ def set_defaults
61
+ @interval ||= 10
62
+ @verbose ||= false
63
+ end
102
64
 
103
- def print_help
104
- puts <<-EOF
105
- heartbeat [OPTION]
65
+ def parse_args!
66
+ opts = GetoptLong.new(['--help', '-h', GetoptLong::NO_ARGUMENT],
67
+ ['--interval', '-i', GetoptLong::REQUIRED_ARGUMENT],
68
+ ['--verbose', '-v', GetoptLong::NO_ARGUMENT])
69
+ @interval = nil
70
+ @verboes = nil
71
+ opts.each do |opt, arg|
72
+ case opt
73
+ when '--help'
74
+ print_help
75
+ when '--interval'
76
+ @interval = arg
77
+ when '--verbose'
78
+ @verbose = true
79
+ end
80
+ end
81
+ @command = ARGV.shift
82
+ return if supported_commands?(@command)
83
+ raise UnsupportedCommand, Rainbow('Unsupported command detected, ').red + Rainbow(@command).green
84
+ end
106
85
 
107
- --help, -h:
108
- show help
86
+ def supported_commands?(cmd)
87
+ cmd.nil? || %w[stop start].include?(cmd)
88
+ end
109
89
 
110
- --interval <interval>, -i <interval>:
111
- interval, e.g: 10 (in seconds)
90
+ def print_details
91
+ return unless @verbose
92
+ table = Terminal::Table.new do |t|
93
+ t << [Rainbow('verbose').green, Rainbow(@verbose).green]
94
+ t.add_row [Rainbow('interval').green, Rainbow(@interval).green]
95
+ t.add_row [Rainbow('command').green, Rainbow(@command).green]
96
+ end
97
+ puts table
98
+ end
99
+
100
+ def print_error(msg)
101
+ puts Rainbow(msg).red
102
+ end
103
+
104
+ def print_help
105
+ puts <<~EOF
106
+ heartbeat [OPTION]
107
+ --help, -h:
108
+ show help
109
+ --interval [interval], -i [interval]:
110
+ interval, e.g: 10 (in seconds)
112
111
 
113
112
  EOF
114
- end
113
+ end
114
+ end
115
115
  end
116
116
  end
@@ -1,9 +1,15 @@
1
- class HeartTop::Plugin::Base
2
- class NotImplementedError < StandardError; end
1
+ # frozen_string_literal: true
3
2
 
4
- class << self
5
- def ping
6
- raise NotImplementedError.new "`##{__method__}` must be implemented in subclass"
3
+ # Base Plugin class
4
+ # Inherit this class if you adding a new plugin
5
+ module HeartTop
6
+ module Plugin
7
+ class Base
8
+ class NotImplementedError < StandardError; end
9
+
10
+ def ping
11
+ raise NotImplementedError, "`##{__method__}` must be implemented in subclass"
12
+ end
7
13
  end
8
14
  end
9
15
  end
@@ -1,11 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'heart_top/plugin/base'
4
+ require 'singleton'
5
+ require 'json'
6
+
1
7
  module HeartTop
2
8
  module Plugin
3
- class Slack
4
- class << self
5
- def ping
6
- puts 'test'
7
- `curl -X POST --data-urlencode 'payload={"channel": "#hearttop", "username": "hearttop", "text": "This is posted to #hearttop and comes from a bot named hearttop.", "icon_emoji": ":ghost:"}' https://hooks.slack.com/services/<key>`
8
- end
9
+ class Slack < Base
10
+ include Singleton
11
+
12
+ def ping
13
+ `curl -X POST --data-urlencode 'payload=#{payload}' #{webhook_url}`
14
+ end
15
+
16
+ private
17
+
18
+ def payload
19
+ {
20
+ channel: '#hearttop',
21
+ username: 'hearttop',
22
+ text: 'This is posted to #hearttop and comes from a bot named hearttop.',
23
+ icon_emoji: ':ghost:'
24
+ }.to_json.to_s
25
+ end
26
+
27
+ def webhook_url
28
+ ENV['SLACK_WEBHOOK_URL']
9
29
  end
10
30
  end
11
31
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module HeartTop
2
4
  module Plugin
3
5
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  every 1.minute do
2
- rake "fave:generate_weekly_statements"
4
+ rake 'fave:generate_weekly_statements'
3
5
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module HeartTop
2
- VERSION = "0.1.1"
4
+ VERSION = '0.2.0'
3
5
  end
data/lib/heart_top.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'heart_top/version'
2
4
  require 'heart_top/cli'
3
5
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: heart_top
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Faizal Zakaria
@@ -52,48 +52,62 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.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: terminal-table
57
71
  requirement: !ruby/object:Gem::Requirement
58
72
  requirements:
59
73
  - - "~>"
60
74
  - !ruby/object:Gem::Version
61
- version: 1.8.0
75
+ version: '1.8'
62
76
  type: :runtime
63
77
  prerelease: false
64
78
  version_requirements: !ruby/object:Gem::Requirement
65
79
  requirements:
66
80
  - - "~>"
67
81
  - !ruby/object:Gem::Version
68
- version: 1.8.0
82
+ version: '1.8'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: rainbow
71
85
  requirement: !ruby/object:Gem::Requirement
72
86
  requirements:
73
87
  - - "~>"
74
88
  - !ruby/object:Gem::Version
75
- version: 2.2.2
89
+ version: '2.2'
76
90
  type: :runtime
77
91
  prerelease: false
78
92
  version_requirements: !ruby/object:Gem::Requirement
79
93
  requirements:
80
94
  - - "~>"
81
95
  - !ruby/object:Gem::Version
82
- version: 2.2.2
96
+ version: '2.2'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: dante
85
99
  requirement: !ruby/object:Gem::Requirement
86
100
  requirements:
87
101
  - - "~>"
88
102
  - !ruby/object:Gem::Version
89
- version: 0.2.0
103
+ version: '0.2'
90
104
  type: :runtime
91
105
  prerelease: false
92
106
  version_requirements: !ruby/object:Gem::Requirement
93
107
  requirements:
94
108
  - - "~>"
95
109
  - !ruby/object:Gem::Version
96
- version: 0.2.0
110
+ version: '0.2'
97
111
  description: Have you ever go to free space, coffee shops or some random place to
98
112
  work, and you need to to toilet for pee, or big business? Then worried what would
99
113
  happen to your laptop? This tool could be the solution
@@ -108,6 +122,7 @@ extra_rdoc_files: []
108
122
  files:
109
123
  - ".gitignore"
110
124
  - ".rspec"
125
+ - ".rubocop.yml"
111
126
  - ".travis.yml"
112
127
  - Gemfile
113
128
  - LICENSE.txt
@@ -146,7 +161,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
146
161
  version: '0'
147
162
  requirements: []
148
163
  rubyforge_project:
149
- rubygems_version: 2.4.5.1
164
+ rubygems_version: 2.6.11
150
165
  signing_key:
151
166
  specification_version: 4
152
167
  summary: HeartTop pings the heartbeat of your laptop every N seconds