Class: Trackchange::Exec
- Inherits:
-
Struct
- Object
- Struct
- Trackchange::Exec
- Defined in:
- lib/trackchange/exec.rb
Constant Summary collapse
- CRON_LINE =
'0 7 * * * trackchange probe >/dev/null'
Instance Attribute Summary collapse
-
#args ⇒ Object
Returns the value of attribute args.
Class Method Summary collapse
Instance Method Summary collapse
- #add ⇒ Object
- #email ⇒ Object
- #install ⇒ Object
- #list ⇒ Object
-
#probe ⇒ Object
commands.
- #remove ⇒ Object
- #rss ⇒ Object
- #run ⇒ Object
- #slack ⇒ Object
-
#test ⇒ Object
TODO refactor to make remove code duplication.
- #uninstall ⇒ Object
Instance Attribute Details
#args ⇒ Object
Returns the value of attribute args
8 9 10 |
# File 'lib/trackchange/exec.rb', line 8 def args @args end |
Class Method Details
.run(args) ⇒ Object
13 14 15 |
# File 'lib/trackchange/exec.rb', line 13 def run(args) new(args).run end |
Instance Method Details
#add ⇒ Object
47 48 49 50 51 52 53 54 55 |
# File 'lib/trackchange/exec.rb', line 47 def add config.sites ||= [] config.sites |= [ { url: args.first } ] store_config! # instant probe on add config.sites = [ { url: args.first } ] Probe.new(config).probe(config.sites.last) end |
#email ⇒ Object
32 33 34 35 |
# File 'lib/trackchange/exec.rb', line 32 def email config.email = args.first store_config! end |
#install ⇒ Object
88 89 90 |
# File 'lib/trackchange/exec.rb', line 88 def install CronEdit::Crontab.Add('trackchange', CRON_LINE) end |
#list ⇒ Object
57 58 59 60 61 |
# File 'lib/trackchange/exec.rb', line 57 def list config.sites.each_with_index do |site, pos| puts "% 4s %s" % [pos+1, site[:url]] end end |
#probe ⇒ Object
commands
28 29 30 |
# File 'lib/trackchange/exec.rb', line 28 def probe Probe.run(config) end |
#remove ⇒ Object
81 82 83 84 85 86 |
# File 'lib/trackchange/exec.rb', line 81 def remove pos = args.first.to_i - 1 raise "Invalid position" if pos == -1 config.sites.delete_at(pos) store_config! end |
#rss ⇒ Object
37 38 39 40 |
# File 'lib/trackchange/exec.rb', line 37 def rss config.rss_path = args.first store_config! end |
#run ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/trackchange/exec.rb', line 18 def run FileUtils.mkdir_p(path) unless File.exist?(path) cmd = args.shift raise "No command" unless cmd return send(cmd) if respond_to?(cmd) raise "Unknown command #{cmd}" end |
#slack ⇒ Object
42 43 44 45 |
# File 'lib/trackchange/exec.rb', line 42 def slack config.slack_hook = args.first store_config! end |
#test ⇒ Object
TODO refactor to make remove code duplication
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/trackchange/exec.rb', line 64 def test pos = args.first.to_i - 1 raise "Invalid position" if pos == -1 site = config.sites[pos] url = site[:url] cmd = config.fetch substitutions = { url: url, queryscript: File.('../query.coffee', __FILE__), selector: site[:selector] } substitutions.each { |key, value| cmd = cmd.gsub("%#{key}%", value.to_s) } puts "% #{cmd}" puts %x[#{cmd}] end |
#uninstall ⇒ Object
92 93 94 |
# File 'lib/trackchange/exec.rb', line 92 def uninstall CronEdit::Crontab.Remove('trackchange') end |