Class: Ditz::Project

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

Defined Under Namespace

Classes: Error

Instance Method Summary collapse

Methods inherited from ModelObject

#after_deserialize, #before_serialize, #changed!, #changed?, changes_are_logged, create_interactively, #each_modelobject, field, fields, from, inherited, #initialize, #log, #save!, #to_yaml_properties, #to_yaml_type, yaml_domain, yaml_other_thing

Constructor Details

This class inherits a constructor from Ditz::ModelObject

Instance Method Details

#assign_issue_names!Object



83
84
85
86
87
88
89
# File 'lib/model-objects.rb', line 83

def assign_issue_names!
  prefixes = components.map { |c| [c.name, c.name.gsub(/^\s+/, "-").downcase] }.to_h
  ids = components.map { |c| [c.name, 0] }.to_h
  issues.each do |i|
    i.name = "#{prefixes[i.component]}-#{ids[i.component] += 1}"
  end
end

#component_for(component_name) ⇒ Object



61
62
63
64
# File 'lib/model-objects.rb', line 61

def component_for component_name
  components.find { |i| i.name == component_name } or
    raise Error, "has no component with name #{component_name.inspect}"
end

#get_componentsObject



45
46
47
48
49
50
51
52
53
54
# File 'lib/model-objects.rb', line 45

def get_components
  puts <<EOS
Issues can be tracked across the project as a whole, or the project can be
split into components, and issues tracked separately for each component.
EOS
  use_components = ask_yon "Track issues separately for different components?"
  comp_names = use_components ? ask_for_many("components") : []

  ([name] + comp_names).uniq.map { |n| Component.create_interactively :with => { :name => n } }
end

#issue_for(issue_name) ⇒ Object



56
57
58
59
# File 'lib/model-objects.rb', line 56

def issue_for issue_name
  issues.find { |i| i.name == issue_name } or
    raise Error, "has no issue with name #{issue_name.inspect}"
end

#issues_for_component(component) ⇒ Object



75
76
77
# File 'lib/model-objects.rb', line 75

def issues_for_component component
  issues.select { |i| i.component == component.name }
end

#issues_for_release(release) ⇒ Object



71
72
73
# File 'lib/model-objects.rb', line 71

def issues_for_release release
  issues.select { |i| i.release == release.name }
end

#release_for(release_name) ⇒ Object



66
67
68
69
# File 'lib/model-objects.rb', line 66

def release_for release_name
  releases.find { |i| i.name == release_name } or
    raise Error, "has no release with name #{release_name.inspect}"
end

#unassigned_issuesObject



79
80
81
# File 'lib/model-objects.rb', line 79

def unassigned_issues
  issues.select { |i| i.release.nil? }
end

#validate!Object



91
92
93
94
95
96
97
# File 'lib/model-objects.rb', line 91

def validate!
  if(dup = components.map { |c| c.name }.first_duplicate)
    raise Error, "more than one component named #{dup.inspect}"
  elsif(dup = releases.map { |r| r.name }.first_duplicate)
    raise Error, "more than one release named #{dup.inspect}"
  end
end