Class: Henchman::Templates

Inherits:
Object
  • Object
show all
Defined in:
lib/templates.rb

Class Method Summary collapse

Class Method Details

.cacheObject



85
86
87
88
89
90
91
92
93
# File 'lib/templates.rb', line 85

def self.cache
  {
    :ignore => {
                 :artist   => Hash.new(0),
                 :playlist => Hash.new(0)
               },
    :history => Hash.new
  }
end

.configObject



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/templates.rb', line 68

def self.config
  {
    :dropbox => {:key => '',
                 :secret => '',
                 :access_token => '',
                 :user_id => '',
                 :root     => ''},
    :root => '',
    :poll_itunes_open => 10,
    :poll_track => 3,
    :reprompt_timeout => 300,
    :delimiter => '|~|',
    :delimiter_major => '|?|',
    :file_extensions => ['mp3', 'm4a']
  }
end

.plist_cleanObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/templates.rb', line 27

def self.plist_clean
  "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"\
  "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" "\
  "\"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n"\
  "<plist version=\"1.0\">\n"\
  "<dict>\n"\
  "\t<key>Label</key>\n"\
  "\t<string>henchman_clean</string>\n"\
  "\t<key>ProgramArguments</key>\n"\
  "\t<array>\n"\
  "\t\t<string>#{File.expand_path('~/.henchman/clean.sh')}</string>\n"\
  "\t</array>\n"\
  "\t<key>StartCalendarInterval</key>\n"\
  "\t<array>\n"\
  "\t<!-- Run twice a day. At 12:00 AM and at 12:00 PM -->\n"\
  "\t\t<dict>\n"\
  "\t\t\t<key>Hour</key>\n"\
  "\t\t\t<integer>00</integer>\n"\
  "\t\t\t<key>Minute</key>\n"\
  "\t\t\t<integer>00</integer>\n"\
  "\t\t</dict>\n"\
  "\t\t<dict>\n"\
  "\t\t\t<key>Hour</key>\n"\
  "\t\t\t<integer>12</integer>\n"\
  "\t\t\t<key>Minute</key>\n"\
  "\t\t\t<integer>00</integer>\n"\
  "\t\t</dict>\n"\
  "\t</array>\n"\
  "\t<key>StandardOutPath</key>\n"\
  "\t<string>#{File.expand_path('~/.henchman/stdout.log')}</string>\n"\
  "\t<key>StandardErrorPath</key>\n"\
  "\t<string>#{File.expand_path('~/.henchman/stderr.log')}</string>\n"\
  "</dict>\n"\
  "</plist>"
end

.plist_mainObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/templates.rb', line 3

def self.plist_main
  config = YAML.load_file(File.expand_path('~/.henchman/config'))

  "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"\
  "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" "\
  "\"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n"\
  "<plist version=\"1.0\">\n"\
  "<dict>\n"\
  "\t<key>Label</key>\n"\
  "\t<string>henchman</string>\n"\
  "\t<key>ProgramArguments</key>\n"\
  "\t<array>\n"\
  "\t\t<string>#{File.expand_path('~/.henchman/run.sh')}</string>\n"\
  "\t</array>\n"\
  "\t<key>StartInterval</key>\n"\
  "\t<integer>#{config[:poll_itunes_open]}</integer>\n"\
  "\t<key>StandardOutPath</key>\n"\
  "\t<string>#{File.expand_path('~/.henchman/stdout.log')}</string>\n"\
  "\t<key>StandardErrorPath</key>\n"\
  "\t<string>#{File.expand_path('~/.henchman/stderr.log')}</string>\n"\
  "</dict>\n"\
  "</plist>"
end

.shell_script(command, args = []) ⇒ Object



63
64
65
66
# File 'lib/templates.rb', line 63

def self.shell_script command, args = []
  "#!/bin/sh\n"\
  "#{`which henchman`.chomp} #{command} #{args.join(' ')}"
end