Class: JiraCache::Data::IssueRepository
- Inherits:
-
Object
- Object
- JiraCache::Data::IssueRepository
- Defined in:
- lib/jira_cache/data/issue_repository.rb
Overview
Superclass for repositories. Simply provide some shared methods.
Class Method Summary collapse
- .count ⇒ Object
- .delete_where(where_data) ⇒ Object
- .exist_with_key?(key) ⇒ Boolean
- .find_by_key(key) ⇒ Object
- .first_where(where_data) ⇒ Object
- .index ⇒ Object
-
.insert(key:, data:, synced_at:, deleted_from_jira_at: nil) ⇒ Object
It inserts a new issue row with the specified data.
- .keys_for_deleted_issues ⇒ Object
- .keys_for_non_deleted_issues ⇒ Object
- .keys_in_all_projects ⇒ Object
- .keys_in_project(project_key) ⇒ Object
- .latest_sync_time ⇒ Object
- .row(attributes, time = nil) ⇒ Object
- .table ⇒ Object
- .update_where(where_data, values) ⇒ Object
Class Method Details
.count ⇒ Object
85 86 87 |
# File 'lib/jira_cache/data/issue_repository.rb', line 85 def self.count table.count end |
.delete_where(where_data) ⇒ Object
69 70 71 |
# File 'lib/jira_cache/data/issue_repository.rb', line 69 def self.delete_where(where_data) table.where(where_data).delete end |
.exist_with_key?(key) ⇒ Boolean
33 34 35 |
# File 'lib/jira_cache/data/issue_repository.rb', line 33 def self.exist_with_key?(key) table.where(key: key).count != 0 end |
.find_by_key(key) ⇒ Object
29 30 31 |
# File 'lib/jira_cache/data/issue_repository.rb', line 29 def self.find_by_key(key) table.where(key: key).first end |
.first_where(where_data) ⇒ Object
77 78 79 |
# File 'lib/jira_cache/data/issue_repository.rb', line 77 def self.first_where(where_data) table.where(where_data).first end |
.index ⇒ Object
81 82 83 |
# File 'lib/jira_cache/data/issue_repository.rb', line 81 def self.index table.entries end |
.insert(key:, data:, synced_at:, deleted_from_jira_at: nil) ⇒ Object
It inserts a new issue row with the specified data. If the issue already exists (checking on the “key”), the row is updated instead.
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/jira_cache/data/issue_repository.rb', line 15 def self.insert(key:, data:, synced_at:, deleted_from_jira_at: nil) attributes = { key: key, data: Sequel.pg_json(data), synced_at: synced_at, deleted_from_jira_at: deleted_from_jira_at } if exist_with_key?(key) update_where({ key: key }, attributes) else table.insert row(attributes) end end |
.keys_for_deleted_issues ⇒ Object
61 62 63 64 65 66 67 |
# File 'lib/jira_cache/data/issue_repository.rb', line 61 def self.keys_for_deleted_issues table .where("deleted_from_jira_at IS NOT NULL") .select(:key) .map(&:values) .flatten end |
.keys_for_non_deleted_issues ⇒ Object
53 54 55 56 57 58 59 |
# File 'lib/jira_cache/data/issue_repository.rb', line 53 def self.keys_for_non_deleted_issues table .where("deleted_from_jira_at IS NULL") .select(:key) .map(&:values) .flatten end |
.keys_in_all_projects ⇒ Object
46 47 48 49 50 51 |
# File 'lib/jira_cache/data/issue_repository.rb', line 46 def self.keys_in_all_projects table. select(:key). map(&:values). flatten end |
.keys_in_project(project_key) ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/jira_cache/data/issue_repository.rb', line 37 def self.keys_in_project(project_key) return keys_in_all_projects if project_key.nil? table. where("(data #>> '{fields,project,key}') = ?", project_key). select(:key). map(&:values). flatten end |
.latest_sync_time ⇒ Object
89 90 91 |
# File 'lib/jira_cache/data/issue_repository.rb', line 89 def self.latest_sync_time table.order(:synced_at).select(:synced_at).last&.dig(:synced_at) end |
.row(attributes, time = nil) ⇒ Object
93 94 95 96 97 98 99 |
# File 'lib/jira_cache/data/issue_repository.rb', line 93 def self.row(attributes, time = nil) time ||= Time.now attributes.merge( created_at: time, updated_at: time ) end |
.table ⇒ Object
101 102 103 |
# File 'lib/jira_cache/data/issue_repository.rb', line 101 def self.table DB[:jira_cache_issues] end |
.update_where(where_data, values) ⇒ Object
73 74 75 |
# File 'lib/jira_cache/data/issue_repository.rb', line 73 def self.update_where(where_data, values) table.where(where_data).update(values) end |