Class: Workarea::Release
- Inherits:
-
Object
show all
- Includes:
- Mongoid::Document::Taggable, ApplicationDocument, Commentable
- Defined in:
- app/models/workarea/release.rb,
app/models/workarea/release/status.rb,
app/models/workarea/release/changes.rb,
app/models/workarea/release/preview.rb,
app/models/workarea/release/changeset.rb,
app/models/workarea/release/activation.rb
Defined Under Namespace
Modules: Activation, Status
Classes: Changes, Changeset, Preview
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
#embedded_children
Class Method Details
.current ⇒ Object
60
61
62
|
# File 'app/models/workarea/release.rb', line 60
def self.current
Thread.current[:current_release]
end
|
.current=(release) ⇒ Object
64
65
66
|
# File 'app/models/workarea/release.rb', line 64
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>]
114
115
116
117
118
119
120
121
122
123
124
125
126
|
# File 'app/models/workarea/release.rb', line 114
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
|
.sort_by_publish ⇒ Object
128
129
130
|
# File 'app/models/workarea/release.rb', line 128
def self.sort_by_publish
scoped.sort_by { |r| [r.publish_at, r.created_at] }
end
|
.unscheduled ⇒ Array<Release>
Gets a list of unscheduled releases
96
97
98
|
# File 'app/models/workarea/release.rb', line 96
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.
105
106
107
|
# File 'app/models/workarea/release.rb', line 105
def self.upcoming
self.unscheduled + scheduled.desc(:publish_at).to_a
end
|
.with_current(release) ⇒ Object
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
# File 'app/models/workarea/release.rb', line 68
def self.with_current(release)
previous = current
new_current = if release.is_a?(Release)
release
elsif release.present?
find(release) rescue nil
end
self.current = new_current
current&.reset_preview
yield
ensure
self.current = previous
current&.reset_preview
previous&.reset_preview
end
|
.without_current(&block) ⇒ Object
88
89
90
|
# File 'app/models/workarea/release.rb', line 88
def self.without_current(&block)
with_current(nil, &block)
end
|
Instance Method Details
#as_current ⇒ Object
132
133
134
|
# File 'app/models/workarea/release.rb', line 132
def as_current
self.class.with_current(self) { yield }
end
|
#build_undo(attributes = {}) ⇒ Object
174
175
176
177
178
179
180
181
182
|
# File 'app/models/workarea/release.rb', line 174
def build_undo(attributes = {})
result = undo || Release.new(attributes)
result.name ||= I18n.t('workarea.release.undo', name: name)
result.tags = %w(undo) if result.tags.blank?
self.undo = result
result
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.
215
216
217
218
219
220
221
|
# File 'app/models/workarea/release.rb', line 215
def ordered_changesets
ordering = Workarea.config.release_changeset_ordering
changesets.sort_by do |changeset|
ordering[changeset.releasable_type].presence || 999
end
end
|
#preview ⇒ Object
152
153
154
|
# File 'app/models/workarea/release.rb', line 152
def preview
@preview ||= Preview.new(self)
end
|
#previous ⇒ Object
170
171
172
|
# File 'app/models/workarea/release.rb', line 170
def previous
scheduled_before.last
end
|
#publish! ⇒ Object
184
185
186
187
188
189
190
191
|
# File 'app/models/workarea/release.rb', line 184
def publish!
self.published_at = Time.current
self.publish_at = nil
save!
ordered_changesets.each(&:publish!)
touch_releasables
end
|
#published? ⇒ Boolean
140
141
142
|
# File 'app/models/workarea/release.rb', line 140
def published?
!!published_at
end
|
#reset_preview ⇒ Object
156
157
158
|
# File 'app/models/workarea/release.rb', line 156
def reset_preview
@preview = nil
end
|
#scheduled? ⇒ Boolean
136
137
138
|
# File 'app/models/workarea/release.rb', line 136
def scheduled?
!!publish_at && (persisted? && !publish_at_changed?)
end
|
#scheduled_after ⇒ Object
165
166
167
168
|
# File 'app/models/workarea/release.rb', line 165
def scheduled_after
return [] unless scheduled?
self.class.scheduled(after: publish_at).ne(id: id).sort_by_publish
end
|
#scheduled_before ⇒ Object
160
161
162
163
|
# File 'app/models/workarea/release.rb', line 160
def scheduled_before
return [] unless scheduled?
self.class.scheduled(before: publish_at).ne(id: id).sort_by_publish
end
|
#set_publish_job ⇒ Object
193
194
195
196
197
198
199
200
|
# File 'app/models/workarea/release.rb', line 193
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
|
#statuses ⇒ Array<Symbol>
Get all statuses of this release.
206
207
208
209
|
# File 'app/models/workarea/release.rb', line 206
def statuses
calculators = Workarea.config.release_status_calculators.map(&:constantize)
StatusCalculator.new(calculators, self).results
end
|
#upcoming? ⇒ Boolean
144
145
146
|
# File 'app/models/workarea/release.rb', line 144
def upcoming?
scheduled? || (!scheduled? && !published?)
end
|