Class: Launchr::Commands
- Inherits:
-
Object
- Object
- Launchr::Commands
- Defined in:
- lib/launchr/commands.rb
Overview
This objects manages all of the commands to be executed by an instance of Application
Constant Summary collapse
- PriorityOrder =
[]
Instance Method Summary collapse
- #clean(value) ⇒ Object
- #cmd(cmd, services) ⇒ Object
- #default(value) ⇒ Object
- #info(services) ⇒ Object
- #preflight_checks ⇒ Object
- #restart(services) ⇒ Object
-
#run ⇒ Object
To be executed once.
- #start(services) ⇒ Object
- #stop(services) ⇒ Object
- #version(value) ⇒ Object
Instance Method Details
#clean(value) ⇒ Object
92 93 94 95 96 |
# File 'lib/launchr/commands.rb', line 92 def clean value puts "Cleaning launchd services..." Launchr::Service.cleanup puts "Done." end |
#cmd(cmd, services) ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/launchr/commands.rb', line 37 def cmd cmd, services Launchr::Service.cleanup services.each do |svc| service = Launchr::Service.find(svc) service.send(cmd) end end |
#default(value) ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/launchr/commands.rb', line 98 def default value if Launchr.config[:args][:boot] puts "Setting default to --boot" Launchr::Path.launchr_default_boot.touch Launchr::Path.chown_down Launchr::Path.launchr_default_boot Launchr.config[:boot] = true else puts "Setting default to --user" if Launchr::Path.launchr_default_boot.exist? Launchr::Path.launchr_default_boot.unlink end Launchr.config[:boot] = nil end end |
#info(services) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/launchr/commands.rb', line 60 def info services Launchr::Service.cleanup if services.empty? level = Launchr.config[:boot] ? "--boot" : "--user" puts "Launchd default target: #{level}" puts "" services = Launchr::Service.find_all if services.empty? puts "No launchd services installed" else puts Launchr::Service.header end services.each do |svc| svc.send :info end else puts Launchr::Service.header services.map! do |svc| Launchr::Service.find(svc) end services.uniq! services.each do |svc| svc.send :info end end puts "" end |
#preflight_checks ⇒ Object
11 12 13 14 15 16 |
# File 'lib/launchr/commands.rb', line 11 def preflight_checks unless Launchr::Path.homebrew_prefix puts "Preflight checks..." raise "No homebrew prefix was found" end end |
#restart(services) ⇒ Object
55 56 57 58 |
# File 'lib/launchr/commands.rb', line 55 def restart services puts "Restarting launchd services..." cmd :restart, services end |
#run ⇒ Object
To be executed once. Branches out to subroutines, and handles the order-of-execution of those main subrountines.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/launchr/commands.rb', line 20 def run preflight_checks PriorityOrder.each do |command| if self.class.method_defined?(command) && ! Launchr.config[:args][command].nil? self.send command, Launchr.config[:args][command] end end left_to_execute = Launchr.config[:args].keys - PriorityOrder Launchr.config[:args].each do |command, value| if left_to_execute.include?(command) && self.class.method_defined?(command) && ! value.nil? self.send command, Launchr.config[:args][command] end end end |
#start(services) ⇒ Object
45 46 47 48 |
# File 'lib/launchr/commands.rb', line 45 def start services puts "Starting launchd services..." cmd :start, services end |
#stop(services) ⇒ Object
50 51 52 53 |
# File 'lib/launchr/commands.rb', line 50 def stop services puts "Stopping launchd services..." cmd :stop, services end |