Class: Shepherd::Command::Check

Inherits:
Object
  • Object
show all
Defined in:
lib/shepherd/commands/check.rb

Instance Method Summary collapse

Instance Method Details

#check_allObject



18
19
20
21
22
23
24
25
26
# File 'lib/shepherd/commands/check.rb', line 18

def check_all
  n = 0
  Shepherd::Db.new.execute "select * from sheeps" do |sheep|
    n += 1
    update_one sheep[0]
    count = Shepherd::Db.new.execute("select count(*) from sheeps").first.first
    puts "         ---\n\n" if n < count
  end
end

#check_one(name) ⇒ Object



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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/shepherd/commands/check.rb', line 28

def check_one name
  out = ""

  sheep = Shepherd::Db.new.get_first_row "select * from sheeps where name = ?", name
  if sheep
    out += "   name: \e[1;35m#{sheep[1]}\e[0;0m from \e[1;34m#{sheep[2]}\e[0;0m\n\n"
    Shepherd::Counter.new(sheep[2]) do |count|
      files = count.files - sheep[3]
      if files < 0
        files = files.to_s[1..-1].to_i
        out += "  state: \e[1;34m#{count.files.to_nice}\e[0;0m files (#{sheep[3].to_nice} \e[1;31m- #{files.to_nice}\e[0;0m)"
      elsif files == 0
        out += "  state: \e[1;34m#{count.files.to_nice}\e[0;0m files\n"
      else
        out += "  state: \e[1;34m#{count.files.to_nice}\e[0;0m files (#{sheep[3].to_nice} \e[1;32m+ #{files.to_nice}\e[0;0m)\n"
      end

      lines = count.lines - sheep[4]
      if lines < 0
        lines = lines.to_s[1..-1].to_i
        out += "         \e[1;34m#{count.lines.to_nice}\e[0;0m lines (#{sheep[4].to_nice} \e[1;31m- #{lines.to_nice}\e[0;0m)"
      elsif lines == 0
        out += "         \e[1;34m#{count.lines.to_nice}\e[0;0m lines\n"
      else
        out += "         \e[1;34m#{count.lines.to_nice}\e[0;0m lines (#{sheep[4].to_nice} \e[1;32m+ #{lines.to_nice}\e[0;0m)\n"
      end

      chars = count.chars - sheep[5]
      if chars < 0
        chars = chars.to_s[1..-1].to_i
        out += "         \e[1;34m#{count.chars.to_nice}\e[0;0m chars (#{sheep[5].to_nice} \e[1;31m- #{chars.to_nice}\e[0;0m)\n\n"
      elsif chars == 0
        out += "         \e[1;34m#{count.chars.to_nice}\e[0;0m chars\n\n"
      else
        out += "         \e[1;34m#{count.chars.to_nice}\e[0;0m chars (#{sheep[5].to_nice} \e[1;32m+ #{chars.to_nice}\e[0;0m)\n\n"
      end

      bytes = count.bytes - sheep[6]
      if bytes < 0
        bytes = bytes.to_s[1..-1].to_i
        out += "         \e[1;34m#{Shepherd::Utils.nice_bytes count.bytes}\e[0;0m bytes (#{Shepherd::Utils.nice_bytes sheep[6]} \e[1;31m- #{Shepherd::Utils.nice_bytes bytes}\e[0;0m)\n"
      elsif bytes == 0
        out += "         \e[1;34m#{Shepherd::Utils.nice_bytes count.bytes}\e[0;0m\n"
      else
        out += "         \e[1;34m#{Shepherd::Utils.nice_bytes count.bytes}\e[0;0m bytes (#{Shepherd::Utils.nice_bytes sheep[6]} \e[1;32m+ #{Shepherd::Utils.nice_bytes bytes}\e[0;0m)\n"
      end

      out += "\n  since: #{sheep[8]}"

      puts "#{out}\n\n"
    end
  else
    puts "[shep] error: no such sheep."
  end
end

#descObject



84
85
86
# File 'lib/shepherd/commands/check.rb', line 84

def desc
  "see how the projects have grown"
end

#initObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/shepherd/commands/check.rb', line 3

def init
  @opts = Trollop::options do
    banner <<-EOB
usage: shep check [sheep] [options]
EOB
    opt :help, "show me and exit", :short => '-h'
  end
  
  if name = ARGV.shift
    check_one name
  else
    check_all
  end
end