Time tracking your any model.
- Ruby on Rails (Active Record) >= 4.0.0
# Gemfile
gem 'acts_as_time_trackable', github: 'ruffnote/acts_as_time_trackable'
$ bundle
$ rails g time_trackable
$ rake db:migrate
Allow a model to be time tracked:
class Task < ActiveRecord::Base
acts_as_time_trackable
end
Allow a model to be a time tracker:
class User < ActiveRecord::Base
acts_as_time_tracker
end
Init
@task = Task.create
@task.time_trackable? # => true
@user = User.create
@user.time_tracker? # => true
@task.time_tracking? # => false
@user.time_tracking? # => false
@task.time_trackers # => []
@user.time_trackable # => nil
Start
@user.start_time_track(@task)
@task.time_tracking? # => true
@task.time_tracking?(@user) # => true
@user.time_tracking? # => true
@user.time_tracking?(@task) # => true
@task.time_trackers # => [@user]
@user.time_trackable # => @task
Stop
@user.stop_time_track
@task.time_tracking? # => false
@user.time_tracking? # => false
@task.time_trackers # => []
@user.time_trackable # => nil
Logs
@time_entry = @task.time_entries.first
(@time_entry = @user.time_entries.first)
@time_entry.time_trackable # => @task
@time_entry.time_tracker # => @user
@time_entry.started_at # => datetime
@time_entry.stopped_at # => datetime
@time_entry.duration # => stopped_at - started_at
@time_entry.formatted_duration # => '00:00:01'
TimeEntry.time_tracking.first # => @time_entry
@time_entry.stop
TimeEntry.stopped.first # => @time_entry
$ cd test/dummy/
$ bin/rake db:create db:migrate
$ cd ../../
$ rake
MIT