Class: Beastie::Issue
- Inherits:
-
Object
- Object
- Beastie::Issue
- Defined in:
- lib/beastie/issue.rb
Constant Summary collapse
- INPUT_F =
A default issue has:
-
title
-
status
-
created
-
component
-
priority
-
severity
-
points
-
type
-
description
Customizing the fields:
-
the fields aske by the new command are specified by the ISSUE_FIELDS variable
-
for each field, the structure if the following:
field name => input function, default value, promptwhere
-
“input function” is a function to ask a value to the user. Use an empty
string for a value which is filled automatically -
“default value” is the default value to assign to the field
-
“prompt” is what is asked to the user. Use an empty string for
a value which is filled automatically.
-
input function and default value are evaluated, so that computation can be performed
-
title, created, and status are compulsory: do not delete them (gen_filename depends upon title and created; the close command depends upon status)
-
0- DEFAULT =
1- PROMPT =
2- ISSUE_FIELDS =
{ "title" => ["Readline.readline", "'title'", "Short description of the issue"], "status" => ["", "'open'", ""], "created" => ["", "Date.today", ""], "component" => ["Readline.readline", "''", "Component affected by the issue"], "priority" => ["get_int", "3", "Priority (an integer number, e.g., from 1 to 5)"], "severity" => ["get_int", "3", "Severity (an integer number, e.g., from 1 to 5)"], "points" => ["get_int", "5", "Points (an integer estimating difficulty of fix)"], "type" => ["Readline.readline", "'bug'", "Type (e.g., story, task, bug, refactoring)"], "description" => ["get_lines", "''", "Longer description (terminate with '.')"] }
- REPORT_FIELDS =
which fields go to the report and formatting options
{ "status" => "%-10s", "type" => "%-12s", "priority" => "%8s", "severity" => "%8s", "created" => "%-10s", "title" => "%-30s" }
Instance Attribute Summary collapse
-
#dir ⇒ Object
readonly
the directory where all issues of this instance are stored.
-
#filename ⇒ Object
readonly
the filename of this issue.
-
#issue ⇒ Object
readonly
the values (a Hash) of this issue.
Instance Method Summary collapse
-
#ask ⇒ Object
interactively ask from command line all fields specified in ISSUE_FIELDS.
- #change(field, value) ⇒ Object
-
#count ⇒ Object
count all issues in current directory to get the maximum ID.
-
#full_filename ⇒ Object
return the full filename, if @filename is set (load, save, …).
- #id_to_full_filename(n) ⇒ Object
-
#initialize(directory) ⇒ Issue
constructor
A new instance of Issue.
-
#list(condition) ⇒ Object
list all issues in current directory.
-
#load(filename) ⇒ Object
load from command line.
-
#load_n(n) ⇒ Object
load by issue id.
-
#save ⇒ Object
save object to file.
-
#set_fields(title) ⇒ Object
initialize all fields with the default values (and set title to the argument).
Constructor Details
#initialize(directory) ⇒ Issue
Returns a new instance of Issue.
82 83 84 85 |
# File 'lib/beastie/issue.rb', line 82 def initialize directory @dir = directory @issue = Hash.new end |
Instance Attribute Details
#dir ⇒ Object (readonly)
the directory where all issues of this instance are stored
73 74 75 |
# File 'lib/beastie/issue.rb', line 73 def dir @dir end |
#filename ⇒ Object (readonly)
the filename of this issue. IT IS ALWAYS A BASENAME. @dir is added only when needed (e.g. load)
77 78 79 |
# File 'lib/beastie/issue.rb', line 77 def filename @filename end |
#issue ⇒ Object (readonly)
the values (a Hash) of this issue
80 81 82 |
# File 'lib/beastie/issue.rb', line 80 def issue @issue end |
Instance Method Details
#ask ⇒ Object
interactively ask from command line all fields specified in ISSUE_FIELDS
88 89 90 91 92 93 |
# File 'lib/beastie/issue.rb', line 88 def ask ISSUE_FIELDS.keys.each do |key| puts "#{ISSUE_FIELDS[key][PROMPT]}: " if ISSUE_FIELDS[key][PROMPT] != "" @issue[key] = (eval ISSUE_FIELDS[key][INPUT_F]) || (eval ISSUE_FIELDS[key][DEFAULT]) end end |
#change(field, value) ⇒ Object
104 105 106 |
# File 'lib/beastie/issue.rb', line 104 def change field, value @issue[field] = value end |
#count ⇒ Object
count all issues in current directory to get the maximum ID
140 141 142 |
# File 'lib/beastie/issue.rb', line 140 def count Dir.glob(File.join(@dir, '*.{yml,yaml}')).size end |
#full_filename ⇒ Object
return the full filename, if @filename is set (load, save, …)
127 128 129 |
# File 'lib/beastie/issue.rb', line 127 def full_filename File.join(@dir, @filename) end |
#id_to_full_filename(n) ⇒ Object
121 122 123 |
# File 'lib/beastie/issue.rb', line 121 def id_to_full_filename n Dir.glob(File.join(@dir, '*.{yml,yaml}'))[n - 1] end |
#list(condition) ⇒ Object
list all issues in current directory
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 |
# File 'lib/beastie/issue.rb', line 145 def list condition # print header printf "ID " REPORT_FIELDS.keys.each do |key| printf REPORT_FIELDS[key] + " ", key end printf "\n" # print issues file_no = 0 Dir.glob(File.join(@dir, '*.{yml,yaml}')) do |file| data = YAML.load_file(file) file_no += 1 # create a string with all the bindings assignments = "" REPORT_FIELDS.keys.each do |key| # not sure why, but using classes does not work.. # so I make them into strings case data[key].class.to_s when "Fixnum" assignments << "#{key} = #{data[key]};" when "String" assignments << "#{key} = '#{data[key]}';" when "Date" assignments << "#{key} = Date.parse('#{data[key]}');" end end if eval (assignments + condition) then printf "%3d ", file_no REPORT_FIELDS.keys.each do |key| printf REPORT_FIELDS[key] + " ", data[key] end printf "\n" end end end |
#load(filename) ⇒ Object
load from command line
109 110 111 112 |
# File 'lib/beastie/issue.rb', line 109 def load filename @filename = File.basename(filename) @issue = YAML.load_file(File.join(@dir, @filename)) end |
#load_n(n) ⇒ Object
load by issue id
117 118 119 |
# File 'lib/beastie/issue.rb', line 117 def load_n n load id_to_full_filename n end |
#save ⇒ Object
save object to file
132 133 134 135 136 137 |
# File 'lib/beastie/issue.rb', line 132 def save @filename = @filename || gen_filename file = File.open(File.join(@dir, @filename), 'w') { |f| f.puts @issue.to_yaml } end |
#set_fields(title) ⇒ Object
initialize all fields with the default values (and set title to the argument)
97 98 99 100 101 102 |
# File 'lib/beastie/issue.rb', line 97 def set_fields title ISSUE_FIELDS.keys.each do |k| @issue[k] = eval(ISSUE_FIELDS[k][DEFAULT]) end @issue['title'] = title end |