eye-patch 0.5.1 → 1.0.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: 55fcb9ea9eeb35bdedf9cf01f89e807e8c11ecf5
4
- data.tar.gz: 451a2aa76f4804825671d64d5b7b9094afb16df2
3
+ metadata.gz: f040c35d2b8df2e0be5a9c2cdaf839187a438882
4
+ data.tar.gz: b8966ebf6aff7d2a03f6d34a790010864b6c9491
5
5
  SHA512:
6
- metadata.gz: 1a832b7eebe66cd52c2b581a25669668c46738646f9878ec90f03389698625cfc504969b8df5cccbf5e0d6232339d7d3fff4c524783b016ff04c36567da02c51
7
- data.tar.gz: ba9036e27f9b35a5ab47ad9d382e841ec39a55f9923abf6492434bb29b140237964dada6c11939a2311efc23b6131d53b37cded1727cd0a6e5e1717d7d6f24fc
6
+ metadata.gz: 833f95e305b8af149028dab3356565e7c302358f6d8d8eab4ef5439786529d3e0de915e5f5da8a9b235c1f45e8b994fa67aaf0104930b8361c03f7de33083474
7
+ data.tar.gz: 7177aeee067ff241387f13f8dedb3d150b1cced75cf1089171fea952ac68e9edf7a1fd370b352b88f0b90caa701dc1676f51be476bc7000a3d2db279e6e41699
@@ -0,0 +1,2 @@
1
+ rubocop:
2
+ config_file: .rubocop.yml
@@ -0,0 +1,46 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.4.2
3
+
4
+ inherit_from: .rubocop_todo.yml
5
+
6
+ Layout/EmptyLinesAroundClassBody:
7
+ EnforcedStyle: empty_lines
8
+
9
+ Layout/EmptyLinesAroundModuleBody:
10
+ EnforcedStyle: empty_lines
11
+
12
+ Layout/MultilineMethodCallIndentation:
13
+ EnforcedStyle: indented
14
+
15
+ Metrics/BlockLength:
16
+ Exclude:
17
+ - lib/eye/patch/capistrano.rb
18
+ - lib/eye/patch/capistrano3.rb
19
+ - lib/eye/patch/overrides.rb
20
+ - test/**/*.rb
21
+
22
+ Metrics/CyclomaticComplexity:
23
+ Exclude:
24
+ - lib/eye/patch/overrides.rb
25
+
26
+ Metrics/PerceivedComplexity:
27
+ Exclude:
28
+ - lib/eye/patch/overrides.rb
29
+
30
+ Style/Documentation:
31
+ Enabled: false
32
+
33
+ Style/StringLiterals:
34
+ EnforcedStyle: double_quotes
35
+
36
+ Style/ClassAndModuleChildren:
37
+ Enabled: false
38
+
39
+ Style/TrailingCommaInArguments:
40
+ EnforcedStyleForMultiline: comma
41
+
42
+ Style/TrailingCommaInArrayLiteral:
43
+ EnforcedStyleForMultiline: comma
44
+
45
+ Style/TrailingCommaInHashLiteral:
46
+ EnforcedStyleForMultiline: comma
@@ -0,0 +1,22 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2018-04-04 14:04:52 -0600 using RuboCop version 0.54.0.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 5
10
+ Metrics/AbcSize:
11
+ Max: 40
12
+
13
+ # Offense count: 7
14
+ # Configuration parameters: CountComments.
15
+ Metrics/MethodLength:
16
+ Max: 25
17
+
18
+ # Offense count: 32
19
+ # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
20
+ # URISchemes: http, https
21
+ Metrics/LineLength:
22
+ Max: 183
data/Gemfile CHANGED
@@ -1,4 +1,6 @@
1
- source 'https://rubygems.org'
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
2
4
 
3
5
  # Specify your gem's dependencies in eye-patch.gemspec
4
6
  gemspec
data/Rakefile CHANGED
@@ -1,4 +1,6 @@
1
1
  #!/usr/bin/env rake
2
+ # frozen_string_literal: true
3
+
2
4
  require "bundler/gem_tasks"
3
5
  require "rake/testtask"
4
6
 
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
- $:.unshift File.expand_path(File.join(File.dirname(__FILE__), %w[.. lib]))
4
+ $LOAD_PATH.unshift File.expand_path(File.join(File.dirname(__FILE__), %w[.. lib]))
4
5
  require "eye/patch"
5
6
 
6
7
  Eye::Cli.start
@@ -1,33 +1,34 @@
1
1
  #!/usr/bin/env ruby
2
- $:.unshift File.expand_path(File.join(File.dirname(__FILE__), %w[.. lib]))
2
+ # frozen_string_literal: true
3
+
4
+ $LOAD_PATH.unshift File.expand_path(File.join(File.dirname(__FILE__), %w[.. lib]))
3
5
  require "eye/loader"
4
6
  require "optparse"
5
7
  require "eye/patch"
6
8
 
7
- options = {:debug => false}
9
+ options = { debug: false }
8
10
 
9
11
  OptionParser.new do |opts|
10
- opts.on( '-h', '--help', 'Display this screen' ) do
12
+ opts.on("-h", "--help", "Display this screen") do
11
13
  puts opts
12
14
  exit
13
15
  end
14
16
 
15
- opts.on( '-c', '--config CONFIG', 'load with config' ) do |config_path|
17
+ opts.on("-c", "--config CONFIG", "load with config") do |config_path|
16
18
  options[:config] = config_path
17
19
  end
18
20
 
19
- opts.on( '-s', '--socket SOCKET', 'start listen on socket' ) do |socket_path|
21
+ opts.on("-s", "--socket SOCKET", "start listen on socket") do |socket_path|
20
22
  options[:socket_path] = socket_path
21
23
  end
22
24
 
23
- opts.on( '-l', '--logger LOGGER', 'custom logger' ) do |logger|
25
+ opts.on("-l", "--logger LOGGER", "custom logger") do |logger|
24
26
  options[:logger] = logger
25
27
  end
26
28
 
27
- opts.on( '-d', '--debug', 'debug info to logger' ) do
29
+ opts.on("-d", "--debug", "debug info to logger") do
28
30
  options[:debug] = true
29
31
  end
30
-
31
32
  end.parse!
32
33
 
33
34
  Eye::Local.ensure_eye_dir
@@ -42,7 +43,7 @@ config = options[:config]
42
43
  config = File.expand_path(config) if config && !config.empty?
43
44
 
44
45
  if config
45
- res = server.command('load', config)
46
+ res = server.command("load", config)
46
47
  exit if res.values.any? { |r| r[:error] }
47
48
  end
48
49
 
@@ -50,8 +51,8 @@ Eye::Control.set_proc_line
50
51
 
51
52
  server.async.run
52
53
 
53
- trap("INT"){ exit }
54
- trap("USR1"){ Eye::Logger.reopen }
55
- trap("USR2"){ GC.start }
54
+ trap("INT") { exit }
55
+ trap("USR1") { Eye::Logger.reopen }
56
+ trap("USR2") { GC.start }
56
57
 
57
58
  sleep
@@ -1,5 +1,6 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path("lib", __dir__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
5
  require "eye/patch/version"
5
6
 
@@ -9,23 +10,26 @@ Gem::Specification.new do |spec|
9
10
  spec.authors = ["Andrew Horner"]
10
11
  spec.email = ["andrew@tablexi.com"]
11
12
  spec.description = "Easily load your eye configuration from a YAML file."
12
- spec.summary = %q[
13
+ spec.summary = "
13
14
  Eye::Patch abstracts out the Eye DSL to allow you to load your configuration
14
15
  from a structured YAML file, rather than relying on Eye's built-in DSL.
15
- ]
16
+ "
16
17
  spec.homepage = "https://github.com/tablexi/eye-patch"
17
18
  spec.license = "MIT"
18
19
 
19
- spec.files = `git ls-files`.split($/)
20
+ spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
20
21
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
21
22
  spec.test_files = spec.files.grep(%r{^test/})
22
23
  spec.require_paths = ["lib"]
23
24
 
24
- spec.add_dependency "eye", ">= 0.6.2"
25
+ spec.required_ruby_version = ">= 2.4.2"
26
+
25
27
  spec.add_dependency "chronic_duration"
28
+ spec.add_dependency "eye", ">= 0.6.2"
26
29
 
27
30
  spec.add_development_dependency "bundler", "~> 1.3"
28
- spec.add_development_dependency "rake"
29
- spec.add_development_dependency "mocha"
30
31
  spec.add_development_dependency "minitest"
32
+ spec.add_development_dependency "mocha"
33
+ spec.add_development_dependency "rake"
34
+ spec.add_development_dependency "rubocop"
31
35
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require "aws-sdk-core"
3
4
 
4
5
  begin
@@ -10,8 +11,11 @@ rescue LoadError
10
11
  end
11
12
 
12
13
  module Eye
14
+
13
15
  class Notify
16
+
14
17
  class AWSSDK < Eye::Notify
18
+
15
19
  param :region, String
16
20
  param :access_key_id, String
17
21
  param :secret_access_key, String
@@ -20,33 +24,35 @@ module Eye
20
24
  def execute
21
25
  options = { region: "us-east-1" } # default to us-east-1
22
26
  options[:region] = region if region
23
- if access_key_id && secret_access_key
24
- options[:credentials] = Aws::Credentials.new(access_key_id, secret_access_key)
25
- end
27
+ options[:credentials] = Aws::Credentials.new(access_key_id, secret_access_key) if access_key_id && secret_access_key
26
28
  client = Aws::SES::Client.new(options)
27
29
  client.send_email(message)
28
30
  end
29
31
 
30
32
  def message
31
- { source: from,
33
+ {
34
+ source: from,
32
35
  destination: {
33
- to_addresses: [contact]
36
+ to_addresses: [contact],
34
37
  },
35
38
  message: {
36
39
  subject: {
37
- data: message_subject
40
+ data: message_subject,
38
41
  },
39
42
  body: {
40
43
  text: {
41
- data: message_body
44
+ data: message_body,
42
45
  },
43
46
  html: {
44
- data: message_body
45
- }
46
- }
47
- }
47
+ data: message_body,
48
+ },
49
+ },
50
+ },
48
51
  }
49
52
  end
53
+
50
54
  end
55
+
51
56
  end
57
+
52
58
  end
@@ -3,8 +3,11 @@
3
3
  require "dogapi"
4
4
 
5
5
  module Eye
6
+
6
7
  class Notify
8
+
7
9
  class DataDog < Eye::Notify
10
+
8
11
  param :aggregation_key, String
9
12
  param :alert_type, String
10
13
  param :api_key, String, true
@@ -16,7 +19,7 @@ module Eye
16
19
  alert_type: "error",
17
20
  aggregation_key: msg_host + msg_full_name,
18
21
  source_type: "None",
19
- tags: ["eye"]
22
+ tags: ["eye"],
20
23
  }
21
24
 
22
25
  options[:alert_type] = alert_type if alert_type
@@ -24,20 +27,21 @@ module Eye
24
27
  options[:source_type] = source_type if source_type
25
28
  options[:tags] = tags if tags
26
29
 
27
- dog = Dogapi::Client.new(api_key)
28
-
29
- dog.emit_event(
30
- Dogapi::Event.new(
31
- message_body,
32
- aggregation_key: options[:aggregation_key],
33
- alert_type: options[:alert_type],
34
- msg_title: message_subject,
35
- host: msg_host,
36
- source_type: options[:source_type],
37
- tags: options[:tags]
38
- )
30
+ event = Dogapi::Event.new(
31
+ message_body,
32
+ aggregation_key: options[:aggregation_key],
33
+ alert_type: options[:alert_type],
34
+ msg_title: message_subject,
35
+ host: msg_host,
36
+ source_type: options[:source_type],
37
+ tags: options[:tags],
39
38
  )
39
+
40
+ Dogapi::Client.new(api_key).emit_event(event)
40
41
  end
42
+
41
43
  end
44
+
42
45
  end
46
+
43
47
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require "aws/ses"
3
4
 
4
5
  class Eye::Notify::SES < Eye::Notify
@@ -9,14 +10,18 @@ class Eye::Notify::SES < Eye::Notify
9
10
 
10
11
  def execute
11
12
  AWS::SES::Base.new(
12
- access_key_id: access_key_id,
13
- secret_access_key: secret_access_key ).send_email(message)
13
+ access_key_id: access_key_id,
14
+ secret_access_key: secret_access_key,
15
+ ).send_email(message)
14
16
  end
15
17
 
16
18
  def message
17
- { to: contact,
19
+ {
20
+ to: contact,
18
21
  from: from,
19
22
  subject: message_subject,
20
- text_body: message_body }
23
+ text_body: message_body,
24
+ }
21
25
  end
26
+
22
27
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "eye"
2
4
  require "eye/patch/overrides"
3
5
 
@@ -6,11 +8,15 @@ Eye::Notify::TYPES[:aws_sdk] = "AWSSDK"
6
8
  Eye::Notify::TYPES[:datadog] = "DataDog"
7
9
 
8
10
  module Eye
11
+
9
12
  class Notify
13
+
10
14
  autoload :SES, "eye/notify/ses"
11
15
  autoload :AWSSDK, "eye/notify/awssdk"
12
16
  autoload :DataDog, "eye/notify/datadog"
17
+
13
18
  end
19
+
14
20
  end
15
21
 
16
22
  module Eye::Patch
@@ -25,7 +31,8 @@ module Eye::Patch
25
31
 
26
32
  config = ::Eye::Config.new(
27
33
  Config.new(settings),
28
- Application.new(settings))
34
+ Application.new(settings),
35
+ )
29
36
  config.validate!
30
37
 
31
38
  config.applications.values.each do |application|
@@ -35,4 +42,5 @@ module Eye::Patch
35
42
 
36
43
  config
37
44
  end
45
+
38
46
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative "group_set"
2
4
  require_relative "option_set"
3
5
 
@@ -25,7 +27,8 @@ module Eye::Patch
25
27
  name: @settings[:name],
26
28
  notify: notifications,
27
29
  triggers: triggers,
28
- checks: checks )
30
+ checks: checks,
31
+ )
29
32
  end
30
33
 
31
34
  def parse_processes
@@ -45,5 +48,7 @@ module Eye::Patch
45
48
  def checks
46
49
  OptionSet.new(Eye::Checker, @settings[:checks])
47
50
  end
51
+
48
52
  end
53
+
49
54
  end
@@ -1,5 +1,6 @@
1
- Capistrano::Configuration.instance.load do
1
+ # frozen_string_literal: true
2
2
 
3
+ Capistrano::Configuration.instance.load do
3
4
  _cset(:eye_default_hooks) { true }
4
5
  _cset(:eye_config) { "config/eye.yml" }
5
6
  _cset(:eye_bin) { "bundle exec eye-patch" }
@@ -12,7 +13,6 @@ Capistrano::Configuration.instance.load do
12
13
  end
13
14
 
14
15
  namespace :eye do
15
-
16
16
  desc "Start eye with the desired configuration file"
17
17
  task :load_config, roles: -> { fetch(:eye_roles) } do
18
18
  run "cd #{current_path} && #{fetch(:eye_bin)} quit"
@@ -1,5 +1,6 @@
1
- namespace :load do
1
+ # frozen_string_literal: true
2
2
 
3
+ namespace :load do
3
4
  task :defaults do
4
5
  set :eye_config, -> { "config/eye.yml" }
5
6
  set :eye_bin, -> { "eye-patch" }
@@ -13,7 +14,6 @@ namespace :load do
13
14
  end
14
15
 
15
16
  namespace :eye do
16
-
17
17
  desc "Start eye with the desired configuration file"
18
18
  task :load_config do
19
19
  on roles(fetch(:eye_roles)) do
@@ -1,8 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Eye::Patch::Config < Hash
2
4
 
3
5
  def initialize(settings)
4
6
  super()
5
- self.merge!(parse(settings))
7
+ merge!(parse(settings))
6
8
  end
7
9
 
8
10
  private
@@ -29,7 +31,9 @@ class Eye::Patch::Config < Hash
29
31
  name: notify[:name].to_s,
30
32
  type: notify[:type].to_sym,
31
33
  contact: notify[:contact].to_s,
32
- opts: {} }
34
+ opts: {},
35
+ }
33
36
  end
34
37
  end
38
+
35
39
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative "process_set"
2
4
 
3
5
  module Eye::Patch
@@ -7,7 +9,7 @@ module Eye::Patch
7
9
  def initialize(application, processes)
8
10
  @application = application
9
11
 
10
- Array(processes).group_by{ |item| item[:group] }.each do |group_name, items|
12
+ Array(processes).group_by { |item| item[:group] }.each do |group_name, items|
11
13
  name = group_name || "__default__"
12
14
  parse_group(name, items)
13
15
  end
@@ -18,9 +20,12 @@ module Eye::Patch
18
20
  def parse_group(name, processes)
19
21
  self[name] = @application.merge(
20
22
  name: name,
21
- application: @application[:name])
23
+ application: @application[:name],
24
+ )
22
25
 
23
26
  self[name][:processes] = ProcessSet.new(self[name], processes)
24
27
  end
28
+
25
29
  end
30
+
26
31
  end
@@ -1,4 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Eye::Patch
4
+
2
5
  class OptionSet < Hash
3
6
 
4
7
  def initialize(option_class, options)
@@ -7,5 +10,7 @@ module Eye::Patch
7
10
  self[option_data[:name]] = option[:config].merge(type: option_data[:type])
8
11
  end
9
12
  end
13
+
10
14
  end
15
+
11
16
  end
@@ -1,62 +1,61 @@
1
+ # frozen_string_literal: true
2
+
1
3
  Eye::Cli.class_eval do
2
4
  private
3
5
 
4
6
  def loader_path
5
7
  filename = File.expand_path(File.join(File.dirname(__FILE__), %w[.. .. .. bin eye-patch-loader]))
6
- File.exists?(filename) ? filename : nil
8
+ File.exist?(filename) ? filename : nil
7
9
  end
8
10
  end
9
11
 
10
12
  require "eye/utils/mini_active_support"
11
13
  Eye::Process.class_eval do
12
-
13
14
  def daemonize_process
14
- time_before = Time.now
15
15
  res = Eye::System.daemonize(self[:start_command], config)
16
- start_time = Time.now - time_before
17
16
 
18
17
  info "daemonizing: `#{self[:start_command]}` with start_grace: #{self[:start_grace].to_f}s, env: #{self[:environment].inspect}, working_dir: #{self[:working_dir]}, <#{res[:pid]}>"
19
18
 
20
19
  if res[:error]
21
-
22
- if res[:error].message == 'Permission denied - open'
20
+ if res[:error].message == "Permission denied - open"
23
21
  error "daemonize failed with #{res[:error].inspect}; make sure #{[self[:stdout], self[:stderr]]} are writable"
24
22
  else
25
23
  error "daemonize failed with #{res[:error].inspect}"
26
24
  end
27
25
 
28
- return {:error => res[:error].inspect}
26
+ return { error: res[:error].inspect }
29
27
  end
30
28
 
31
29
  self.pid = res[:pid]
32
30
 
33
- unless self.pid
34
- error 'no pid was returned'
35
- return {:error => :empty_pid}
31
+ unless pid
32
+ error "no pid was returned"
33
+ return { error: :empty_pid }
36
34
  end
37
35
 
38
36
  sleep_grace(:start_grace)
39
37
 
40
38
  unless process_really_running?
41
- error "process <#{self.pid}> not found, it may have crashed (#{check_logs_str})"
42
- return {:error => :not_really_running}
39
+ error "process <#{pid}> not found, it may have crashed (#{check_logs_str})"
40
+ return { error: :not_really_running }
43
41
  end
44
42
 
45
43
  if !self[:smart_pid] && !failsafe_save_pid
46
- error "expected to manage pidfile for process <#{self.pid}>; pidfile is unwritable"
47
- return {:error => :cant_write_pid}
44
+ error "expected to manage pidfile for process <#{pid}>; pidfile is unwritable"
45
+ return { error: :cant_write_pid }
48
46
  end
49
47
 
50
48
  res
51
49
  end
52
50
 
53
51
  def control_pid?
54
- !!self[:daemonize] && !self[:smart_pid]
52
+ !!self[:daemonize] && !self[:smart_pid] # rubocop:disable Style/DoubleNegation
55
53
  end
56
54
  end
57
55
 
58
56
  Eye::System.class_eval do
59
57
  class << self
58
+
60
59
  alias_method :daemonize_without_hook, :daemonize
61
60
  alias_method :exec_without_hook, :exec
62
61
 
@@ -75,11 +74,12 @@ Eye::System.class_eval do
75
74
  def spawn_options(config = {})
76
75
  options = {
77
76
  pgroup: true,
78
- chdir: config[:working_dir] || '/',
79
- close_others: !config[:preserve_fds] }
77
+ chdir: config[:working_dir] || "/",
78
+ close_others: !config[:preserve_fds],
79
+ }
80
80
 
81
- options[:out] = [config[:stdout], 'a'] if config[:stdout]
82
- options[:err] = [config[:stderr], 'a'] if config[:stderr]
81
+ options[:out] = [config[:stdout], "a"] if config[:stdout]
82
+ options[:err] = [config[:stderr], "a"] if config[:stderr]
83
83
  options[:in] = config[:stdin] if config[:stdin]
84
84
  options[:umask] = config[:umask] if config[:umask]
85
85
 
@@ -90,17 +90,17 @@ Eye::System.class_eval do
90
90
 
91
91
  options
92
92
  end
93
+
93
94
  end
94
95
  end
95
96
 
96
97
  Eye::Controller.class_eval do
97
-
98
98
  def invoke_spawn_callback
99
99
  debug "Attempting before_spawn hook"
100
- if respond_to?(:before_spawn)
101
- debug "Invoking before_spawn hook"
102
- before_spawn
103
- end
100
+ return unless respond_to?(:before_spawn)
101
+
102
+ debug "Invoking before_spawn hook"
103
+ before_spawn
104
104
  end
105
105
 
106
106
  private
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Eye::Patch
2
4
 
3
5
  class ProcessSet < Hash
@@ -19,7 +21,8 @@ module Eye::Patch
19
21
  parse_single_process(
20
22
  process[:name],
21
23
  process[:config],
22
- process_monitors(process))
24
+ process_monitors(process),
25
+ )
23
26
  end
24
27
  end
25
28
 
@@ -29,7 +32,8 @@ module Eye::Patch
29
32
  parse_single_process(
30
33
  name,
31
34
  indexed_config(process[:config], index),
32
- process_monitors(process))
35
+ process_monitors(process),
36
+ )
33
37
  end
34
38
  end
35
39
 
@@ -47,7 +51,8 @@ module Eye::Patch
47
51
 
48
52
  monitor_options = OptionSet.new(
49
53
  Eye::Checker,
50
- config[:monitor_children][:checks])
54
+ config[:monitor_children][:checks],
55
+ )
51
56
 
52
57
  self[name][:monitor_children][:checks] = monitor_options
53
58
  end
@@ -59,8 +64,12 @@ module Eye::Patch
59
64
  end
60
65
 
61
66
  def process_monitors(config)
62
- { triggers: OptionSet.new(Eye::Trigger, config[:triggers]),
63
- checks: OptionSet.new(Eye::Checker, config[:checks]) }
67
+ {
68
+ triggers: OptionSet.new(Eye::Trigger, config[:triggers]),
69
+ checks: OptionSet.new(Eye::Checker, config[:checks]),
70
+ }
64
71
  end
72
+
65
73
  end
74
+
66
75
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "erb"
2
4
  require "forwardable"
3
5
  require_relative "value_parser"
@@ -5,6 +7,7 @@ require_relative "value_parser"
5
7
  module Eye::Patch
6
8
 
7
9
  class Settings
10
+
8
11
  extend Forwardable
9
12
  def_delegators :parsed, :[], :fetch
10
13
 
@@ -13,9 +16,9 @@ module Eye::Patch
13
16
  erb = ERB.new(file.read)
14
17
  erb.filename = file.path
15
18
 
16
- @settings = YAML.load(erb.result)
19
+ @settings = YAML.safe_load(erb.result)
17
20
  ensure
18
- file.close unless file.nil?
21
+ file&.close
19
22
  end
20
23
 
21
24
  private
@@ -38,5 +41,7 @@ module Eye::Patch
38
41
  item
39
42
  end
40
43
  end
44
+
41
45
  end
46
+
42
47
  end
@@ -1,14 +1,17 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "chronic_duration"
2
4
 
3
5
  module Eye::Patch
4
6
 
5
7
  class ValueParser
6
8
 
7
- TIME_MATCHER = /\s(?<duration>(?:week|day|hour|minute|second)s?)(?:\s|\Z)/.freeze
8
- SIZE_MATCHER = /\s(?<size>(?:tera|giga|mega|kilo)?bytes?)(?:\s|\Z)/.freeze
9
- MATCHERS = {
9
+ TIME_MATCHER = /\s(?<duration>(?:week|day|hour|minute|second)s?)(?:\s|\Z)/
10
+ SIZE_MATCHER = /\s(?<size>(?:tera|giga|mega|kilo)?bytes?)(?:\s|\Z)/
11
+ MATCHERS = {
10
12
  time: TIME_MATCHER,
11
- size: SIZE_MATCHER }.freeze
13
+ size: SIZE_MATCHER,
14
+ }.freeze
12
15
 
13
16
  def self.parse(value)
14
17
  return value unless value.is_a?(String)
@@ -20,8 +23,6 @@ module Eye::Patch
20
23
  result || value
21
24
  end
22
25
 
23
- private
24
-
25
26
  def self.parse_time(value)
26
27
  ChronicDuration.parse(value)
27
28
  end
@@ -30,5 +31,7 @@ module Eye::Patch
30
31
  unit = value.match(SIZE_MATCHER)[:size]
31
32
  value.gsub(/[^\d.]/, "").to_f.send(unit)
32
33
  end
34
+
33
35
  end
36
+
34
37
  end
@@ -1,5 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Eye
4
+
2
5
  module Patch
3
- VERSION = "0.5.1"
6
+
7
+ VERSION = "1.0.0"
8
+
4
9
  end
10
+
5
11
  end
@@ -1,8 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative "../../../test_helper"
2
4
  require "tempfile"
3
5
 
4
6
  module Eye
7
+
5
8
  module Patch
9
+
6
10
  describe Settings do
7
11
  it "evaluates the yaml as ERB" do
8
12
  file = Tempfile.new("yaml")
@@ -22,5 +26,7 @@ module Eye
22
26
  )
23
27
  end
24
28
  end
29
+
25
30
  end
31
+
26
32
  end
@@ -1,7 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative "../../../test_helper"
2
4
 
3
5
  describe Eye::Patch::ValueParser do
4
-
5
6
  it "parses time values" do
6
7
  assert_equal 2.weeks, Eye::Patch::ValueParser.parse("2 weeks")
7
8
  assert_equal 1.5.hours, Eye::Patch::ValueParser.parse("1.5 hours")
@@ -1,7 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative "../../../test_helper"
2
4
 
3
5
  describe Eye::Patch do
4
-
5
6
  it "defines a version" do
6
7
  assert Eye::Patch::VERSION
7
8
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative "../../test_helper"
2
4
 
3
5
  describe Eye::Patch do
@@ -8,7 +10,7 @@ describe Eye::Patch do
8
10
  describe ".parse" do
9
11
  before do
10
12
  @fixture = File.expand_path(File.join(File.dirname(__FILE__), %w[.. .. fixtures test.yml]))
11
- @original = YAML.load(File.open(@fixture))
13
+ @original = YAML.safe_load(File.open(@fixture))
12
14
  @parsed = Eye::Patch.parse(@fixture)
13
15
 
14
16
  @settings = @parsed.settings
@@ -37,7 +39,7 @@ describe Eye::Patch do
37
39
  trigger = @original["triggers"].first
38
40
  parsed_trigger = @application[:triggers][trigger["name"].to_sym]
39
41
 
40
- %w(times within).each do |setting|
42
+ %w[times within].each do |setting|
41
43
  assert_equal Eye::Patch::ValueParser.parse(trigger["config"][setting]), parsed_trigger[setting.to_sym]
42
44
  end
43
45
  end
@@ -46,7 +48,7 @@ describe Eye::Patch do
46
48
  check = @original["checks"].first
47
49
  parsed_check = @application[:checks][check["name"].to_sym]
48
50
 
49
- %w(times every below).each do |setting|
51
+ %w[times every below].each do |setting|
50
52
  assert_equal Eye::Patch::ValueParser.parse(check["config"][setting]), parsed_check[setting.to_sym]
51
53
  end
52
54
  end
@@ -66,9 +68,9 @@ describe Eye::Patch do
66
68
  end
67
69
 
68
70
  it "creates process clusters" do
69
- process = @original["processes"].detect { |process| process["count"] }
71
+ process = @original["processes"].detect { |p| p["count"] }
70
72
  process["count"].times do |index|
71
- name = "#{process["name"]}-#{index}"
73
+ name = "#{process['name']}-#{index}"
72
74
  parsed_process = @application[:groups][process["group"]][:processes][name]
73
75
 
74
76
  assert_equal process["group"], parsed_process[:group]
@@ -84,10 +86,11 @@ describe Eye::Patch do
84
86
  check = process_config["config"]["monitor_children"]["checks"].first
85
87
  parsed_check = process[:monitor_children][:checks][check["name"].to_sym]
86
88
 
87
- %w(times every below).each do |setting|
89
+ %w[times every below].each do |setting|
88
90
  assert_equal(
89
91
  Eye::Patch::ValueParser.parse(check["config"][setting]),
90
- parsed_check[setting.to_sym])
92
+ parsed_check[setting.to_sym],
93
+ )
91
94
  end
92
95
  end
93
96
 
@@ -97,7 +100,7 @@ describe Eye::Patch do
97
100
  end
98
101
 
99
102
  it "sets :stderr and :stdout options for each process from passed :stdall" do
100
- process = @original["processes"].reject { |process| process["group"] }.first
103
+ process = @original["processes"].reject { |p| p["group"] }.first
101
104
  parsed_process = @application[:groups]["__default__"][:processes].values.first
102
105
 
103
106
  assert_equal process["config"]["stdall"], parsed_process[:stdout]
@@ -108,7 +111,7 @@ describe Eye::Patch do
108
111
  describe ".parse with per-process overrides" do
109
112
  before do
110
113
  @fixture = File.expand_path(File.join(File.dirname(__FILE__), %w[.. .. fixtures overrides.yml]))
111
- @original = YAML.load(File.open(@fixture))
114
+ @original = YAML.safe_load(File.open(@fixture))
112
115
  @parsed = Eye::Patch.parse(@fixture)
113
116
 
114
117
  @settings = @parsed.settings
@@ -121,7 +124,7 @@ describe Eye::Patch do
121
124
  trigger = @original["processes"].detect { |p| p["name"] == process[:name] }["triggers"].first
122
125
  parsed_trigger = process[:triggers][trigger["name"].to_sym]
123
126
 
124
- %w(times within).each do |setting|
127
+ %w[times within].each do |setting|
125
128
  assert_equal Eye::Patch::ValueParser.parse(trigger["config"][setting]), parsed_trigger[setting.to_sym]
126
129
  end
127
130
  end
@@ -131,7 +134,7 @@ describe Eye::Patch do
131
134
  check = @original["processes"].detect { |p| p["name"] == process[:name] }["checks"].first
132
135
  parsed_check = process[:checks][check["name"].to_sym]
133
136
 
134
- %w(times every below).each do |setting|
137
+ %w[times every below].each do |setting|
135
138
  assert_equal Eye::Patch::ValueParser.parse(check["config"][setting]), parsed_check[setting.to_sym]
136
139
  end
137
140
  end
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "minitest/autorun"
2
4
  require "minitest/unit"
3
5
  require "mocha/mini_test"
4
6
 
5
- require File.expand_path("../../lib/eye/patch.rb", __FILE__)
7
+ require File.expand_path("../lib/eye/patch.rb", __dir__)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eye-patch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Horner
@@ -11,33 +11,33 @@ cert_chain: []
11
11
  date: 2018-04-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: eye
14
+ name: chronic_duration
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 0.6.2
19
+ version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 0.6.2
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: chronic_duration
28
+ name: eye
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: 0.6.2
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: 0.6.2
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -53,7 +53,7 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '1.3'
55
55
  - !ruby/object:Gem::Dependency
56
- name: rake
56
+ name: minitest
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - ">="
@@ -81,7 +81,21 @@ dependencies:
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
- name: minitest
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop
85
99
  requirement: !ruby/object:Gem::Requirement
86
100
  requirements:
87
101
  - - ">="
@@ -104,6 +118,9 @@ extensions: []
104
118
  extra_rdoc_files: []
105
119
  files:
106
120
  - ".gitignore"
121
+ - ".hound.yml"
122
+ - ".rubocop.yml"
123
+ - ".rubocop_todo.yml"
107
124
  - Gemfile
108
125
  - LICENSE.txt
109
126
  - README.md
@@ -150,7 +167,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
150
167
  requirements:
151
168
  - - ">="
152
169
  - !ruby/object:Gem::Version
153
- version: '0'
170
+ version: 2.4.2
154
171
  required_rubygems_version: !ruby/object:Gem::Requirement
155
172
  requirements:
156
173
  - - ">="
@@ -158,7 +175,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
158
175
  version: '0'
159
176
  requirements: []
160
177
  rubyforge_project:
161
- rubygems_version: 2.4.5.1
178
+ rubygems_version: 2.6.13
162
179
  signing_key:
163
180
  specification_version: 4
164
181
  summary: Eye::Patch abstracts out the Eye DSL to allow you to load your configuration