Class: Shepherd::Command::Update
- Inherits:
-
Object
- Object
- Shepherd::Command::Update
- Defined in:
- lib/shepherd/commands/update.rb
Instance Method Summary collapse
Instance Method Details
#desc ⇒ Object
40 41 42 |
# File 'lib/shepherd/commands/update.rb', line 40 def desc "update sheep's current state" end |
#init ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/shepherd/commands/update.rb', line 3 def init @opts = Trollop:: do <<-EOB usage: shep update [sheep] EOB opt :help, "show me and exit", :short => '-h' end if sheep = ARGV.shift update_one sheep else update_all end end |
#update_all ⇒ Object
18 19 20 |
# File 'lib/shepherd/commands/update.rb', line 18 def update_all puts "updat'd all" end |
#update_one(name) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/shepherd/commands/update.rb', line 22 def update_one name sheep = Shepherd::Db.new.get_first_row "select * from sheeps where name = ?", name state = {} Shepherd::Counter.new(sheep[2]) do |count| state[:files] = count.files state[:lines] = count.lines state[:chars] = count.chars state[:bytes] = count.bytes end if Shepherd::Db.new.execute "update sheeps set files = ?, lines = ?, chars = ?, bytes = ?, updated_at = datetime() where name = ?", state[:files], state[:lines], state[:chars], state[:bytes], name puts "[shep] nice: #{name} was successfuly updated." else puts "[shep] error: something went wrong.." end end |