Class: Torque::Settings
- Inherits:
-
Object
- Object
- Torque::Settings
- Defined in:
- lib/torque/settings.rb
Overview
Stores all of the settings for a release notes generation
Instance Attribute Summary collapse
-
#accept_from ⇒ Object
readonly
The accept-from date.
-
#accept_to ⇒ Object
readonly
The accept-to date.
-
#current_notes_path ⇒ Object
readonly
The path to the most recently generated notes.
-
#custom ⇒ Object
readonly
True if should treat this run as a custom run, else false.
-
#custom_date_range ⇒ Object
readonly
True if a custom date range is being used (set manually through the command line), false if using the default one.
-
#email ⇒ Object
readonly
True if should send the notes to the email list after notes are generated, else false.
-
#email_address ⇒ Object
readonly
The email address from which to send notes.
-
#email_password ⇒ Object
readonly
The password to the email address from which to send notes.
-
#email_to ⇒ Object
readonly
A list of email addresses to send the notes to.
-
#filter_string ⇒ Object
readonly
A string representing the current filter.
-
#filters ⇒ Object
readonly
A list of field filters in use.
-
#filters_on ⇒ Object
readonly
True if field filters are being used for stories, else false.
-
#format_string ⇒ Object
readonly
The FormatString object to use to generate notes.
-
#iterations ⇒ Object
readonly
The number of iterations of the project to generate notes for, or nil if not using iterations.
-
#last_run_path ⇒ Object
readonly
The path to the .last-run file in the records directory.
-
#output_dir ⇒ Object
readonly
The output directory to use.
-
#project ⇒ Object
readonly
The Pivotal Tracker project ID to use.
-
#record_path ⇒ Object
readonly
The path to the record file of the notes.
-
#root_dir ⇒ Object
readonly
The path to the root directory (the directory which contains a .torqueinfo.yaml file).
-
#silent ⇒ Object
readonly
True if should silence all output, else false.
-
#token ⇒ Object
readonly
The Pivotal Tracker api token to use to access the Pivotal project.
-
#torque_info_path ⇒ Object
readonly
The path to the .torqueinfo.yaml file.
-
#verbose ⇒ Object
readonly
True if should be verbose, else false.
Instance Method Summary collapse
-
#initialize(options = {}, fs = FileSystem.new) ⇒ Settings
constructor
Determines the project settings from the environment.
Constructor Details
#initialize(options = {}, fs = FileSystem.new) ⇒ Settings
Determines the project settings from the environment
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 |
# File 'lib/torque/settings.rb', line 114 def initialize(={}, fs=FileSystem.new) @options = @fs = fs # Initializes the root directory for Torque @root_dir = @options[:root_dir] || "." @root_dir = File.(@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 |
Instance Attribute Details
#accept_from ⇒ Object (readonly)
The accept-from date. All stories accepted on Pivotal Tracker before this date will be ignored
20 21 22 |
# File 'lib/torque/settings.rb', line 20 def accept_from @accept_from end |
#accept_to ⇒ Object (readonly)
The accept-to date. All stories accepted on Pivotal Tracker after this date will be ignored
24 25 26 |
# File 'lib/torque/settings.rb', line 24 def accept_to @accept_to end |
#current_notes_path ⇒ Object (readonly)
The path to the most recently generated notes
28 29 30 |
# File 'lib/torque/settings.rb', line 28 def current_notes_path @current_notes_path end |
#custom ⇒ Object (readonly)
True if should treat this run as a custom run, else false
32 33 34 |
# File 'lib/torque/settings.rb', line 32 def custom @custom end |
#custom_date_range ⇒ Object (readonly)
True if a custom date range is being used (set manually through the command line), false if using the default one
36 37 38 |
# File 'lib/torque/settings.rb', line 36 def custom_date_range @custom_date_range end |
#email ⇒ Object (readonly)
True if should send the notes to the email list after notes are generated, else false
40 41 42 |
# File 'lib/torque/settings.rb', line 40 def email @email end |
#email_address ⇒ Object (readonly)
The email address from which to send notes
44 45 46 |
# File 'lib/torque/settings.rb', line 44 def email_address @email_address end |
#email_password ⇒ Object (readonly)
The password to the email address from which to send notes
48 49 50 |
# File 'lib/torque/settings.rb', line 48 def email_password @email_password end |
#email_to ⇒ Object (readonly)
A list of email addresses to send the notes to
52 53 54 |
# File 'lib/torque/settings.rb', line 52 def email_to @email_to end |
#filter_string ⇒ Object (readonly)
A string representing the current filter
56 57 58 |
# File 'lib/torque/settings.rb', line 56 def filter_string @filter_string end |
#filters ⇒ Object (readonly)
A list of field filters in use
60 61 62 |
# File 'lib/torque/settings.rb', line 60 def filters @filters end |
#filters_on ⇒ Object (readonly)
True if field filters are being used for stories, else false
64 65 66 |
# File 'lib/torque/settings.rb', line 64 def filters_on @filters_on end |
#format_string ⇒ Object (readonly)
The FormatString object to use to generate notes
68 69 70 |
# File 'lib/torque/settings.rb', line 68 def format_string @format_string end |
#iterations ⇒ Object (readonly)
The number of iterations of the project to generate notes for, or nil if not using iterations
72 73 74 |
# File 'lib/torque/settings.rb', line 72 def iterations @iterations end |
#last_run_path ⇒ Object (readonly)
The path to the .last-run file in the records directory
76 77 78 |
# File 'lib/torque/settings.rb', line 76 def last_run_path @last_run_path end |
#output_dir ⇒ Object (readonly)
The output directory to use
84 85 86 |
# File 'lib/torque/settings.rb', line 84 def output_dir @output_dir end |
#project ⇒ Object (readonly)
The Pivotal Tracker project ID to use
80 81 82 |
# File 'lib/torque/settings.rb', line 80 def project @project end |
#record_path ⇒ Object (readonly)
The path to the record file of the notes
88 89 90 |
# File 'lib/torque/settings.rb', line 88 def record_path @record_path end |
#root_dir ⇒ Object (readonly)
The path to the root directory (the directory which contains a .torqueinfo.yaml file)
92 93 94 |
# File 'lib/torque/settings.rb', line 92 def root_dir @root_dir end |
#silent ⇒ Object (readonly)
True if should silence all output, else false
96 97 98 |
# File 'lib/torque/settings.rb', line 96 def silent @silent end |
#token ⇒ Object (readonly)
The Pivotal Tracker api token to use to access the Pivotal project
100 101 102 |
# File 'lib/torque/settings.rb', line 100 def token @token end |
#torque_info_path ⇒ Object (readonly)
The path to the .torqueinfo.yaml file
104 105 106 |
# File 'lib/torque/settings.rb', line 104 def torque_info_path @torque_info_path end |
#verbose ⇒ Object (readonly)
True if should be verbose, else false
108 109 110 |
# File 'lib/torque/settings.rb', line 108 def verbose @verbose end |