Class: RepoTimeline
- Inherits:
-
Object
- Object
- RepoTimeline
- Defined in:
- lib/repo_timetracker/repo_timeline.rb,
lib/repo_timetracker/repo_timeline_class.rb
Class Method Summary collapse
Instance Method Summary collapse
- #add_event(event_string) ⇒ Object
- #current_commit_time ⇒ Object
-
#initialize(repo_directory) ⇒ RepoTimeline
constructor
A new instance of RepoTimeline.
- #project_time ⇒ Object
- #watch_for_file_change_events ⇒ Object
Constructor Details
#initialize(repo_directory) ⇒ RepoTimeline
Returns a new instance of RepoTimeline.
8 9 10 11 12 13 14 |
# File 'lib/repo_timetracker/repo_timeline.rb', line 8 def initialize(repo_directory) @repo_directory = repo_directory.sub(/\/$/, '') #no trailing slash @project_name = @repo_directory.slice(/[^\/]*$/) @timeline_directory = initialize_timeline_directory_for(@repo_directory) @commit_records = load_commit_records end |
Class Method Details
.find_in_or_above(directory) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/repo_timetracker/repo_timeline_class.rb', line 11 def find_in_or_above(directory) return nil if directory.nil? if contains_repo? directory directory elsif directory.slice!(/\/\w+(\/?)$/) find_in_or_above(directory) else nil end end |
.load_or_initialize_for(directory_called_from) ⇒ Object
4 5 6 7 8 9 |
# File 'lib/repo_timetracker/repo_timeline_class.rb', line 4 def load_or_initialize_for(directory_called_from) directory = find_in_or_above(directory_called_from) return nil if directory.nil? RepoTimeline.new(directory) end |
Instance Method Details
#add_event(event_string) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/repo_timetracker/repo_timeline.rb', line 16 def add_event(event_string) case event_string when /git commit --amend/ amend(event_string) when /git commit/ commit(event_string) else staging.generate_new_event(event_string) end end |
#current_commit_time ⇒ Object
29 30 31 |
# File 'lib/repo_timetracker/repo_timeline.rb', line 29 def current_commit_time staging.total_time end |
#project_time ⇒ Object
33 34 35 36 37 38 |
# File 'lib/repo_timetracker/repo_timeline.rb', line 33 def project_time time = 0 @commit_records.inject(0) { |total_time, cr| total_time + cr.total_time } end |
#watch_for_file_change_events ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/repo_timetracker/repo_timeline.rb', line 40 def watch_for_file_change_events if defined? Process.daemon kill_previous_commit_timeline_process Process.daemon FileWatcher.new([@repo_directory]).watch do |filename| staging.generate_new_event("File changed: #{filename}") end end end |