Module: Rtt
- Extended by:
- Rtt, CmdLineParser, QueryBuilder, ReportGenerator, Storage
- Included in:
- Rtt
- Defined in:
- lib/rtt.rb,
lib/rtt/storage.rb,
lib/rtt/query_builder.rb,
lib/rtt/cmd_line_parser.rb,
lib/rtt/report_generator.rb,
lib/rtt/interactive_configurator.rb
Defined Under Namespace
Modules: CmdLineParser, InteractiveConfigurator, QueryBuilder, ReportGenerator, Storage Classes: Command, CommandNotFoundError, ConfigureCommand, DeleteCommand, ExportCommand, ImportCommand, ParametersNotMatchCommandSignatureError, PauseCommand, QueryCommand, RenameCommand, ReportCommand, SetClientCommand, SetProjectCommand, SetUserCommand, StartCommand, StopCommand, TaskNotStartedError
Constant Summary collapse
- VERSION =
'0.0.6'
Constants included from ReportGenerator
ReportGenerator::DEFAULT_FILENAME, ReportGenerator::FIXED_FIELDS, ReportGenerator::FORMATS_ACCEPTED, ReportGenerator::REPORT_FIELDS, ReportGenerator::REPORT_FIELD_OUTPUT
Constants included from CmdLineParser
CmdLineParser::COMMAND_MAPPING
Instance Attribute Summary
Attributes included from ReportGenerator
Class Method Summary collapse
- .current_client ⇒ Object
- .current_project ⇒ Object
- .current_task ⇒ Object
- .current_user ⇒ Object
- .delete(options = {}) ⇒ Object
-
.list(options = {}) ⇒ Object
Lists all entries filtered by parameters.
-
.pause ⇒ Object
Used to set the client at system level.
-
.rename(task_name) ⇒ Object
Change the name of the current task.
-
.set_client(name = nil, configure = false) ⇒ Object
Used to set the client at system level.
- .set_project(project_name = nil, client_name = nil, configure = false) ⇒ Object
- .set_user(nickname = nil, configure = false) ⇒ Object
-
.start(task_name = nil) ⇒ Object
Starts a new timer.
-
.stop ⇒ Object
Stops the current task.
- .update_task(name, conditions) ⇒ Object
Methods included from Storage
config, database_file, export, import, init, tables_exists?
Methods included from ReportGenerator
column_widths, custom_user_is_defined?, fill_user_information, fixed_fields_for_current_data, fixed_value, full_path, has_default_value?, report
Methods included from QueryBuilder
Methods included from CmdLineParser
capture, env_filters, env_variable, execute, execute_single, handle_error, puts_usage
Class Method Details
.current_client ⇒ Object
153 154 155 |
# File 'lib/rtt.rb', line 153 def current_client Client.where(:active => true).first end |
.current_project ⇒ Object
157 158 159 |
# File 'lib/rtt.rb', line 157 def current_project Project.where(:active => true).first end |
.current_task ⇒ Object
161 162 163 |
# File 'lib/rtt.rb', line 161 def current_task Task.where(:active => true).first end |
.current_user ⇒ Object
27 28 29 30 31 |
# File 'lib/rtt.rb', line 27 def current_user active = User.where(:active => true).first return active if active.present? User.find_or_create_active end |
.delete(options = {}) ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/rtt.rb', line 33 def delete( = {}) if current_task && .blank? current_task.destroy else query().map(&:destroy) end end |
.list(options = {}) ⇒ Object
Lists all entries filtered by parameters
For example:
Rtt.list :from => '2010-5-3', :to => '2010-5-20'
75 76 77 78 79 80 81 |
# File 'lib/rtt.rb', line 75 def list = {} say 'Task List' say '=========' query().each do |task| say "Task: #{task.name} || Client: #{task.client.name} || Project: #{task.project.name} || User: #{task.user.nickname} || Elapsed time: #{task.duration} #{'[ACTIVE]' if task.active} \n" end end |
.pause ⇒ Object
Used to set the client at system level.
Usage
pause
89 90 91 |
# File 'lib/rtt.rb', line 89 def pause current_task.pause if current_task end |
.rename(task_name) ⇒ Object
Change the name of the current task.
Usage
rename ‘new_timer_name’ => Doesn’t change task#start_at
62 63 64 65 66 67 68 |
# File 'lib/rtt.rb', line 62 def rename task_name task = current_task if task task.name = task_name task.save end end |
.set_client(name = nil, configure = false) ⇒ Object
Used to set the client at system level.
Usage
set_client name
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/rtt.rb', line 99 def set_client(name = nil, configure = false) if name.blank? || configure extend(InteractiveConfigurator) configure_client(name) else raise ParametersNotMatchCommandSignatureError if name.blank? deactivate_current_client if current_client client = client(name) unless client.active client.activate else client.save end end end |
.set_project(project_name = nil, client_name = nil, configure = false) ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/rtt.rb', line 115 def set_project(project_name = nil, client_name = nil, configure = false) if project_name.blank? || configure extend(InteractiveConfigurator) configure_project(project_name, client_name) else raise ParametersNotMatchCommandSignatureError if project_name.blank? deactivate_current_project if current_project client = client(client_name) unless client_name.nil? project = Project.find_or_create_by_name project_name project.client = client project.description = project_name unless project.active project.activate else project.save end end end |
.set_user(nickname = nil, configure = false) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/rtt.rb', line 41 def set_user(nickname = nil, configure = false) user = if nickname.blank? current_user else User.where(:nickname => nickname).first end current_user.deactivate if current_user if user.blank? || configure extend(InteractiveConfigurator) configure_user(nickname) else user.activate end end |
.start(task_name = nil) ⇒ Object
Starts a new timer. It stops the current task if there is any.
Usage
start a time new:
start ‘new_task’ TODO: Make it start PAUSED TASKS!
142 143 144 145 |
# File 'lib/rtt.rb', line 142 def start(task_name = nil) current_task.stop if current_task.present? && task_name.present? Task::task(task_name).start end |
.stop ⇒ Object
Stops the current task.
149 150 151 |
# File 'lib/rtt.rb', line 149 def stop current_task.stop if current_task end |
.update_task(name, conditions) ⇒ Object
22 23 24 25 |
# File 'lib/rtt.rb', line 22 def update_task(name, conditions) extend(InteractiveConfigurator) configure_task(name, conditions) end |