Class: GlobalMilestone

Inherits:
Object
  • Object
show all
Includes:
Milestoneish
Defined in:
app/models/global_milestone.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Milestoneish

#closed_items_count, #complete?, #issues_visible_to_user, #percent_complete, #remaining_days, #total_items_count

Constructor Details

#initialize(title, milestones) ⇒ GlobalMilestone

Returns a new instance of GlobalMilestone


15
16
17
18
19
# File 'app/models/global_milestone.rb', line 15

def initialize(title, milestones)
  @title = title
  @name = title
  @milestones = milestones
end

Instance Attribute Details

#milestonesObject

Returns the value of attribute milestones


4
5
6
# File 'app/models/global_milestone.rb', line 4

def milestones
  @milestones
end

#titleObject

Returns the value of attribute title


4
5
6
# File 'app/models/global_milestone.rb', line 4

def title
  @title
end

Class Method Details

.build_collection(milestones) ⇒ Object


7
8
9
10
11
12
13
# File 'app/models/global_milestone.rb', line 7

def self.build_collection(milestones)
  milestones = milestones.group_by(&:title)

  milestones.map do |title, milestones|
    new(title, milestones)
  end
end

Instance Method Details

#active?Boolean

Returns:

  • (Boolean)

47
48
49
# File 'app/models/global_milestone.rb', line 47

def active?
  state == 'active'
end

#closed?Boolean

Returns:

  • (Boolean)

51
52
53
# File 'app/models/global_milestone.rb', line 51

def closed?
  state == 'closed'
end

#due_dateObject


72
73
74
75
76
77
78
79
80
81
# File 'app/models/global_milestone.rb', line 72

def due_date
  return @due_date if defined?(@due_date)

  @due_date =
    if @milestones.all? { |x| x.due_date == @milestones.first.due_date }
      @milestones.first.due_date
    else
      nil
    end
end

#expired?Boolean

Returns:

  • (Boolean)

25
26
27
28
29
30
31
# File 'app/models/global_milestone.rb', line 25

def expired?
  if due_date
    due_date.past?
  else
    false
  end
end

#expires_atObject


83
84
85
86
87
88
89
90
91
# File 'app/models/global_milestone.rb', line 83

def expires_at
  if due_date
    if due_date.past?
      "expired on #{due_date.to_s(:medium)}"
    else
      "expires on #{due_date.to_s(:medium)}"
    end
  end
end

#issuesObject


55
56
57
# File 'app/models/global_milestone.rb', line 55

def issues
  @issues ||= Issue.of_milestones(milestones.map(&:id)).includes(:project)
end

#labelsObject


67
68
69
70
# File 'app/models/global_milestone.rb', line 67

def labels
  @labels ||= GlobalLabel.build_collection(milestones.map(&:labels).flatten)
                         .sort_by!(&:title)
end

#merge_requestsObject


59
60
61
# File 'app/models/global_milestone.rb', line 59

def merge_requests
  @merge_requests ||= MergeRequest.of_milestones(milestones.map(&:id)).includes(:target_project)
end

#participantsObject


63
64
65
# File 'app/models/global_milestone.rb', line 63

def participants
  @participants ||= milestones.map(&:participants).flatten.compact.uniq
end

#projectsObject


33
34
35
# File 'app/models/global_milestone.rb', line 33

def projects
  @projects ||= Project.for_milestones(milestones.map(&:id))
end

#safe_titleObject


21
22
23
# File 'app/models/global_milestone.rb', line 21

def safe_title
  @title.to_slug.normalize.to_s
end

#stateObject


37
38
39
40
41
42
43
44
45
# File 'app/models/global_milestone.rb', line 37

def state
  state = milestones.map { |milestone| milestone.state }

  if state.count('closed') == state.size
    'closed'
  else
    'active'
  end
end