potluck 0.0.2 → 0.0.3

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
  SHA256:
3
- metadata.gz: 92a30f07b5c14817cd0f61c62cf3ea56dce665498b022321348d9d9fe99605b7
4
- data.tar.gz: f7166d54bb8c382714c6503569a4d4416c9db432575de49ee763402f42520310
3
+ metadata.gz: 8be6daeb322e6bd8b0a99cc25d8fb5a2a805b6354c620439c7a22ecdd289e189
4
+ data.tar.gz: 852bafb9263287a210c98c26b99e4a3e9358fd490c8b71910ecce2be16b980d7
5
5
  SHA512:
6
- metadata.gz: 76407292ddfa7135cfe05728a1b860237ee6914fed9ebc5477960cf607174515d81058d2b0f23e1d7bab525a977593430d8830394083f2326f2b30d41b04bb02
7
- data.tar.gz: ad0a00525b1146bf8587defa8fd96e2a1bd7066dd92961bd37d74a53283da22aaaab9bf434a848bf92d375756d2c204e96229e52c3c2d5fa4725c8eaf67b1b37
6
+ metadata.gz: 84d60ae064035c6657aa601a622e1f65e38fc915162cbb6287a40b2309d6736c17881f552abbf7daef2c159961a010aed4a61d5cc8111c7d7c4865925c058a81
7
+ data.tar.gz: 2659df968b31e9851addaa50369c92c1e143ea118e3837ae493c728ea6050f1f9efb34a350f238cb788d847a3a77632f5777b9f607e3cf00b391effec9c34c3f
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.2
1
+ 0.0.3
data/lib/potluck/dish.rb CHANGED
@@ -10,14 +10,54 @@ module Potluck
10
10
 
11
11
  LAUNCHCTL_ERROR_REGEX = /^-|\t[^0]\t/.freeze
12
12
 
13
- def initialize(logger: nil, is_local: nil)
13
+ def initialize(logger: nil, manage: launchctl?, is_local: (is_local_omitted = true; nil))
14
14
  @logger = logger
15
+ @manage = !!manage
16
+
17
+ if manage.kind_of?(Hash)
18
+ @status_command = manage[:status]
19
+ @status_error_regex = manage[:status_error_regex]
20
+ @start_command = manage[:start]
21
+ @stop_command = manage[:stop]
22
+ elsif manage
23
+ ensure_launchctl!
24
+ end
25
+
26
+ # DEPRECATED. Use `manage` instead.
15
27
  @is_local = is_local.nil? ? (IS_MACOS && ensure_launchctl! rescue false) : is_local
28
+
29
+ unless is_local_omitted
30
+ warn("#{self.class}#initialize `is_local` parameter is deprecated and will be removed soon (use "\
31
+ '`manage` instead)')
32
+ end
33
+ end
34
+
35
+ def manage?
36
+ @manage
37
+ end
38
+
39
+ def launchctl?
40
+ defined?(@@launchctl) ? @@launchctl : (@@launchctl = `which launchctl 2>&1` && $? == 0)
16
41
  end
17
42
 
18
43
  def ensure_launchctl!
19
- @@launchctl = `which launchctl` && $? == 0 unless defined?(@@launchctl)
20
- @@launchctl || raise("Cannot manage #{self.class.to_s.split('::').last}: launchctl not found")
44
+ launchctl? || raise("Cannot manage #{self.class.to_s.split('::').last}: launchctl not found")
45
+ end
46
+
47
+ def status_command
48
+ @status_command || "launchctl list 2>&1 | grep #{SERVICE_PREFIX}#{self.class.service_name}"
49
+ end
50
+
51
+ def status_error_regex
52
+ @status_error_regex || LAUNCHCTL_ERROR_REGEX
53
+ end
54
+
55
+ def start_command
56
+ @start_command || "launchctl bootstrap gui/#{Process.uid} #{self.class.plist_path}"
57
+ end
58
+
59
+ def stop_command
60
+ @stop_command || "launchctl bootout gui/#{Process.uid}/#{self.class.launchctl_name}"
21
61
  end
22
62
 
23
63
  def ensure_plist
@@ -25,13 +65,13 @@ module Potluck
25
65
  end
26
66
 
27
67
  def status
28
- return :inactive unless @is_local && ensure_launchctl!
68
+ return :inactive unless manage?
29
69
 
30
- output = `launchctl list 2>&1 | grep #{SERVICE_PREFIX}#{self.class.service_name}`
70
+ output = `#{status_command}`
31
71
 
32
72
  if $? != 0
33
73
  :inactive
34
- elsif output[LAUNCHCTL_ERROR_REGEX]
74
+ elsif status_error_regex && output[status_error_regex]
35
75
  :error
36
76
  else
37
77
  :active
@@ -39,16 +79,16 @@ module Potluck
39
79
  end
40
80
 
41
81
  def start
42
- return unless @is_local && ensure_launchctl!
82
+ return unless manage?
43
83
 
44
- ensure_plist
84
+ ensure_plist unless @start_command
45
85
 
46
86
  case status
47
87
  when :error then stop
48
88
  when :active then return
49
89
  end
50
90
 
51
- run("launchctl bootstrap gui/#{Process.uid} #{self.class.plist_path}")
91
+ run(start_command)
52
92
  wait { status == :inactive }
53
93
 
54
94
  raise("Could not start #{self.class.pretty_name}") if status != :active
@@ -57,9 +97,9 @@ module Potluck
57
97
  end
58
98
 
59
99
  def stop
60
- return unless @is_local && ensure_launchctl! && status != :inactive
100
+ return unless manage? && status != :inactive
61
101
 
62
- run("launchctl bootout gui/#{Process.uid}/#{self.class.launchctl_name}")
102
+ run(stop_command)
63
103
  wait { status != :inactive }
64
104
 
65
105
  raise("Could not stop #{self.class.pretty_name}") if status != :inactive
@@ -68,7 +108,7 @@ module Potluck
68
108
  end
69
109
 
70
110
  def restart
71
- return unless @is_local && ensure_launchctl!
111
+ return unless manage?
72
112
 
73
113
  stop
74
114
  start
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Potluck
4
- VERSION = '0.0.2'
4
+ VERSION = '0.0.3'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: potluck
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nate Pickens
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-12-13 00:00:00.000000000 Z
11
+ date: 2021-12-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler