tlog 0.2.0 → 0.2.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.
@@ -1,27 +1,27 @@
1
1
 
2
2
  class Tlog::Command::Push < Tlog::Command
3
3
 
4
- def name
5
- "push"
6
- end
4
+ def name
5
+ "push"
6
+ end
7
7
 
8
- def description
9
- "pushes your time logs upstream"
10
- end
8
+ def description
9
+ "pushes your time logs upstream"
10
+ end
11
11
 
12
- def execute(input, output)
13
- push_logs
14
- end
12
+ def execute(input, output)
13
+ push_logs
14
+ end
15
15
 
16
- def options(parser, options)
17
- parser.banner = "usage: tlog push"
18
- end
16
+ def options(parser, options)
17
+ parser.banner = "usage: tlog push"
18
+ end
19
19
 
20
- private
20
+ private
21
21
 
22
- def push_logs
23
- storage.in_branch do |wd|
24
- storage.push_logs
25
- end
26
- end
22
+ def push_logs
23
+ storage.in_branch do |wd|
24
+ storage.push_logs
25
+ end
26
+ end
27
27
  end
@@ -1,39 +1,39 @@
1
1
 
2
2
  class Tlog::Command::Start < Tlog::Command
3
3
 
4
- def name
5
- "start"
6
- end
7
-
8
- def description
9
- "starts a new task for a time log"
10
- end
11
-
12
- def execute(input, output)
13
- updated_log = start(input.options[:description])
14
- output.line("Started '#{updated_log.name}'")
15
- end
16
-
17
- def options(parser, options)
18
- parser.banner = "usage: tlog start"
19
-
20
- parser.on("-d", "--description <description>") do |description|
21
- options[:description] = description
22
- end
23
- end
24
-
25
- private
26
-
27
- def start(entry_description)
28
- storage.in_branch do |wd|
29
- checked_out_log = storage.checkout_value
30
- raise Tlog::Error::CheckoutInvalid, "No time log is checked out" unless checked_out_log
31
- log = storage.require_log(checked_out_log)
32
- raise Tlog::Error::TimeLogNotFound, "Time log '#{checked_out_log}' does not exist" unless log
33
- unless storage.start_log(log, entry_description)
34
- raise Tlog::Error::CommandInvalid, "Time log '#{checked_out_log}' is already in progress"
35
- end
36
- log
37
- end
38
- end
4
+ def name
5
+ "start"
6
+ end
7
+
8
+ def description
9
+ "starts a new task for a time log"
10
+ end
11
+
12
+ def execute(input, output)
13
+ updated_log = start(input.options[:description])
14
+ output.line("Started '#{updated_log.name}'")
15
+ end
16
+
17
+ def options(parser, options)
18
+ parser.banner = "usage: tlog start"
19
+
20
+ parser.on("-d", "--description <description>") do |description|
21
+ options[:description] = description
22
+ end
23
+ end
24
+
25
+ private
26
+
27
+ def start(entry_description)
28
+ storage.in_branch do |wd|
29
+ checked_out_log = storage.checkout_value
30
+ raise Tlog::Error::CheckoutInvalid, "No time log is checked out" unless checked_out_log
31
+ log = storage.require_log(checked_out_log)
32
+ raise Tlog::Error::TimeLogNotFound, "Time log '#{checked_out_log}' does not exist" unless log
33
+ unless storage.start_log(log, entry_description)
34
+ raise Tlog::Error::CommandInvalid, "Time log '#{checked_out_log}' is already in progress"
35
+ end
36
+ log
37
+ end
38
+ end
39
39
  end
@@ -1,34 +1,34 @@
1
1
 
2
2
  class Tlog::Command::State < Tlog::Command
3
3
 
4
- def name
5
- "state"
6
- end
4
+ def name
5
+ "state"
6
+ end
7
7
 
8
- def description
9
- "changes the state of the checked-out time log"
10
- end
8
+ def description
9
+ "changes the state of the checked-out time log"
10
+ end
11
11
 
12
- def execute(input, output)
13
- new_state = input.args[0]
14
- updated_log = change_state(new_state)
15
- output.line("Changed state of '#{updated_log.name}' to #{new_state}")
16
- end
12
+ def execute(input, output)
13
+ new_state = input.args[0]
14
+ updated_log = change_state(new_state)
15
+ output.line("Changed state of '#{updated_log.name}' to #{new_state}")
16
+ end
17
17
 
18
- def options(parser, options)
19
- parser.banner = "usage: tlog state <new_state>"
20
- end
18
+ def options(parser, options)
19
+ parser.banner = "usage: tlog state <new_state>"
20
+ end
21
21
 
22
- private
22
+ private
23
23
 
24
- def change_state(new_state)
25
- storage.in_branch do |wd|
26
- checked_out_log = storage.checkout_value
27
- raise Tlog::Error::CheckoutInvalid, "No time log is checked out" unless checked_out_log
28
- log = storage.require_log(checked_out_log)
29
- raise Tlog::Error::TimeLogNotFound, "Time log '#{checked_out_log}' does not exist" unless log
30
- storage.change_log_state(log, new_state)
31
- log
32
- end
33
- end
24
+ def change_state(new_state)
25
+ storage.in_branch do |wd|
26
+ checked_out_log = storage.checkout_value
27
+ raise Tlog::Error::CheckoutInvalid, "No time log is checked out" unless checked_out_log
28
+ log = storage.require_log(checked_out_log)
29
+ raise Tlog::Error::TimeLogNotFound, "Time log '#{checked_out_log}' does not exist" unless log
30
+ storage.change_log_state(log, new_state)
31
+ log
32
+ end
33
+ end
34
34
  end
@@ -1,35 +1,35 @@
1
1
  class Tlog::Command::Stop < Tlog::Command
2
2
 
3
- def name
4
- "stop"
5
- end
3
+ def name
4
+ "stop"
5
+ end
6
6
 
7
- def description
8
- "ends a task for a time log"
9
- end
7
+ def description
8
+ "ends a task for a time log"
9
+ end
10
10
 
11
- def execute(input, output)
12
- updated_log = stop
13
- output.line("Stopped '#{updated_log.name}'")
14
- end
11
+ def execute(input, output)
12
+ updated_log = stop
13
+ output.line("Stopped '#{updated_log.name}'")
14
+ end
15
15
 
16
- def options(parser, options)
17
- parser.banner = "usage: tlog stop"
18
- end
16
+ def options(parser, options)
17
+ parser.banner = "usage: tlog stop"
18
+ end
19
19
 
20
- private
20
+ private
21
21
 
22
- def stop
23
- storage.in_branch do |wd|
24
- checked_out_log = storage.checkout_value
25
- raise Tlog::Error::CheckoutInvalid, "No time log is checked out" unless checked_out_log
26
- log = storage.require_log(checked_out_log)
27
- raise Tlog::Error::TimeLogNotFound, "Time log '#{checked_out_log}' does not exist" unless log
28
- unless storage.stop_log(log)
29
- raise Tlog::Error::CommandInvalid, "Failed to stop log '#{checked_out_log}': This time log is not in progress"
30
- end
31
- log
32
- end
33
- end
22
+ def stop
23
+ storage.in_branch do |wd|
24
+ checked_out_log = storage.checkout_value
25
+ raise Tlog::Error::CheckoutInvalid, "No time log is checked out" unless checked_out_log
26
+ log = storage.require_log(checked_out_log)
27
+ raise Tlog::Error::TimeLogNotFound, "Time log '#{checked_out_log}' does not exist" unless log
28
+ unless storage.stop_log(log)
29
+ raise Tlog::Error::CommandInvalid, "Failed to stop log '#{checked_out_log}': This time log is not in progress"
30
+ end
31
+ log
32
+ end
33
+ end
34
34
 
35
35
  end
data/lib/tlog/command.rb CHANGED
@@ -1,14 +1,15 @@
1
+
1
2
  class Tlog::Command
2
3
 
3
- attr_accessor :storage
4
- attr_accessor :seconds_format
5
- attr_accessor :date_time_format
4
+ attr_accessor :storage
5
+ attr_accessor :seconds_format
6
+ attr_accessor :date_time_format
6
7
 
7
- def execute(input, output)
8
- raise NotImplementedError
9
- end
8
+ def execute(input, output)
9
+ raise Tlog::Error::NotImplementedError
10
+ end
10
11
 
11
- def options(parser, options)
12
- end
12
+ def options(parser, options)
13
+ end
13
14
 
14
15
  end
@@ -2,35 +2,35 @@
2
2
  # Simple helper class that handles an array of commands
3
3
  class Tlog::Command_Suite
4
4
 
5
- class << self
6
- def commands
7
- storage = self.working_dir_storage
8
- commands = [
9
- Tlog::Command::Start.new,
10
- Tlog::Command::Stop.new,
11
- Tlog::Command::Help.new,
12
- Tlog::Command::Active.new,
13
- Tlog::Command::Delete.new,
14
- Tlog::Command::Display.new,
15
- Tlog::Command::Create.new,
16
- Tlog::Command::Checkout.new,
17
- Tlog::Command::State.new,
18
- Tlog::Command::Points.new,
19
- Tlog::Command::Owner.new,
20
- Tlog::Command::Push.new,
21
- Tlog::Command::Pull.new,
22
- ]
23
- commands.each do |command|
24
- command.storage = storage
25
- command.seconds_format = Tlog::Format::Seconds
26
- command.date_time_format = Tlog::Format::DateTime
27
- end
28
- commands
29
- end
5
+ class << self
6
+ def commands
7
+ storage = self.working_dir_storage
8
+ commands = [
9
+ Tlog::Command::Start.new,
10
+ Tlog::Command::Stop.new,
11
+ Tlog::Command::Help.new,
12
+ Tlog::Command::Active.new,
13
+ Tlog::Command::Delete.new,
14
+ Tlog::Command::Display.new,
15
+ Tlog::Command::Create.new,
16
+ Tlog::Command::Checkout.new,
17
+ Tlog::Command::State.new,
18
+ Tlog::Command::Points.new,
19
+ Tlog::Command::Owner.new,
20
+ Tlog::Command::Push.new,
21
+ Tlog::Command::Pull.new,
22
+ ]
23
+ commands.each do |command|
24
+ command.storage = storage
25
+ command.seconds_format = Tlog::Format::Seconds
26
+ command.date_time_format = Tlog::Format::DateTime
27
+ end
28
+ commands
29
+ end
30
30
 
31
- def working_dir_storage
32
- Tlog::Storage::Disk.new('.')
33
- end
34
- end
31
+ def working_dir_storage
32
+ Tlog::Storage::Disk.new('.')
33
+ end
34
+ end
35
35
 
36
36
  end
@@ -1,13 +1,13 @@
1
1
 
2
2
  # Helper class for printing out active time logs
3
3
  class Tlog::Entity::Active_Log
4
- attr_reader :name
5
- attr_accessor :current
6
- attr_accessor :checked_out
4
+ attr_reader :name
5
+ attr_accessor :current
6
+ attr_accessor :checked_out
7
7
 
8
- def initialize(name)
9
- @name = name
10
- @current = false
11
- @checked_out = false
12
- end
8
+ def initialize(name)
9
+ @name = name
10
+ @current = false
11
+ @checked_out = false
12
+ end
13
13
  end
@@ -1,82 +1,82 @@
1
1
 
2
2
  class Tlog::Entity::Entry
3
3
 
4
- attr_accessor :hex
5
- attr_accessor :path
6
-
7
- def initialize(path, hex)
8
- @path = path
9
- @hex = hex
10
- end
11
-
12
- def length
13
- time_difference if time[:start] && time[:end]
14
- end
15
-
16
- def create(parent, current)
17
- FileUtils.mkdir_p(path)
18
- time_log = current[:start_time].to_s + " " + Time.now.to_s
19
- write_file(parent_path, parent)
20
- write_file(time_path, time_log.strip)
21
- write_file(description_path, current[:description])
22
- #write_file(owner_path, current[:owner])
23
- end
24
-
25
- def parent_hex
26
- read_file(parent_path)
27
- end
28
-
29
- def time
30
- time_hash = {}
31
- start_time_string = ""
32
- end_time_string = ""
33
- time_contents = read_file(time_path)
34
- return time_hash unless time_contents
35
- split_contents = time_contents.split(" ", 6)
36
- for i in 0..2
37
- start_time_string += split_contents[i] + " "
38
- end
39
- for i in 3..5
40
- end_time_string += split_contents[i] + " "
41
- end
42
- time_hash[:start] = Time.parse(start_time_string)
43
- time_hash[:end] = Time.parse(end_time_string)
44
- return time_hash
45
- end
46
-
47
- def description
48
- read_file(description_path)
49
- end
50
-
51
- private
52
-
53
- def write_file(path, content)
54
- File.open(path, 'w'){ |f| f.write(content)}
55
- end
56
-
57
- def read_file(path)
58
- if File.exists?(path)
59
- contents = File.read(path)
60
- contents.strip
61
- end
62
- end
63
-
64
- def time_difference
65
- time_hash = time
66
- difference = time_hash[:end] - time_hash[:start]
67
- difference.to_i
68
- end
69
-
70
- def parent_path
71
- File.join(@path, 'PARENT')
72
- end
73
-
74
- def time_path
75
- File.join(@path, 'TIME')
76
- end
77
-
78
- def description_path
79
- File.join(@path, 'DESCRIPTION')
80
- end
4
+ attr_accessor :hex
5
+ attr_accessor :path
6
+
7
+ def initialize(path, hex)
8
+ @path = path
9
+ @hex = hex
10
+ end
11
+
12
+ def length
13
+ time_difference if time[:start] && time[:end]
14
+ end
15
+
16
+ def create(parent, current)
17
+ FileUtils.mkdir_p(path)
18
+ time_log = current[:start_time].to_s + " " + Time.now.to_s
19
+ write_file(parent_path, parent)
20
+ write_file(time_path, time_log.strip)
21
+ write_file(description_path, current[:description])
22
+ #write_file(owner_path, current[:owner])
23
+ end
24
+
25
+ def parent_hex
26
+ read_file(parent_path)
27
+ end
28
+
29
+ def time
30
+ time_hash = {}
31
+ start_time_string = ""
32
+ end_time_string = ""
33
+ time_contents = read_file(time_path)
34
+ return time_hash unless time_contents
35
+ split_contents = time_contents.split(" ", 6)
36
+ for i in 0..2
37
+ start_time_string += split_contents[i] + " "
38
+ end
39
+ for i in 3..5
40
+ end_time_string += split_contents[i] + " "
41
+ end
42
+ time_hash[:start] = Time.parse(start_time_string)
43
+ time_hash[:end] = Time.parse(end_time_string)
44
+ return time_hash
45
+ end
46
+
47
+ def description
48
+ read_file(description_path)
49
+ end
50
+
51
+ private
52
+
53
+ def write_file(path, content)
54
+ File.open(path, 'w'){ |f| f.write(content)}
55
+ end
56
+
57
+ def read_file(path)
58
+ if File.exists?(path)
59
+ contents = File.read(path)
60
+ contents.strip
61
+ end
62
+ end
63
+
64
+ def time_difference
65
+ time_hash = time
66
+ difference = time_hash[:end] - time_hash[:start]
67
+ difference.to_i
68
+ end
69
+
70
+ def parent_path
71
+ File.join(@path, 'PARENT')
72
+ end
73
+
74
+ def time_path
75
+ File.join(@path, 'TIME')
76
+ end
77
+
78
+ def description_path
79
+ File.join(@path, 'DESCRIPTION')
80
+ end
81
81
 
82
82
  end