class JiraCache::Data::IssueRepository
Superclass for repositories. Simply provide some shared methods.
Public Class Methods
count()
click to toggle source
# File lib/jira_cache/data/issue_repository.rb, line 85 def self.count table.count end
delete_where(where_data)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# File lib/jira_cache/data/issue_repository.rb, line 77 def self.first_where(where_data) table.where(where_data).first end
index()
click to toggle source
# 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)
click to toggle source
It inserts a new issue row with the specified data. If the issue already exists (checking on the “key”), the row is updated instead.
# 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()
click to toggle source
# 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()
click to toggle source
# 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()
click to toggle source
# 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)
click to toggle source
# 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()
click to toggle source
# 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)
click to toggle source
# 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()
click to toggle source
# File lib/jira_cache/data/issue_repository.rb, line 101 def self.table DB[:jira_cache_issues] end
update_where(where_data, values)
click to toggle source
# File lib/jira_cache/data/issue_repository.rb, line 73 def self.update_where(where_data, values) table.where(where_data).update(values) end