shepherd 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.md +11 -7
- data/LICENSE.txt +1 -1
- data/README.md +33 -28
- data/lib/shepherd.rb +56 -56
- data/lib/shepherd/cli.rb +129 -129
- data/lib/shepherd/command.rb +62 -62
- data/lib/shepherd/commands/init.rb +45 -45
- data/lib/shepherd/commands/list.rb +29 -0
- data/lib/shepherd/commands/rm.rb +26 -26
- data/lib/shepherd/commands/show.rb +36 -46
- data/lib/shepherd/counter.rb +101 -101
- data/lib/shepherd/db.rb +36 -36
- data/lib/shepherd/setup.rb +29 -29
- data/lib/shepherd/utils.rb +54 -54
- data/lib/shepherd/version.rb +7 -7
- metadata +9 -8
data/lib/shepherd/db.rb
CHANGED
|
@@ -1,40 +1,40 @@
|
|
|
1
1
|
require "sqlite3"
|
|
2
2
|
|
|
3
3
|
module Shepherd
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
|
|
4
|
+
|
|
5
|
+
# A class through which you can connect to the database.
|
|
6
|
+
#
|
|
7
|
+
# == Usage
|
|
8
|
+
#
|
|
9
|
+
# module Shepherd
|
|
10
|
+
# Db.new.execute "sql query"
|
|
11
|
+
# end
|
|
12
|
+
#
|
|
13
|
+
# Inside a +Shepherd::Command::Klass+, it would look like:
|
|
14
|
+
#
|
|
15
|
+
# module Shepherd::Command
|
|
16
|
+
# class Klass
|
|
17
|
+
# def init
|
|
18
|
+
# Shepherd::Db.new.execute "sql query"
|
|
19
|
+
# end
|
|
20
|
+
# end
|
|
21
|
+
# end
|
|
22
|
+
#
|
|
23
|
+
# Here is {SQLite3 documantation}[http://sqlite-ruby.rubyforge.org/sqlite3/faq.html]. +Shepherd::Db.new+ is equal to +SQLite3::Database.new+ so there you've got a complete documentation.
|
|
24
|
+
#
|
|
25
|
+
class Db
|
|
26
|
+
|
|
27
|
+
# When the database file was not found
|
|
28
|
+
class DatabaseNotFound < RuntimeError; end
|
|
29
|
+
|
|
30
|
+
def initialize
|
|
31
|
+
raise DatabaseNotFound, "Error: database file not found: '#{Dir.home}/.shepherd/herd.db'\nTry running 'shep setup'." unless File.exists? "#{Dir.home}/.shepherd/herd.db"
|
|
32
|
+
# A new instance of +SQLite3::Database+
|
|
33
|
+
@db = SQLite3::Database.new "#{Dir.home}/.shepherd/herd.db"
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def method_missing m, *args, &block
|
|
37
|
+
@db.send m, *args, &block
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
40
|
end
|
data/lib/shepherd/setup.rb
CHANGED
|
@@ -1,39 +1,39 @@
|
|
|
1
1
|
require "fileutils"
|
|
2
2
|
|
|
3
3
|
module Shepherd
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
class Setup
|
|
5
|
+
def initialize
|
|
6
6
|
puts "[shep] performing a setup:\n\n"
|
|
7
|
-
|
|
7
|
+
@schema = <<-EOS
|
|
8
8
|
create table if not exists sheeps (
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
9
|
+
id integer primary key autoincrement,
|
|
10
|
+
name varchar(128) not null,
|
|
11
|
+
path varchar(256) not null,
|
|
12
|
+
files integer(6) not null,
|
|
13
|
+
lines integer(7) not null,
|
|
14
|
+
chars integer(10) not null,
|
|
15
|
+
bytes integer(10) not null,
|
|
16
|
+
inited_at datetime not null,
|
|
17
17
|
updated_at datetime not null
|
|
18
18
|
);
|
|
19
19
|
EOS
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
21
|
+
crdir "#{Dir.home}/.shepherd"
|
|
22
|
+
crfile "#{Dir.home}/.shepherd/herd.db"
|
|
23
|
+
puts "[shep] setup: making a real database: #{Dir.home}/.shepherd/herd.db"
|
|
24
|
+
Db.new.execute "#{@schema}"
|
|
25
|
+
exit 0
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
private
|
|
29
|
+
def crdir dir
|
|
30
|
+
puts "[shep] setup: creating dir: #{dir}"
|
|
31
|
+
::FileUtils.mkdir "#{Dir.home}/.shepherd"
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def crfile file
|
|
35
|
+
puts "[shep] setup: creating file: #{file}"
|
|
36
|
+
::FileUtils.touch "#{Dir.home}/.shepherd/herd.db"
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
39
|
end
|
data/lib/shepherd/utils.rb
CHANGED
|
@@ -1,60 +1,60 @@
|
|
|
1
1
|
module Shepherd
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
2
|
+
module Utils
|
|
3
|
+
def yes? msg = "Would you like to proceed?"
|
|
4
|
+
print "#{msg} [Yn]: "
|
|
5
|
+
case $stdin.gets
|
|
6
|
+
when /(y|yes)/i
|
|
7
|
+
true
|
|
8
|
+
when "\n"
|
|
9
|
+
true
|
|
10
|
+
when /(n|no)/i
|
|
11
|
+
false
|
|
12
|
+
else
|
|
13
|
+
false
|
|
14
|
+
end
|
|
15
|
+
end # yes?:Method
|
|
16
|
+
|
|
17
|
+
# Convert bytes into more human readable format.
|
|
18
|
+
# I have found nice resolution here[http://www.ruby-forum.com/topic/119703]
|
|
19
|
+
# which was originally written by Jeff Emminger and I just add this part
|
|
20
|
+
# to automaticly set the unit. Thank you, Jeff!
|
|
21
|
+
#
|
|
22
|
+
# @param [Integer] number of bytes to be formatted
|
|
23
|
+
# @return [String] a formatted number with the unit appended to it
|
|
24
|
+
def self.nice_bytes number
|
|
25
|
+
units = {:b => 1,
|
|
26
|
+
:kb => 2**10,
|
|
27
|
+
:mb => 2**20,
|
|
28
|
+
:gb => 2**30,
|
|
29
|
+
:tb => 2**40}
|
|
30
|
+
|
|
31
|
+
unit = :b
|
|
32
|
+
case number
|
|
33
|
+
when 1...2**10
|
|
34
|
+
unit = :b
|
|
35
|
+
when 2**10...2**20
|
|
36
|
+
unit = :kb
|
|
37
|
+
when 2**20...2**30
|
|
38
|
+
unit = :mb
|
|
39
|
+
when 2**30...2**40
|
|
40
|
+
unit = :gb
|
|
41
|
+
when 2**40...2**50
|
|
42
|
+
unit = :tb
|
|
43
|
+
end
|
|
44
|
+
"#{sprintf("%.#{0}f", number / units[unit.to_s.downcase.to_sym])} #{unit.to_s.upcase}"
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
47
|
end
|
|
48
48
|
|
|
49
49
|
class Integer
|
|
50
|
-
|
|
51
|
-
|
|
50
|
+
def to_nice
|
|
51
|
+
s = self.to_s
|
|
52
52
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
53
|
+
if s.include? ?.
|
|
54
|
+
pre, post = s.split '.'
|
|
55
|
+
"#{pre.reverse.gsub( /\d{3}(?=\d)/, '\&,' ).reverse}.#{post}"
|
|
56
|
+
else
|
|
57
|
+
s.reverse.gsub( /\d{3}(?=\d)/, '\&.' ).reverse
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
60
|
end
|
data/lib/shepherd/version.rb
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
module Shepherd
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
module Version
|
|
3
|
+
MAJOR = 0
|
|
4
|
+
MINOR = 3
|
|
5
|
+
PATCH = 1
|
|
6
|
+
BUILD = nil
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
STRING = [MAJOR, MINOR, PATCH, BUILD].compact.join "."
|
|
9
|
+
end
|
|
10
10
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: shepherd
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.3.
|
|
4
|
+
version: 0.3.1
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -9,11 +9,11 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date: 2012-01-
|
|
12
|
+
date: 2012-01-17 00:00:00.000000000Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: sqlite3
|
|
16
|
-
requirement: &
|
|
16
|
+
requirement: &71169800 !ruby/object:Gem::Requirement
|
|
17
17
|
none: false
|
|
18
18
|
requirements:
|
|
19
19
|
- - ~>
|
|
@@ -21,10 +21,10 @@ dependencies:
|
|
|
21
21
|
version: 1.3.0
|
|
22
22
|
type: :runtime
|
|
23
23
|
prerelease: false
|
|
24
|
-
version_requirements: *
|
|
24
|
+
version_requirements: *71169800
|
|
25
25
|
- !ruby/object:Gem::Dependency
|
|
26
26
|
name: yard
|
|
27
|
-
requirement: &
|
|
27
|
+
requirement: &71169380 !ruby/object:Gem::Requirement
|
|
28
28
|
none: false
|
|
29
29
|
requirements:
|
|
30
30
|
- - ~>
|
|
@@ -32,10 +32,10 @@ dependencies:
|
|
|
32
32
|
version: 0.7.2
|
|
33
33
|
type: :development
|
|
34
34
|
prerelease: false
|
|
35
|
-
version_requirements: *
|
|
35
|
+
version_requirements: *71169380
|
|
36
36
|
- !ruby/object:Gem::Dependency
|
|
37
37
|
name: rspec
|
|
38
|
-
requirement: &
|
|
38
|
+
requirement: &71169130 !ruby/object:Gem::Requirement
|
|
39
39
|
none: false
|
|
40
40
|
requirements:
|
|
41
41
|
- - ~>
|
|
@@ -43,7 +43,7 @@ dependencies:
|
|
|
43
43
|
version: 2.6.0
|
|
44
44
|
type: :development
|
|
45
45
|
prerelease: false
|
|
46
|
-
version_requirements: *
|
|
46
|
+
version_requirements: *71169130
|
|
47
47
|
description: Check if/how your projects are growing up!
|
|
48
48
|
email:
|
|
49
49
|
- szymon.urbas@yahoo.com
|
|
@@ -64,6 +64,7 @@ files:
|
|
|
64
64
|
- lib/shepherd/command.rb
|
|
65
65
|
- lib/shepherd/commands/check.rb
|
|
66
66
|
- lib/shepherd/commands/init.rb
|
|
67
|
+
- lib/shepherd/commands/list.rb
|
|
67
68
|
- lib/shepherd/commands/rm.rb
|
|
68
69
|
- lib/shepherd/commands/show.rb
|
|
69
70
|
- lib/shepherd/commands/update.rb
|