Class: IssueManager

Inherits:
Object
  • Object
show all
Includes:
TTYPromptHelper, TimeHelper
Defined in:
lib/devlogs/repository/issue_manager.rb

Overview

IssueManager is an abstraction class to orchestrate the internals of issue management and creation for a repository

Constant Summary collapse

VALID_DIRECTION =
%i[asc desc].freeze
ISSUE_SEPARATOR =
"__"

Constants included from TimeHelper

TimeHelper::TIME_FORMAT_FILE_PREFIX

Instance Method Summary collapse

Methods included from TimeHelper

#current_time

Methods included from TTYPromptHelper

#build_select_prompt

Constructor Details

#initialize(repo_config_store) ⇒ IssueManager

Returns a new instance of IssueManager.

Parameters:



21
22
23
# File 'lib/devlogs/repository/issue_manager.rb', line 21

def initialize(repo_config_store)
  @config_store = repo_config_store
end

Instance Method Details

#createObject

Adds a new entry to the repository



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/devlogs/repository/issue_manager.rb', line 64

def create
  info = issue_info_prompt

  issue = compose_issue(info)

  issue_file_path = File.join(@config_store.issue_dir_path, issue[:file_name])

  template = IssueTemplateRenderer.new(@config_store.issue_template_file_path, issue)

  unless File.exist?(issue_file_path)
    # Add default boiler plate if the file does not exist yet
    File.open(issue_file_path, "w") do |f|
      f.write template.render
    end

    increment_issue_index!
  end

  issue_file_path
end

#list(direction = :desc) ⇒ Object

Lists the issue entries present in the repository

Parameters:

  • direction (Symbol) (defaults to: :desc)

    ascending or descending

Raises:

  • (ArgumentError)


30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/devlogs/repository/issue_manager.rb', line 30

def list(direction = :desc)
  raise ArgumentError, "Must be one of: " + VALID_DIRECTION unless VALID_DIRECTION.include?(direction.to_sym)

  # Anything with the SHORTCODE- prefix
  #
  # i.e. RLP-1, RLP-2, et cetera
  #
  short_code_pattern = "#{config_values.short_code}-*"

  #
  # pattern: RLP-*
  #
  glob_pattern = File.join(@config_store.issue_dir_path, short_code_pattern)

  Dir.glob(glob_pattern).sort_by do |fpath|
    # i.e. [RLP-1, title_of_issue.md]
    issue_tag, = File.basename(fpath).split(ISSUE_SEPARATOR)

    # i.e. [RLP, 1]
    _, issue_num = issue_tag.split("-")

    if direction == :asc
      issue_num.to_i
    else
      -1 * issue_num.to_i
    end
  end
end