Class: Ditz::Project

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

Defined Under Namespace

Classes: Error

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from ModelObject

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

Constructor Details

This class inherits a constructor from Ditz::ModelObject

Instance Attribute Details

#issuesObject

issues are not model fields proper, so we build up their interface here.



47
48
49
# File 'lib/model-objects.rb', line 47

def issues
  @issues
end

#pathnameObject

Returns the value of attribute pathname.



39
40
41
# File 'lib/model-objects.rb', line 39

def pathname
  @pathname
end

Instance Method Details

#add_issue(issue) ⇒ Object



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

def add_issue issue; added_issues << issue; issues << issue end

#added_issuesObject



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

def added_issues; @added_issues ||= [] end

#assign_issue_names!Object



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

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.sort_by { |i| i.creation_time }.each do |i|
    i.name = "#{prefixes[i.component]}-#{ids[i.component] += 1}"
  end
end

#component_for(component_name) ⇒ Object



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

def component_for component_name
  components.find { |i| i.name == component_name }
end

#deleted_issuesObject



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

def deleted_issues; @deleted_issues ||= [] end

#drop_issue(issue) ⇒ Object



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

def drop_issue issue; deleted_issues << issue if issues.delete issue end

#get_componentsObject



53
54
55
56
57
58
59
60
61
62
# File 'lib/model-objects.rb', line 53

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

#group_issues(these_issues = issues) ⇒ Object



88
89
90
# File 'lib/model-objects.rb', line 88

def group_issues these_issues=issues
  these_issues.group_by { |i| i.type }.sort_by { |(t,g)| Issue::TYPE_ORDER[t] }
end

#issue_for(issue_name) ⇒ Object



64
65
66
# File 'lib/model-objects.rb', line 64

def issue_for issue_name
  issues.find { |i| i.name == issue_name }
end

#issues_for_component(component) ⇒ Object



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

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

#issues_for_release(release) ⇒ Object



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

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

#release_for(release_name) ⇒ Object



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

def release_for release_name
  releases.find { |i| i.name == release_name }
end

#unassigned_issuesObject



84
85
86
# File 'lib/model-objects.rb', line 84

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

#validate!Object



100
101
102
103
104
105
106
# File 'lib/model-objects.rb', line 100

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