Class: Workarea::Release
Defined Under Namespace
Modules: Status
Classes: Changeset
Class Method Summary
collapse
Instance Method Summary
collapse
#add_subscription, #remove_subscription
included
#releasable?
add_worker, assert_valid_config!, async, caching_classes?, disable, enable, inline, #run_callbacks, workers, workers_list
Class Method Details
.current ⇒ Object
52
53
54
|
# File 'app/models/workarea/release.rb', line 52
def self.current
Thread.current[:current_release]
end
|
.current=(release) ⇒ Object
56
57
58
|
# File 'app/models/workarea/release.rb', line 56
def self.current=(release)
Thread.current[:current_release] = release
end
|
.published_within(start_date, end_date) ⇒ Object
Get a list of releases published or to be published within a given range
@ return [Array<Release>]
93
94
95
96
97
98
99
100
101
102
103
104
105
|
# File 'app/models/workarea/release.rb', line 93
def self.published_within(start_date, end_date)
results = where(
:publish_at.gte => start_date.to_time,
:publish_at.lte => end_date.to_time
)
results += where(
:published_at.gte => start_date.to_time,
:published_at.lte => end_date.to_time
)
results.uniq.sort_by { |r| [r.publish_at || 0, r.published_at || 0] }
end
|
.undone_within(start_date, end_date) ⇒ Object
Get a list of releases undone or to be undone within a given range
@ return [Array<Release>]
112
113
114
115
116
117
118
119
120
121
122
123
124
|
# File 'app/models/workarea/release.rb', line 112
def self.undone_within(start_date, end_date)
results = where(
:undo_at.gte => start_date.to_time,
:undo_at.lte => end_date.to_time
)
results += where(
:undone_at.gte => start_date.to_time,
:undone_at.lte => end_date.to_time
)
results.uniq.sort_by { |r| [r.undo_at || 0, r.undone_at || 0] }
end
|
.unscheduled ⇒ Array<Release>
Gets a list of unscheduled releases
75
76
77
|
# File 'app/models/workarea/release.rb', line 75
def self.unscheduled
all.and(not_scheduled.selector, not_published.selector).desc(:created_at).to_a
end
|
.upcoming ⇒ Array<Release>
Gets a list of unpublished releases sorted by when they will be published.
84
85
86
|
# File 'app/models/workarea/release.rb', line 84
def self.upcoming
self.unscheduled + scheduled.desc(:publish_at).to_a
end
|
.with_current(release_id, &block) ⇒ Object
60
61
62
63
64
65
66
67
68
69
|
# File 'app/models/workarea/release.rb', line 60
def self.with_current(release_id, &block)
previous = current
self.current = release_id.blank? ? nil : find(release_id) rescue nil
return_value = block.call
ensure
self.current = previous
return_value
end
|
Instance Method Details
#as_current ⇒ Object
126
127
128
129
130
|
# File 'app/models/workarea/release.rb', line 126
def as_current
self.class.with_current(id) do
yield
end
end
|
#has_changes? ⇒ Boolean
148
149
150
|
# File 'app/models/workarea/release.rb', line 148
def has_changes?
changesets.present?
end
|
Get changesets ordered based on publish priority set by configuration.
202
203
204
205
206
207
208
|
# File 'app/models/workarea/release.rb', line 202
def ordered_changesets
ordering = Workarea.config.release_changeset_ordering
changesets.sort_by do |changeset|
ordering[changeset.releasable_type].presence || 999
end
end
|
#publish! ⇒ Object
152
153
154
155
156
157
158
159
160
|
# File 'app/models/workarea/release.rb', line 152
def publish!
self.published_at = Time.current
self.undone_at = nil
self.publish_at = nil
save!
ordered_changesets.each(&:publish!)
touch_releasables
end
|
#published? ⇒ Boolean
136
137
138
|
# File 'app/models/workarea/release.rb', line 136
def published?
!!published_at
end
|
#scheduled? ⇒ Boolean
132
133
134
|
# File 'app/models/workarea/release.rb', line 132
def scheduled?
!!publish_at && (persisted? && !publish_at_changed?)
end
|
#set_publish_job ⇒ Object
171
172
173
174
175
176
177
178
|
# File 'app/models/workarea/release.rb', line 171
def set_publish_job
self.publish_job_id = Scheduler.schedule(
worker: PublishRelease,
at: publish_at,
args: [id.to_s],
job_id: publish_job_id
)
end
|
#set_undo_job ⇒ Object
180
181
182
183
184
185
186
187
|
# File 'app/models/workarea/release.rb', line 180
def set_undo_job
self.undo_job_id = Scheduler.schedule(
worker: UndoRelease,
at: undo_at,
args: [id.to_s],
job_id: undo_job_id
)
end
|
#statuses ⇒ Array<Symbol>
Get all statuses of this release.
193
194
195
196
|
# File 'app/models/workarea/release.rb', line 193
def statuses
calculators = Workarea.config.release_status_calculators.map(&:constantize)
StatusCalculator.new(calculators, self).results
end
|
#undo! ⇒ Object
162
163
164
165
166
167
168
169
|
# File 'app/models/workarea/release.rb', line 162
def undo!
self.undo_at = nil if undo_at.present? && undo_at >= Time.current
self.undone_at = Time.current
save!
ordered_changesets.each(&:undo!)
touch_releasables
end
|
#undone? ⇒ Boolean
144
145
146
|
# File 'app/models/workarea/release.rb', line 144
def undone?
!!undone_at
end
|
#upcoming? ⇒ Boolean
140
141
142
|
# File 'app/models/workarea/release.rb', line 140
def upcoming?
scheduled? || (!scheduled? && !published?)
end
|