Class: Milestone
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Milestone
- Extended by:
- Nosync
- Defined in:
- app/models/milestone.rb
Class Method Summary collapse
- .completed ⇒ Object
- .current ⇒ Object
- .during(range) ⇒ Object
- .empty ⇒ Object
- .id_for_remote_id(remote_id) ⇒ Object
- .populated ⇒ Object
- .remote_id_map ⇒ Object
- .uncompleted ⇒ Object (also: open)
- .visible ⇒ Object
- .without(milestones) ⇒ Object
- .without_remote_ids(*ids) ⇒ Object
Instance Method Summary collapse
- #close! ⇒ Object
- #completed? ⇒ Boolean
- #remote_milestone ⇒ Object (also: #remote)
- #uncompleted? ⇒ Boolean
- #update_closed_tickets_count! ⇒ Object
Methods included from Nosync
Class Method Details
.completed ⇒ Object
28 29 30 31 32 |
# File 'app/models/milestone.rb', line 28 def completed where( arel_table[:tickets_count].gt(0).and( arel_table[:closed_tickets_count].eq(arel_table[:tickets_count]))) end |
.current ⇒ Object
46 47 48 |
# File 'app/models/milestone.rb', line 46 def current during(Date.today..Date.today) end |
.during(range) ⇒ Object
50 51 52 53 54 |
# File 'app/models/milestone.rb', line 50 def during(range) visible .where(arel_table[:start_date].lteq(range.end)) .where(arel_table[:end_date].gteq(range.begin)) end |
.empty ⇒ Object
20 21 22 |
# File 'app/models/milestone.rb', line 20 def empty where(tickets_count: 0) end |
.id_for_remote_id(remote_id) ⇒ Object
69 70 71 72 |
# File 'app/models/milestone.rb', line 69 def id_for_remote_id(remote_id) return nil if remote_id.nil? or remote_id == 0 where(remote_id: remote_id).pluck(:id).first end |
.populated ⇒ Object
24 25 26 |
# File 'app/models/milestone.rb', line 24 def populated where(arel_table[:tickets_count].gt(0)) end |
.remote_id_map ⇒ Object
64 65 66 67 |
# File 'app/models/milestone.rb', line 64 def remote_id_map query = select("remote_id, id").to_sql connection.select_rows(query).each_with_object({}) { |(remote_id, id), map| map[remote_id.to_i] = id.to_i } end |
.uncompleted ⇒ Object Also known as: open
34 35 36 37 38 |
# File 'app/models/milestone.rb', line 34 def uncompleted where( arel_table[:tickets_count].eq(0).or( arel_table[:closed_tickets_count].lt(arel_table[:tickets_count]))) end |
.visible ⇒ Object
41 42 43 44 |
# File 'app/models/milestone.rb', line 41 def visible where(arel_table[:start_date].not_eq(nil)). where(arel_table[:end_date].not_eq(nil)) end |
.without(milestones) ⇒ Object
56 57 58 |
# File 'app/models/milestone.rb', line 56 def without(milestones) without_remote_ids(milestones.map(&:remote_id)) end |
.without_remote_ids(*ids) ⇒ Object
60 61 62 |
# File 'app/models/milestone.rb', line 60 def without_remote_ids(*ids) where(arel_table[:remote_id].not_in(ids.flatten.map(&:to_i))) end |
Instance Method Details
#close! ⇒ Object
85 86 87 88 |
# File 'app/models/milestone.rb', line 85 def close! project.ticket_tracker.close_milestone!(self) if project.ticket_tracker.respond_to?(:close_milestone!) touch :completed_at end |
#completed? ⇒ Boolean
77 78 79 |
# File 'app/models/milestone.rb', line 77 def completed? tickets_count > 0 && closed_tickets_count == tickets_count end |
#remote_milestone ⇒ Object Also known as: remote
90 91 92 |
# File 'app/models/milestone.rb', line 90 def remote_milestone @remote_milestone ||= ticket_tracker.find_milestone(remote_id) if ticket_tracker.respond_to?(:find_milestone) end |
#uncompleted? ⇒ Boolean
81 82 83 |
# File 'app/models/milestone.rb', line 81 def uncompleted? !completed? end |
#update_closed_tickets_count! ⇒ Object
95 96 97 |
# File 'app/models/milestone.rb', line 95 def update_closed_tickets_count! update_column :closed_tickets_count, tickets.closed.count end |