Class: DitzStr::Issue

Inherits:
ModelObject show all
Defined in:
lib/ditzstr/model-objects.rb

Defined Under Namespace

Classes: Error

Constant Summary collapse

INTERPOLATED_FIELDS =

these are the fields we interpolate issue names on

[:title, :desc, :log_events]
STATUS_SORT_ORDER =
{ :unstarted => 2, :paused => 1, :in_progress => 0, :closed => 3 }
STATUS_WIDGET =
{ :unstarted => "_", :in_progress => ">", :paused => "=", :closed => "x" }
DISPOSITIONS =
[ :fixed, :wontfix, :reorg ]
TYPES =
[ :bugfix, :feature, :task ]
TYPE_ORDER =
{ :bugfix => 0, :feature => 1, :task => 2 }
TYPE_LETTER =
{ 'b' => :bugfix, 'f' => :feature, 't' => :task }
STATUSES =
STATUS_WIDGET.keys
STATUS_STRINGS =
{ :in_progress => "in progress", :wontfix => "won't fix" }
DISPOSITION_STRINGS =
{ :wontfix => "won't fix", :reorg => "reorganized" }

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from ModelObject

#changed!, #changed?, changes_are_logged, create, create_interactively, #each_modelobject, field, field_names, from, inherited, #initialize, #inspect, #log, #save!, #to_s, #to_yaml, #to_yaml_type, #unchanged!, yaml_domain, yaml_other_thing

Constructor Details

This class inherits a constructor from DitzStr::ModelObject

Instance Attribute Details

#nameObject

Returns the value of attribute name.



154
155
156
# File 'lib/ditzstr/model-objects.rb', line 154

def name
  @name
end

#pathnameObject

Returns the value of attribute pathname.



154
155
156
# File 'lib/ditzstr/model-objects.rb', line 154

def pathname
  @pathname
end

#projectObject

Returns the value of attribute project.



154
155
156
# File 'lib/ditzstr/model-objects.rb', line 154

def project
  @project
end

Instance Method Details

#assign_to_component(component, who, comment) ⇒ Object



276
277
278
279
# File 'lib/ditzstr/model-objects.rb', line 276

def assign_to_component component, who, comment
  log "assigned to component #{component.name} from #{self.component}", who, comment
  self.component = component.name
end

#assign_to_release(release, who, comment) ⇒ Object



271
272
273
274
# File 'lib/ditzstr/model-objects.rb', line 271

def assign_to_release release, who, comment
  log "assigned to release #{release.name} from #{self.release || 'unassigned'}", who, comment
  self.release = release.name
end

#assigned?Boolean

Returns:

  • (Boolean)


222
# File 'lib/ditzstr/model-objects.rb', line 222

def assigned?; !unassigned? end

#bug?Boolean

Returns:

  • (Boolean)


219
# File 'lib/ditzstr/model-objects.rb', line 219

def bug?; type == :bugfix end

#change(hash, who, comment, silent) ⇒ Object



246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
# File 'lib/ditzstr/model-objects.rb', line 246

def change hash, who, comment, silent
  what = []
  if title != hash[:title]
    what << "title"
    self.title = hash[:title]
  end

  if desc != hash[:description]
    what << "description"
    self.desc = hash[:description]
  end

  if reporter != hash[:reporter]
    what << "reporter"
    self.reporter = hash[:reporter]
  end

  unless what.empty? || silent
    log "edited " + what.join(", "), who, comment
    true
  end

  !what.empty?
end

#close(disp, who, comment) ⇒ Object

Raises:



231
232
233
234
235
236
# File 'lib/ditzstr/model-objects.rb', line 231

def close disp, who, comment
  raise Error, "unknown disposition #{disp}" unless DISPOSITIONS.member? disp
  log "closed with disposition #{disp}", who, comment
  self.status = :closed
  self.disposition = disp
end

#closed?Boolean

Returns:

  • (Boolean)


215
# File 'lib/ditzstr/model-objects.rb', line 215

def closed?; status == :closed end

#deserialized_form_of(field, value) ⇒ Object



187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# File 'lib/ditzstr/model-objects.rb', line 187

def deserialized_form_of field, value
  return super unless INTERPOLATED_FIELDS.member? field

  if field == :log_events
    value.map do |time, who, what, comment|
      comment = @project.issues.inject(comment) do |s, i|
        s.gsub(/\{issue #{i.id}\}/, i.name)
      end.gsub(/\{issue \w+\}/, "[unknown issue]")
      [time, who, what, comment]
    end
  else
    @project.issues.inject(value) do |s, i|
      s.gsub(/\{issue #{i.id}\}/, i.name)
    end.gsub(/\{issue \w+\}/, "[unknown issue]")
  end
end

#disposition_stringObject



213
# File 'lib/ditzstr/model-objects.rb', line 213

def disposition_string; DISPOSITION_STRINGS[disposition] || disposition.to_s end

#feature?Boolean

Returns:

  • (Boolean)


220
# File 'lib/ditzstr/model-objects.rb', line 220

def feature?; type == :feature end

#get_component(config, project) ⇒ Object



292
293
294
295
296
297
298
# File 'lib/ditzstr/model-objects.rb', line 292

def get_component config, project
  if project.components.size == 1
    project.components.first
  else
    ask_for_selection project.components, "component", :name
  end.name
end

#get_release(config, project) ⇒ Object



300
301
302
303
304
305
306
307
308
309
310
311
# File 'lib/ditzstr/model-objects.rb', line 300

def get_release config, project
  releases = project.releases.select { |r| r.unreleased? }
  if !releases.empty? && ask_yon("Assign to a release now?")
    if releases.size == 1
      r = releases.first
      puts "Assigning to release #{r.name}."
      r
    else
      ask_for_selection releases, "release", :name
    end.name
  end
end

#get_reporter(config, project) ⇒ Object



313
314
315
# File 'lib/ditzstr/model-objects.rb', line 313

def get_reporter config, project
  reporter = ask "Creator", :default => config.user
end

#get_type(config, project) ⇒ Object



287
288
289
290
# File 'lib/ditzstr/model-objects.rb', line 287

def get_type config, project
  type = ask "Is this a (b)ugfix, a (f)eature, or a (t)ask?", :restrict => /^[bft]$/
  TYPE_LETTER[type]
end

#in_progress?Boolean

Returns:

  • (Boolean)


217
# File 'lib/ditzstr/model-objects.rb', line 217

def in_progress?; status == :in_progress end

#make_id(config, project) ⇒ Object

make a unique id



205
206
207
# File 'lib/ditzstr/model-objects.rb', line 205

def make_id config, project
  SHA1.hexdigest [Time.now, rand, creation_time, reporter, title, desc].join("\n")
end

#open?Boolean

Returns:

  • (Boolean)


216
# File 'lib/ditzstr/model-objects.rb', line 216

def open?; !closed? end

#paused?Boolean

Returns:

  • (Boolean)


223
# File 'lib/ditzstr/model-objects.rb', line 223

def paused?; status == :paused end

#serialized_form_of(field, value) ⇒ Object



170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
# File 'lib/ditzstr/model-objects.rb', line 170

def serialized_form_of field, value
  return super unless INTERPOLATED_FIELDS.member? field

  if field == :log_events
    value.map do |time, who, what, comment|
      comment = @project.issues.inject(comment) do |s, i|
        s.gsub(/\b#{i.name}\b/, "{issue #{i.id}}")
      end
      [time, who, what, comment]
    end
  else
    @project.issues.inject(value) do |s, i|
      s.gsub(/\b#{i.name}\b/, "{issue #{i.id}}")
    end
  end
end

#sort_orderObject



209
# File 'lib/ditzstr/model-objects.rb', line 209

def sort_order; [STATUS_SORT_ORDER[status], creation_time] end

#start_work(who, comment) ⇒ Object



225
# File 'lib/ditzstr/model-objects.rb', line 225

def start_work who, comment; change_status :in_progress, who, comment end

#status_stringObject



212
# File 'lib/ditzstr/model-objects.rb', line 212

def status_string; STATUS_STRINGS[status] || status.to_s end

#status_widgetObject



210
# File 'lib/ditzstr/model-objects.rb', line 210

def status_widget; STATUS_WIDGET[status] end

#stop_work(who, comment) ⇒ Object

Raises:



226
227
228
229
# File 'lib/ditzstr/model-objects.rb', line 226

def stop_work who, comment
  raise Error, "unstarted" unless self.status == :in_progress
  change_status :paused, who, comment
end

#unassign(who, comment) ⇒ Object

Raises:



281
282
283
284
285
# File 'lib/ditzstr/model-objects.rb', line 281

def unassign who, comment
  raise Error, "not assigned to a release" unless release
  log "unassigned from release #{release}", who, comment
  self.release = nil
end

#unassigned?Boolean

Returns:

  • (Boolean)


221
# File 'lib/ditzstr/model-objects.rb', line 221

def unassigned?; release.nil? end

#unstarted?Boolean

Returns:

  • (Boolean)


218
# File 'lib/ditzstr/model-objects.rb', line 218

def unstarted?; !in_progress? end