class GitStoryid::Configuration

Constants

FILENAME

Public Class Methods

build() click to toggle source
# File lib/git_storyid.rb, line 150
def self.build
  load_config
  ensure_full_config
  TRACKER_CONFIG[engine][:class].new(@config)
end
engine() click to toggle source
# File lib/git_storyid.rb, line 162
def engine
  e = @config[:engine]
  e ? e.to_sym : nil
end
ensure_full_config() click to toggle source
# File lib/git_storyid.rb, line 167
def ensure_full_config
  @config[:engine] = read_configuration_value("Engine (pivotal/jira)") unless engine
  tracker_config = TRACKER_CONFIG[engine]

  return if tracker_config && @config.keys.sort == (tracker_config[:options].keys + [:engine]).sort

  tracker_config[:options].each do |key, label|
    @config[key] = read_configuration_value(label, key == :password)
  end

  File.open(project_config_path, "w") do |file|
    file.write YAML.dump(@config)
  end
  output "Writing config to #{project_config_path}"
end
find_project_config() click to toggle source
# File lib/git_storyid.rb, line 207
def find_project_config
  dirs = File.split(Dir.pwd)
  until dirs.empty? || File.exists?(File.join(dirs, FILENAME))
    dirs.pop
  end
  unless dirs.empty?
    File.join(dirs, FILENAME)
  else
    File.join(Dir.pwd, FILENAME)
  end
end
load_config() click to toggle source
# File lib/git_storyid.rb, line 158
def load_config
  @config ||= load_config_from
end
load_config_from() click to toggle source
# File lib/git_storyid.rb, line 195
def load_config_from
  return {} unless project_config_path
  if File.exists?(project_config_path)
    YAML.load(File.read(project_config_path)) || {}
  else
    {}
  end
end
new(config) click to toggle source
# File lib/git_storyid.rb, line 220
def initialize(config)
  @config = config
  setup_api_client
end
output(message) click to toggle source
# File lib/git_storyid.rb, line 235
def self.output(message)
  GitStoryid.output(message)
end
project_config_path() click to toggle source
# File lib/git_storyid.rb, line 204
def project_config_path
  @project_config_path ||= find_project_config
end
read_configuration_value(label, hidden = false) click to toggle source
# File lib/git_storyid.rb, line 183
def read_configuration_value(label, hidden = false)
  label = "#{label}: "
  if hidden
    print label
    password = STDIN.noecho(&:gets).chomp
    puts ''
    password
  else
    Readline.readline(label, true)
  end
end

Public Instance Methods

all_stories() click to toggle source
# File lib/git_storyid.rb, line 225
def all_stories
  @all_stories ||= fetch_all_stories.map do |story|
    serialize_issue(story)
  end
end
reset() click to toggle source
# File lib/git_storyid.rb, line 231
def reset
  @all_stories = nil
end