Class: Saimaa::Command
- Inherits:
-
Object
- Object
- Saimaa::Command
- Defined in:
- lib/saimaa.rb
Class Method Summary collapse
- .execute(cmd, project) ⇒ Object
- .notify(cmd, stdin) ⇒ Object
- .run(argv) ⇒ Object
- .save(project, record) ⇒ Object
Class Method Details
.execute(cmd, project) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/saimaa.rb', line 43 def execute(cmd, project) stats, stdout, stderr = systemu(cmd) result = %W( --project-- #{project} --stdout-- #{stdout} --stderr-- #{stderr} ).join("\n") [stats, result] end |
.notify(cmd, stdin) ⇒ Object
56 57 58 |
# File 'lib/saimaa.rb', line 56 def notify(cmd, stdin) systemu(cmd, :stdin => stdin) end |
.run(argv) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/saimaa.rb', line 10 def run(argv) = {} stats, result = [] OptionParser.new do |opt| opt.on('-c COMMAND', 'execute command') do |cmd| [:execute] = cmd end opt.on('-n COMMAND', 'notifier command') do |cmd| [:notify] = cmd end opt.parse!(argv) end project = argv.first if .key?(:execute) stats, result = execute([:execute], project) end unless stats.to_i == 0 if .key?(:notify) notify([:notify], result) else puts result end end save(project, :stats => stats.to_i, :result => result, :time => Time.now) end |
.save(project, record) ⇒ Object
60 61 62 63 64 65 66 67 68 |
# File 'lib/saimaa.rb', line 60 def save(project, record) path = "#{ENV["HOME"]}/.saimaa" FileUtils.mkdir(path) unless File.exists?(path) db = YAML::Store.new("#{path}/saimaa.yml") db.transaction do db[project] ||= [] db[project] << record end end |