Class: ActivePivot::Story
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- ActivePivot::Story
- Defined in:
- lib/active_pivot/story.rb
Class Method Summary collapse
- .accepted ⇒ Object
- .accepted_after(date) ⇒ Object
- .accepted_before(date) ⇒ Object
- .for_project(project_id) ⇒ Object
- .order_by_project_name ⇒ Object
- .select_all ⇒ Object
- .select_points(as = :accepted_points) ⇒ Object
- .subselect(scope, attribute = :id) ⇒ Object
- .unique_estimates ⇒ Object
- .unique_statuses ⇒ Object
- .with_estimate(estimate) ⇒ Object
- .with_number(number) ⇒ Object
- .with_status(status) ⇒ Object
- .with_tags(*tags) ⇒ Object
- .worked_on_after(date) ⇒ Object
- .worked_on_before(date) ⇒ Object
Instance Method Summary collapse
- #accepted? ⇒ Boolean
- #billed_amount ⇒ Object
- #billed_amount_per_point ⇒ Object
- #hours ⇒ Object
- #hours_per_point ⇒ Object
- #human_state ⇒ Object
- #human_type ⇒ Object
- #invoice_hours ⇒ Object
- #invoice_hours_per_point ⇒ Object
- #labels=(labels) ⇒ Object
- #remote_activities(params = {}) ⇒ Object
- #state ⇒ Object
- #to_param ⇒ Object
Class Method Details
.accepted ⇒ Object
65 66 67 |
# File 'lib/active_pivot/story.rb', line 65 def self.accepted where.not(accepted_at: nil) end |
.accepted_after(date) ⇒ Object
69 70 71 |
# File 'lib/active_pivot/story.rb', line 69 def self.accepted_after(date) where("#{table_name}.accepted_at >= ?", date) end |
.accepted_before(date) ⇒ Object
73 74 75 |
# File 'lib/active_pivot/story.rb', line 73 def self.accepted_before(date) where("#{table_name}.accepted_at <= ?", date) end |
.for_project(project_id) ⇒ Object
21 22 23 |
# File 'lib/active_pivot/story.rb', line 21 def self.for_project(project_id) where(project_id: project_id) end |
.order_by_project_name ⇒ Object
37 38 39 |
# File 'lib/active_pivot/story.rb', line 37 def self.order_by_project_name joins(:project).merge(Project.alphabetized) end |
.select_all ⇒ Object
61 62 63 |
# File 'lib/active_pivot/story.rb', line 61 def self.select_all select("#{table_name}.*") end |
.select_points(as = :accepted_points) ⇒ Object
77 78 79 |
# File 'lib/active_pivot/story.rb', line 77 def self.select_points(as = :accepted_points) select("SUM(#{table_name}.estimate) as #{as}") end |
.subselect(scope, attribute = :id) ⇒ Object
41 42 43 |
# File 'lib/active_pivot/story.rb', line 41 def self.subselect(scope, attribute = :id) where("#{table_name}.id IN (#{scope.select(attribute).to_sql})") end |
.unique_estimates ⇒ Object
57 58 59 |
# File 'lib/active_pivot/story.rb', line 57 def self.unique_estimates group(:estimate).pluck(:estimate).reject(&:blank?) end |
.unique_statuses ⇒ Object
53 54 55 |
# File 'lib/active_pivot/story.rb', line 53 def self.unique_statuses group(:current_state).pluck(:current_state) end |
.with_estimate(estimate) ⇒ Object
29 30 31 |
# File 'lib/active_pivot/story.rb', line 29 def self.with_estimate(estimate) where(estimate: estimate) end |
.with_number(number) ⇒ Object
33 34 35 |
# File 'lib/active_pivot/story.rb', line 33 def self.with_number(number) where(pivotal_id: number) end |
.with_status(status) ⇒ Object
25 26 27 |
# File 'lib/active_pivot/story.rb', line 25 def self.with_status(status) where(current_state: status) end |
.with_tags(*tags) ⇒ Object
81 82 83 |
# File 'lib/active_pivot/story.rb', line 81 def self.(*) where("#{table_name}.tags @> ARRAY[?]", .join(",")) end |
.worked_on_after(date) ⇒ Object
49 50 51 |
# File 'lib/active_pivot/story.rb', line 49 def self.worked_on_after(date) subselect Story.unscoped.joins(:time_entries).merge(TimeEntry.worked_on_after(date)) end |
.worked_on_before(date) ⇒ Object
45 46 47 |
# File 'lib/active_pivot/story.rb', line 45 def self.worked_on_before(date) subselect Story.unscoped.joins(:time_entries).merge(TimeEntry.worked_on_before(date)) end |
Instance Method Details
#accepted? ⇒ Boolean
132 133 134 |
# File 'lib/active_pivot/story.rb', line 132 def accepted? accepted_at? end |
#billed_amount ⇒ Object
112 113 114 |
# File 'lib/active_pivot/story.rb', line 112 def billed_amount (read_attribute(:billed_amount) || time_entries.map(&:billed_amount).sum).to_f end |
#billed_amount_per_point ⇒ Object
116 117 118 |
# File 'lib/active_pivot/story.rb', line 116 def billed_amount_per_point estimate.to_i.zero? ? 0 : billed_amount / estimate.to_i end |
#hours ⇒ Object
104 105 106 |
# File 'lib/active_pivot/story.rb', line 104 def hours read_attribute(:minutes) ? (minutes / 60.0) : time_entries.map(&:hours).sum end |
#hours_per_point ⇒ Object
120 121 122 |
# File 'lib/active_pivot/story.rb', line 120 def hours_per_point estimate.to_i.zero? ? 0 : hours / estimate.to_i end |
#human_state ⇒ Object
96 97 98 |
# File 'lib/active_pivot/story.rb', line 96 def human_state state.titleize end |
#human_type ⇒ Object
100 101 102 |
# File 'lib/active_pivot/story.rb', line 100 def human_type story_type.titleize end |
#invoice_hours ⇒ Object
108 109 110 |
# File 'lib/active_pivot/story.rb', line 108 def invoice_hours read_attribute(:invoice_minutes) ? (invoice_minutes / 60.0) : time_entries.map(&:invoice_hours).sum end |
#invoice_hours_per_point ⇒ Object
124 125 126 |
# File 'lib/active_pivot/story.rb', line 124 def invoice_hours_per_point estimate.to_i.zero? ? 0 : invoice_hours / estimate.to_i end |
#labels=(labels) ⇒ Object
85 86 87 88 89 90 |
# File 'lib/active_pivot/story.rb', line 85 def labels=(labels) super(Array.wrap(labels)) self.epics = extract_epics_for_labels(labels) self. = (labels) end |
#remote_activities(params = {}) ⇒ Object
17 18 19 |
# File 'lib/active_pivot/story.rb', line 17 def remote_activities(params = {}) Api::Activity.for_project(project_id, pivotal_id, params) end |
#state ⇒ Object
92 93 94 |
# File 'lib/active_pivot/story.rb', line 92 def state current_state end |
#to_param ⇒ Object
128 129 130 |
# File 'lib/active_pivot/story.rb', line 128 def to_param pivotal_id end |