rtt 0.0.0.7 → 0.0.0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. data/Manifest +34 -2
  2. data/README.rdoc +17 -5
  3. data/Rakefile +2 -2
  4. data/USAGE.txt +47 -9
  5. data/db/rtt.sqlite3 +0 -0
  6. data/db/rtt2.sqlite3 +0 -0
  7. data/db/test.sqlite3 +0 -0
  8. data/lib/rtt.rb +75 -31
  9. data/lib/rtt/client.rb +17 -0
  10. data/lib/rtt/{cmd_line_interpreter.rb → cmd_line_parser.rb} +53 -13
  11. data/lib/rtt/interactive_configurator.rb +162 -0
  12. data/lib/rtt/project.rb +21 -2
  13. data/lib/rtt/query_builder.rb +5 -3
  14. data/lib/rtt/report_generator.rb +70 -50
  15. data/lib/rtt/storage.rb +1 -1
  16. data/lib/rtt/task.rb +9 -1
  17. data/lib/rtt/user.rb +12 -1
  18. data/rtt.gemspec +10 -7
  19. data/spec/lib/rtt_spec.rb +5 -5
  20. data/todo.txt +1 -0
  21. data/vendor/highline-1.5.2/CHANGELOG +227 -0
  22. data/vendor/highline-1.5.2/INSTALL +41 -0
  23. data/vendor/highline-1.5.2/LICENSE +7 -0
  24. data/vendor/highline-1.5.2/README +63 -0
  25. data/vendor/highline-1.5.2/Rakefile +82 -0
  26. data/vendor/highline-1.5.2/TODO +6 -0
  27. data/vendor/highline-1.5.2/examples/ansi_colors.rb +38 -0
  28. data/vendor/highline-1.5.2/examples/asking_for_arrays.rb +18 -0
  29. data/vendor/highline-1.5.2/examples/basic_usage.rb +75 -0
  30. data/vendor/highline-1.5.2/examples/color_scheme.rb +32 -0
  31. data/vendor/highline-1.5.2/examples/limit.rb +12 -0
  32. data/vendor/highline-1.5.2/examples/menus.rb +65 -0
  33. data/vendor/highline-1.5.2/examples/overwrite.rb +19 -0
  34. data/vendor/highline-1.5.2/examples/page_and_wrap.rb +322 -0
  35. data/vendor/highline-1.5.2/examples/password.rb +7 -0
  36. data/vendor/highline-1.5.2/examples/trapping_eof.rb +22 -0
  37. data/vendor/highline-1.5.2/examples/using_readline.rb +17 -0
  38. data/vendor/highline-1.5.2/lib/highline.rb +758 -0
  39. data/vendor/highline-1.5.2/lib/highline/color_scheme.rb +120 -0
  40. data/vendor/highline-1.5.2/lib/highline/compatibility.rb +17 -0
  41. data/vendor/highline-1.5.2/lib/highline/import.rb +43 -0
  42. data/vendor/highline-1.5.2/lib/highline/menu.rb +395 -0
  43. data/vendor/highline-1.5.2/lib/highline/question.rb +463 -0
  44. data/vendor/highline-1.5.2/lib/highline/system_extensions.rb +240 -0
  45. data/vendor/highline-1.5.2/setup.rb +1360 -0
  46. data/vendor/highline-1.5.2/test/tc_color_scheme.rb +56 -0
  47. data/vendor/highline-1.5.2/test/tc_highline.rb +823 -0
  48. data/vendor/highline-1.5.2/test/tc_import.rb +54 -0
  49. data/vendor/highline-1.5.2/test/tc_menu.rb +429 -0
  50. data/vendor/highline-1.5.2/test/ts_all.rb +15 -0
  51. metadata +65 -15
  52. data/lib/rtt/user_configurator.rb +0 -24
data/Manifest CHANGED
@@ -5,21 +5,53 @@ Rakefile
5
5
  USAGE.txt
6
6
  bin/rtt
7
7
  db/rtt.sqlite3
8
+ db/rtt2.sqlite3
8
9
  db/test.sqlite3
9
10
  lib/rtt.rb
10
11
  lib/rtt/client.rb
11
- lib/rtt/cmd_line_interpreter.rb
12
+ lib/rtt/cmd_line_parser.rb
12
13
  lib/rtt/hash_extensions.rb
14
+ lib/rtt/interactive_configurator.rb
13
15
  lib/rtt/project.rb
14
16
  lib/rtt/query_builder.rb
15
17
  lib/rtt/report_generator.rb
16
18
  lib/rtt/storage.rb
17
19
  lib/rtt/task.rb
18
20
  lib/rtt/user.rb
19
- lib/rtt/user_configurator.rb
20
21
  log/rtt.sqlite3
21
22
  rtt.gemspec
22
23
  spec/datamapper_spec_helper.rb
23
24
  spec/lib/rtt/task_spec.rb
24
25
  spec/lib/rtt_spec.rb
25
26
  tasks/rtt.rake
27
+ todo.txt
28
+ vendor/highline-1.5.2/CHANGELOG
29
+ vendor/highline-1.5.2/INSTALL
30
+ vendor/highline-1.5.2/LICENSE
31
+ vendor/highline-1.5.2/README
32
+ vendor/highline-1.5.2/Rakefile
33
+ vendor/highline-1.5.2/TODO
34
+ vendor/highline-1.5.2/examples/ansi_colors.rb
35
+ vendor/highline-1.5.2/examples/asking_for_arrays.rb
36
+ vendor/highline-1.5.2/examples/basic_usage.rb
37
+ vendor/highline-1.5.2/examples/color_scheme.rb
38
+ vendor/highline-1.5.2/examples/limit.rb
39
+ vendor/highline-1.5.2/examples/menus.rb
40
+ vendor/highline-1.5.2/examples/overwrite.rb
41
+ vendor/highline-1.5.2/examples/page_and_wrap.rb
42
+ vendor/highline-1.5.2/examples/password.rb
43
+ vendor/highline-1.5.2/examples/trapping_eof.rb
44
+ vendor/highline-1.5.2/examples/using_readline.rb
45
+ vendor/highline-1.5.2/lib/highline.rb
46
+ vendor/highline-1.5.2/lib/highline/color_scheme.rb
47
+ vendor/highline-1.5.2/lib/highline/compatibility.rb
48
+ vendor/highline-1.5.2/lib/highline/import.rb
49
+ vendor/highline-1.5.2/lib/highline/menu.rb
50
+ vendor/highline-1.5.2/lib/highline/question.rb
51
+ vendor/highline-1.5.2/lib/highline/system_extensions.rb
52
+ vendor/highline-1.5.2/setup.rb
53
+ vendor/highline-1.5.2/test/tc_color_scheme.rb
54
+ vendor/highline-1.5.2/test/tc_highline.rb
55
+ vendor/highline-1.5.2/test/tc_import.rb
56
+ vendor/highline-1.5.2/test/tc_menu.rb
57
+ vendor/highline-1.5.2/test/ts_all.rb
data/README.rdoc CHANGED
@@ -10,11 +10,11 @@ If no <task-name> is specified the last paused one is activated, otherwise a tas
10
10
 
11
11
  Then to stop the timer, you can do:
12
12
 
13
- $ rtt stop
13
+ $ rtt stop | pause | resume (if there is a paused task)
14
14
 
15
15
  Also, by just typying: 'rtt start', without specifying the task, it would default to the previous task.
16
16
 
17
- If you start a task with the same name as one already stored for the very same day, then the elapsed time for both activities will be sum into just one task.
17
+ If you start a task with the same name as one already stored for the very same day, then both task will be merged (suming the time of each one of those).
18
18
 
19
19
  Installation
20
20
  ------------
@@ -23,12 +23,18 @@ Installation
23
23
 
24
24
  After installing the gem you will need to setup some basic information of yours (data to be printed in the reports). With the following command:
25
25
 
26
- $ rtt user <user-nick-name>
26
+ $ rtt configure user [<user-nick-name>]
27
27
 
28
28
  Then you will be prompt for First name, Last name, country, city, e-mail, site, etc. Information that will be used to fill-in the reports.
29
29
 
30
30
  The only required field is the Nickname, which identifies the user.
31
31
 
32
+ To configure the current Project and Client you can use an analogous command:
33
+
34
+ $ rtt configure project | rtt configure client
35
+
36
+ After which, you'll be prompted for the attributes for those models.
37
+
32
38
  How to start a task?
33
39
  --------------------
34
40
 
@@ -37,15 +43,17 @@ $ rtt '<task-name>' ( or the more explicit way: 'rtt start <task-name>')
37
43
 
38
44
  That simple!
39
45
 
46
+ Note: This command will create a task for the current configured user, project and client.
47
+
40
48
  More about the API
41
49
  ------------------
42
50
 
43
- Task can be grouped in Projects. For that you must set the project before starting the timer, in the following way:
51
+ To change the current project. You can do this:
44
52
 
45
53
  $ rtt project <project-name>
46
54
  ..
47
55
 
48
- Anagolous, you can define a Client for the current project by typing:
56
+ Anagolous, you can change the current Client by typing:
49
57
 
50
58
  $ rtt client <client-name>
51
59
 
@@ -72,6 +80,10 @@ $ PROJECT=SomeProject rtt report
72
80
 
73
81
  This will generate a report for the project 'SomeProject'.
74
82
 
83
+ $ FROM=20-01-2010 TO=25-01-2010 CLIENT=SomeClient rtt report
84
+
85
+ The output for this command will produce a report only for the task started after 20th of January and before 25th of January and also that were produced for the client called 'SomeClient'.
86
+
75
87
  Questions/Comments
76
88
  ------------------
77
89
 
data/Rakefile CHANGED
@@ -3,13 +3,13 @@ require 'echoe'
3
3
 
4
4
  # PACKAGING ============================================================
5
5
 
6
- Echoe.new('rtt', '0.0.0.7') do |p|
6
+ Echoe.new('rtt', '0.0.0.8') do |p|
7
7
  p.description = 'RTT is a tool for tracking time'
8
8
  p.url = 'http://github.com/marklazz/rtt'
9
9
  p.author = 'Marcelo Giorgi'
10
10
  p.email = 'marklazz.uy@gmail.com'
11
11
  p.ignore_pattern = [ 'tmp/*', 'script/*', '*.sh' ]
12
- p.runtime_dependencies = [ ['highline', ">= 1.5.2"], ['activesupport', '>= 2.3.0'], ['prawn', '>= 0.8.0'], 'data_mapper', 'dm-sqlite-adapter' ]
12
+ p.runtime_dependencies = [ ['highline', ">= 1.5.2"], ['activesupport', '>= 2.3.0'], ['prawn', '>= 0.8.0'], ['dm-core', '>= 1.0.0'], [ 'dm-migrations', '>= 1.0.0'], 'dm-sqlite-adapter' ]
13
13
  p.development_dependencies = [ 'spec' ]
14
14
  end
15
15
 
data/USAGE.txt CHANGED
@@ -1,13 +1,51 @@
1
+
1
2
  RTT is a tool for tracking time. It's primary extend is to be used from command line.
3
+ =====================================================================================
2
4
 
3
5
  Usage:
4
6
 
5
- rtt start <task-name>
6
- rtt pause
7
- rtt stop
8
- rtt user <nickname>
9
- rtt client <client-name>
10
- rtt project <project-name>
11
- rtt rename <new-name-current-task>
12
- rtt list
13
- rtt report <filename>.pdf
7
+ - rtt start <task-name> | rtt <task-name>
8
+
9
+ Starts a new task (or existing task with that name) for the current project/client/user.
10
+
11
+ - rtt pause
12
+
13
+ Pauses the current task.
14
+
15
+ - rtt resume
16
+
17
+ Resumes the last paused task.
18
+
19
+ - rtt stop
20
+
21
+ Stops the current task.
22
+
23
+ - rtt user <nickname>
24
+
25
+ Changes the current user. If there is no user with the nickname specified it ask for user information interactivly.
26
+
27
+ - rtt client <client-name>
28
+
29
+ Sets the current client with with name specified (creates one client if there no client stored with that name).
30
+
31
+ - rtt project <project-name>
32
+
33
+ Sets the current project with the specified name.
34
+
35
+ - rtt rename <new-name-current-task>
36
+
37
+ Rename current task
38
+
39
+ - CLIENT=some_client rtt list | CLIENT=some_client PROJECT=some_project rtt list | PROJECT=some_project rtt list
40
+
41
+ List all tasks created for the filters provided.
42
+
43
+ - rtt report <filename>
44
+
45
+ Generates a report to be stored on on the path specified.
46
+
47
+ - rtt configure (client|project|user|task)
48
+
49
+ Allows to change properties of current objects.
50
+
51
+ Enjoy!
data/db/rtt.sqlite3 CHANGED
Binary file
data/db/rtt2.sqlite3 ADDED
Binary file
data/db/test.sqlite3 CHANGED
Binary file
data/lib/rtt.rb CHANGED
@@ -10,22 +10,44 @@ module Rtt
10
10
 
11
11
  class << self
12
12
 
13
- include CmdLineInterpreter
13
+ include CmdLineParser
14
14
  include QueryBuilder
15
15
  include ReportGenerator
16
16
  include Storage
17
17
 
18
+ def update_task(name, conditions)
19
+ extend(InteractiveConfigurator)
20
+ configure_task(name, conditions)
21
+ end
22
+
18
23
  def current_user
19
- User.first :active => true
24
+ active = User.first :active => true
25
+ return active if active.present?
26
+ User.find_or_create_active
20
27
  end
21
28
 
22
- def set_user(nickname = nil)
23
- current_user.deactivate if current_user
24
- if nickname && (user = User.first(:nickname => nickname)).present?
25
- user.activate
29
+ def delete(options = {})
30
+ if current_task && options.blank?
31
+ current_task.destroy
26
32
  else
27
- extend(UserConfigurator)
33
+ require 'ruby-debug'; debugger;
34
+
35
+ query(options).map(&:destroy)
36
+ end
37
+ end
38
+
39
+ def set_user(nickname = nil, configure = false)
40
+ user = if nickname.blank?
41
+ current_user
42
+ else
43
+ User.first(:nickname => nickname)
44
+ end
45
+ current_user.deactivate if current_user
46
+ if user.blank? || configure
47
+ extend(InteractiveConfigurator)
28
48
  configure_user(nickname)
49
+ else
50
+ user.activate
29
51
  end
30
52
  end
31
53
 
@@ -49,10 +71,10 @@ module Rtt
49
71
  # Rtt.list :from => '2010-5-3', :to => '2010-5-20'
50
72
  #
51
73
  def list options = {}
52
- puts 'Task List'
53
- puts '========='
74
+ say 'Task List'
75
+ say '========='
54
76
  query(options).each do |task|
55
- puts "Name: #{task.name} elapsed time: #{task.duration} #{'[ACTIVE]' if task.active}"
77
+ say "Name: #{task.name} || Client: #{task.client.name} || Project: #{task.project.name} || User: #{task.user.nickname} || Elapsed time: #{task.duration} #{'[ACTIVE]' if task.active} \n"
56
78
  end
57
79
  end
58
80
 
@@ -72,17 +94,39 @@ module Rtt
72
94
  # Usage
73
95
  #
74
96
  # set_client name
75
- def set_client name
76
- deactivate_current_client if current_client
77
- client = client(name)
78
- client.activate
97
+ def set_client(name = nil, configure = false)
98
+ if name.blank? || configure
99
+ extend(InteractiveConfigurator)
100
+ configure_client(name)
101
+ else
102
+ raise ParametersNotMatchCommandSignatureError if name.blank?
103
+ deactivate_current_client if current_client
104
+ client = client(name)
105
+ unless client.active
106
+ client.activate
107
+ else
108
+ client.save
109
+ end
110
+ end
79
111
  end
80
112
 
81
- def set_project project_name, client_name = nil
82
- deactivate_current_project if current_project
83
- client = client(client_name) unless client_name.nil?
84
- project = Project.first_or_create :name => project_name, :description => project_name
85
- project.activate_with_client(client)
113
+ def set_project(project_name = nil, client_name = nil, configure = false)
114
+ if project_name.blank? || configure
115
+ extend(InteractiveConfigurator)
116
+ configure_project(project_name, client_name)
117
+ else
118
+ raise ParametersNotMatchCommandSignatureError if project_name.blank?
119
+ deactivate_current_project if current_project
120
+ client = client(client_name) unless client_name.nil?
121
+ project = Project.first_or_create :name => project_name
122
+ project.client = client
123
+ project.description = project_name
124
+ unless project.active
125
+ project.activate
126
+ else
127
+ project.save
128
+ end
129
+ end
86
130
  end
87
131
 
88
132
  # Starts a new timer. It stops the current task if there is any.
@@ -104,6 +148,18 @@ module Rtt
104
148
  current_task.stop if current_task
105
149
  end
106
150
 
151
+ def current_client
152
+ Client.first :active => true
153
+ end
154
+
155
+ def current_project
156
+ Project.first :active => true
157
+ end
158
+
159
+ def current_task
160
+ Task.first :active => true
161
+ end
162
+
107
163
  private
108
164
 
109
165
  def client(name)
@@ -121,17 +177,5 @@ module Rtt
121
177
  project.active = false
122
178
  project.save
123
179
  end
124
-
125
- def current_client
126
- Client.first :active => true
127
- end
128
-
129
- def current_project
130
- Project.first :active => true
131
- end
132
-
133
- def current_task
134
- Task.first :active => true
135
- end
136
180
  end
137
181
  end
data/lib/rtt/client.rb CHANGED
@@ -12,14 +12,31 @@ module Rtt
12
12
  property :active, Boolean, :default => false
13
13
  has n, :projects #, :through => Resource
14
14
 
15
+ before :create do |client|
16
+ client.active = true if Client.all.length == 0
17
+ true
18
+ end
19
+
15
20
  def self.default
16
21
  first_or_create :active => true
17
22
  end
18
23
 
24
+ def self.current_active?
25
+ first :active => true
26
+ end
27
+
19
28
  def activate
29
+ deactivate_all
20
30
  self.active = true
21
31
  self.save
22
32
  self
23
33
  end
34
+
35
+ def deactivate_all
36
+ Client.all.each do |client|
37
+ client.active = false
38
+ client.save
39
+ end
40
+ end
24
41
  end
25
42
  end
@@ -2,18 +2,28 @@
2
2
  module Rtt
3
3
  class Command
4
4
  attr_accessor :name, :optional
5
+
6
+ def next_optional
7
+ optional.shift if optional.present?
8
+ end
9
+ end
10
+ class ConfigureCommand < Command
11
+ NUMBER_OF_PARAM_REQUIRED = 1
12
+ end
13
+ class DeleteCommand < Command
14
+ NUMBER_OF_PARAM_REQUIRED = 0
5
15
  end
6
16
  class PauseCommand < Command
7
17
  NUMBER_OF_PARAM_REQUIRED = 0
8
18
  end
9
19
  class SetProjectCommand < Command
10
- NUMBER_OF_PARAM_REQUIRED = 1
20
+ NUMBER_OF_PARAM_REQUIRED = 0
11
21
  end
12
22
  class SetUserCommand < Command
13
23
  NUMBER_OF_PARAM_REQUIRED = 0
14
24
  end
15
25
  class SetClientCommand < Command
16
- NUMBER_OF_PARAM_REQUIRED = 1
26
+ NUMBER_OF_PARAM_REQUIRED = 0
17
27
  end
18
28
  class StartCommand < Command
19
29
  NUMBER_OF_PARAM_REQUIRED = 0
@@ -32,8 +42,9 @@ module Rtt
32
42
  end
33
43
  class CommandNotFoundError < StandardError; end
34
44
  class TaskNotStartedError < StandardError; end
45
+ class ParametersNotMatchCommandSignatureError < StandardError; end
35
46
 
36
- module CmdLineInterpreter
47
+ module CmdLineParser
37
48
 
38
49
  COMMAND_MAPPING = {
39
50
  :project => SetProjectCommand,
@@ -45,7 +56,9 @@ module Rtt
45
56
  :list => QueryCommand,
46
57
  :pause => PauseCommand,
47
58
  :resume => StartCommand,
48
- :user => SetUserCommand
59
+ :user => SetUserCommand,
60
+ :delete => DeleteCommand,
61
+ :configure => ConfigureCommand
49
62
  }
50
63
 
51
64
  def capture(arguments)
@@ -55,8 +68,14 @@ module Rtt
55
68
  klazz = COMMAND_MAPPING[operation]
56
69
  if arguments.length >= klazz::NUMBER_OF_PARAM_REQUIRED
57
70
  command = klazz.new
58
- command.name = arguments.shift
59
- command.optional = arguments if arguments.present?
71
+ first_argument = arguments.shift
72
+ if /^--.*$/.match(first_argument)
73
+ command.name = nil
74
+ command.optional = [first_argument]
75
+ else
76
+ command.name = first_argument
77
+ command.optional = arguments if arguments.present?
78
+ end
60
79
  Array(command)
61
80
  end
62
81
  elsif operation.present?
@@ -71,7 +90,7 @@ module Rtt
71
90
  end
72
91
 
73
92
  def env_filters
74
- [ 'client', 'project' ].inject({}) do |filters, key|
93
+ [ 'date', 'nickname', 'from', 'to', 'client', 'project' ].inject({}) do |filters, key|
75
94
  filters[key.to_sym] = env_variable(key) if env_variable(key).present?
76
95
  filters
77
96
  end
@@ -83,7 +102,7 @@ module Rtt
83
102
 
84
103
  def execute(cmds)
85
104
  cmds.each { |cmd| execute_single(cmd) }
86
- puts "Operation(s) succeded."
105
+ say "Operation(s) succeded."
87
106
  rescue => e
88
107
  handle_error(e)
89
108
  end
@@ -91,12 +110,14 @@ module Rtt
91
110
  def execute_single(cmd)
92
111
  case cmd
93
112
  when SetProjectCommand
94
- client = cmd.optional if cmd.optional.present?
113
+ client = cmd.optional.shift if cmd.optional.present? && (/^--.*$/.match(cmd.optional.first)).blank?
95
114
  set_project(cmd.name, client)
96
115
  when SetClientCommand
97
116
  set_client(cmd.name)
98
117
  when StartCommand
99
118
  start(cmd.name)
119
+ when RenameCommand
120
+ rename(cmd.name)
100
121
  when PauseCommand
101
122
  if current_task.present?
102
123
  pause
@@ -112,6 +133,25 @@ module Rtt
112
133
  list(env_filters)
113
134
  when SetUserCommand
114
135
  set_user(cmd.name)
136
+ when DeleteCommand
137
+ delete(env_filters)
138
+ when ConfigureCommand
139
+ case cmd.name.downcase
140
+ when 'task'
141
+ update_task(cmd.optional, env_filters)
142
+ when 'project'
143
+ name = cmd.next_optional
144
+ client = cmd.next_optional
145
+ set_project(name, client, true)
146
+ when 'client'
147
+ name = cmd.next_optional
148
+ set_client(name, true)
149
+ when 'user'
150
+ name = cmd.next_optional
151
+ set_user(name, true)
152
+ else
153
+ raise CommandNotFoundError
154
+ end
115
155
  else
116
156
  raise CommandNotFoundError
117
157
  end
@@ -122,18 +162,18 @@ module Rtt
122
162
  when CommandNotFoundError
123
163
  return puts_usage
124
164
  when TaskNotStartedError
125
- puts "There is no active task. Pause is not valid at this point."
165
+ say "There is no active task. Pause is not valid at this point."
126
166
  end
127
167
  end
128
168
 
129
169
  def puts_usage
130
- puts
170
+ say('')
131
171
  File.open(File.join( File.dirname(__FILE__), '..', '..', "USAGE.txt")) do |file|
132
172
  while content = file.gets
133
- puts content
173
+ say content
134
174
  end
135
175
  end
136
- puts
176
+ say('')
137
177
  end
138
178
  end
139
179
  end