Skip to content

Commit

Permalink
implement list method
Browse files Browse the repository at this point in the history
  • Loading branch information
GrantBirki committed Nov 28, 2024
1 parent 1b27539 commit 40021e9
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
4 changes: 4 additions & 0 deletions lib/issue_db.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ def delete(key, options = {})
db.delete(key, options)
end

def list(options = {})
db.list(options)
end

def list_keys(options = {})
db.list_keys(options)
end
Expand Down
27 changes: 26 additions & 1 deletion lib/issue_db/database.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ def delete(key, options = {})

# List all keys in the database
# This will return an array of strings that represent the issue titles that are "keys" in the database
# :param: options [Hash] a hash of options to pass through to the search method
# :return: An array of strings that represent the issue titles that are "keys" in the database
# usage example:
# options = {include_closed: true}
# keys = db.list_keys(options)
def list_keys(options = {})
keys = issues.select do |issue|
options[:include_closed] || issue[:state] == "open"
Expand All @@ -99,14 +104,34 @@ def list_keys(options = {})
return keys
end

# List all issues/record in the database as Record objects (parsed)
# This will return an array of Record objects that represent the issues in the database
# :param: options [Hash] a hash of options to pass through to the search method
# :return: An array of Record objects that represent the issues in the database
# usage example:
# options = {include_closed: true}
# records = db.list(options)
def list(options = {})
records = issues.select do |issue|
options[:include_closed] || issue[:state] == "open"
end.map do |issue|
Record.new(issue)
end

return records
end

# Force a refresh of the issues cache
# This will update the issues cache with the latest issues from the repo
# :return: The updated issue cache as a list of issues (Hash objects not parsed)
def refresh!
update_issue_cache!
end

protected

def not_found!(key)
raise RecordNotFound, "no issue found for key: #{key}"
raise RecordNotFound, "no record found for key: #{key}"
end

# A helper method to search through the issues cache and return the first issue that matches the given key
Expand Down

0 comments on commit 40021e9

Please sign in to comment.