Class: TogglCache::Data::ReportRepository
- Inherits:
-
Object
- Object
- TogglCache::Data::ReportRepository
- Defined in:
- lib/toggl_cache/data/report_repository.rb
Overview
Repository for Toggl reports.
TODO: should be used through instances TODO: #table should be private
Constant Summary collapse
- MAPPED_REPORT_ATTRIBUTES =
%w( description pid project uid user task tid ).freeze
Instance Method Summary collapse
- #count ⇒ Object
-
#create_or_update(report) ⇒ Object
It inserts a new issue row with the specified data.
- #delete_starting(time_since:, time_until:) ⇒ Object
- #delete_where(where_data) ⇒ Object
- #exist_with_id?(id) ⇒ Boolean
- #find_by_id(id) ⇒ Object
- #first(by: :start) ⇒ Object
- #first_where(where_data) ⇒ Object
- #index ⇒ Object
-
#starting(time_since:, time_until:) ⇒ Object
Returns reports whose
starttime is within the specified range. - #update_where(where_data, values) ⇒ Object
- #where(project_id:, task_id: nil) ⇒ Object
Instance Method Details
#count ⇒ Object
64 65 66 |
# File 'lib/toggl_cache/data/report_repository.rb', line 64 def count table.count end |
#create_or_update(report) ⇒ Object
It inserts a new issue row with the specified data. If the issue already exists (unicity key is id) the row is updated instead.
27 28 29 30 31 32 33 34 |
# File 'lib/toggl_cache/data/report_repository.rb', line 27 def create_or_update(report) id = report["id"].to_s if exist_with_id?(id) update_where({ id: id }, row(report: report)) else table.insert row(report: report, insert_created_at: true) end end |
#delete_starting(time_since:, time_until:) ⇒ Object
76 77 78 |
# File 'lib/toggl_cache/data/report_repository.rb', line 76 def delete_starting(time_since:, time_until:) table.where("start >= ? AND start <= ?", time_since, time_until).delete end |
#delete_where(where_data) ⇒ Object
44 45 46 |
# File 'lib/toggl_cache/data/report_repository.rb', line 44 def delete_where(where_data) table.where(where_data).delete end |
#exist_with_id?(id) ⇒ Boolean
40 41 42 |
# File 'lib/toggl_cache/data/report_repository.rb', line 40 def exist_with_id?(id) table.where(id: id).count != 0 end |
#find_by_id(id) ⇒ Object
36 37 38 |
# File 'lib/toggl_cache/data/report_repository.rb', line 36 def find_by_id(id) table.where(id: id).first end |
#first(by: :start) ⇒ Object
52 53 54 |
# File 'lib/toggl_cache/data/report_repository.rb', line 52 def first(by: :start) table.order(by).first end |
#first_where(where_data) ⇒ Object
56 57 58 |
# File 'lib/toggl_cache/data/report_repository.rb', line 56 def first_where(where_data) table.where(where_data).first end |
#index ⇒ Object
60 61 62 |
# File 'lib/toggl_cache/data/report_repository.rb', line 60 def index table.entries end |
#starting(time_since:, time_until:) ⇒ Object
Returns reports whose start time is within the specified range.
72 73 74 |
# File 'lib/toggl_cache/data/report_repository.rb', line 72 def starting(time_since:, time_until:) table.where("start >= ? AND start <= ?", time_since, time_until).entries end |
#update_where(where_data, values) ⇒ Object
48 49 50 |
# File 'lib/toggl_cache/data/report_repository.rb', line 48 def update_where(where_data, values) table.where(where_data).update(values) end |
#where(project_id:, task_id: nil) ⇒ Object
82 83 84 85 86 |
# File 'lib/toggl_cache/data/report_repository.rb', line 82 def where(project_id:, task_id: nil) where_criteria = { pid: project_id } where_criteria[:tid] = tid if task_id table.where(where_criteria).entries end |