class Torque::Settings

Stores all of the settings for a release notes generation

Attributes

accept_from[R]

The accept-from date. All stories accepted on Pivotal Tracker before this date will be ignored

accept_to[R]

The accept-to date. All stories accepted on Pivotal Tracker after this date will be ignored

current_notes_path[R]

The path to the most recently generated notes

custom[R]

True if should treat this run as a custom run, else false

custom_date_range[R]

True if a custom date range is being used (set manually through the command line), false if using the default one

email[R]

True if should send the notes to the email list after notes are generated, else false

email_address[R]

The email address from which to send notes

email_password[R]

The password to the email address from which to send notes

email_to[R]

A list of email addresses to send the notes to

filter_string[R]

A string representing the current filter

filters[R]

A list of field filters in use

filters_on[R]

True if field filters are being used for stories, else false

format_string[R]

The FormatString object to use to generate notes

iterations[R]

The number of iterations of the project to generate notes for, or nil if not using iterations

last_run_path[R]

The path to the .last-run file in the records directory

output_dir[R]

The output directory to use

project[R]

The Pivotal Tracker project ID to use

record_path[R]

The path to the record file of the notes

root_dir[R]

The path to the root directory (the directory which contains a .torqueinfo.yaml file)

silent[R]

True if should silence all output, else false

token[R]

The Pivotal Tracker api token to use to access the Pivotal project

torque_info_path[R]

The path to the .torqueinfo.yaml file

verbose[R]

True if should be verbose, else false

Public Class Methods

new(options={}, fs=FileSystem.new) click to toggle source

@param options A hash of the options used to run the program @param fs An instance of the FileSystem class

Determines the project settings from the environment

# File lib/torque/settings.rb, line 114
def initialize(options={}, fs=FileSystem.new)

  @options = options
  @fs = fs

  # Initializes the root directory for Torque

  @root_dir = @options[:root_dir] || "."
  @root_dir = File.expand_path(@root_dir)

  # Handles basic options

  @email = @options[:email] || false
  @silent = @options[:silent] || false
  @verbose = @options[:verbose] || false

  # Parses story filters from the options

  @filters = []
  
  @filters << FieldFilter.new(:label, @options[:label]) if @options[:label]
  @filters << FieldFilter.new(:owner, @options[:owner]) if @options[:owner]
  @filters << FieldFilter.new(:type, @options[:type])  if @options[:type]

  @filters_on = !@filters.empty?

  @filter_string = @filters.map {|f| f.to_s}.join ", "

  # Parses and processes data from .torqueinfo.yaml

  @torque_info_path = "#{@root_dir}/.torqueinfo.yaml"
  torque_info = TorqueInfoParser.new(torque_info_path).parse
  
  @email_address = torque_info.email_address
  @email_password = torque_info.email_password
  email_to_raw = torque_info.email_to
  format_string_raw = torque_info.format
  output_dir_raw = torque_info.output_dir
  @project = torque_info.project
  @token = torque_info.token

  if    email_to_raw.class == NilClass; @email_to = []
  elsif email_to_raw.class == String;   @email_to = [email_to_raw]
  elsif email_to_raw.class == Array;    @email_to = email_to_raw
  else; raise "Unknown parsing error on .torqueinfo.yaml's 'email_to' field: #{@email_to}"
  end

  @format_string = Torque::FormatString.new(format_string_raw)

  output_dir_raw = "release_notes" if output_dir_raw.blank?
  @output_dir = "#{@root_dir}/#{output_dir_raw}"

  raise MissingTokenError.new(
    "API token for Pivotal Tracker has not been set"
    ) if @token.blank?
  raise MissingProjectError.new(
    "Project ID for Pivotal Tracker has not been set"
    ) if @project.blank?

  # Sets up the output directory, throwing an error if it cannot be found

  if !@fs.path_exist? @output_dir
    raise MissingOutputDirectoryError.new(
      "Could not find the output directory: #{@output_dir}"
    )
  elsif !@fs.path_exist? "#{@output_dir}/previous"
    @fs.mkdir_p("#{@output_dir}/previous")
  end
  
  # The path to the last-run file for this project
  
  @last_run_path = "#{output_dir}/previous/.last-run-#{project}"

  # Determines the date range within which to accept stories
  
  date_settings = DateSettings.new(@options, @last_run_path, @fs)
  @accept_from, @accept_to = date_settings.get_dates
  @custom_date_range = date_settings.custom_date_range?

  # Determines the number of iterations to generate for, throwing an error if it is invalid

  @iterations = @options[:iterations]

  if @iterations
    begin
      @iterations = Integer(@iterations)
      raise ArgumentError.new if @iterations <= 0
    rescue ArgumentError
      raise ArgumentError.new "Invalid number of iterations: #{@iterations}"
    end
  end

  # Sets the path to the main "release-notes.txt" file
  
  @current_notes_path = "#{output_dir}/release-notes.txt"

  # Determines whether to treat this run as a custom or a default run

  @custom = @custom_date_range || @filters_on

  # Determines the path name to use for the record of the output file
  
  record_pathname_settings = RecordPathnameSettings.new(@output_dir, @project, @custom, @iterations, @fs)
  @record_path = record_pathname_settings.get_path

end