Class: Stagehand::Staging::Commit
- Inherits:
-
Object
- Object
- Stagehand::Staging::Commit
- Defined in:
- lib/stagehand/staging/commit.rb
Class Method Summary collapse
- .all ⇒ Object
- .capture(subject_record = nil, except: [], &block) ⇒ Object
- .capturing? ⇒ Boolean
- .containing(record) ⇒ Object
- .empty ⇒ Object
- .find(start_ids) ⇒ Object
Instance Method Summary collapse
- #==(other) ⇒ Object
- #destroy ⇒ Object
- #empty? ⇒ Boolean
- #entries ⇒ Object
- #eql?(other) ⇒ Boolean
- #hash ⇒ Object
- #id ⇒ Object
- #include?(record) ⇒ Boolean
-
#initialize(start_id) ⇒ Commit
constructor
A new instance of Commit.
- #subject ⇒ Object
Constructor Details
#initialize(start_id) ⇒ Commit
Returns a new instance of Commit.
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/stagehand/staging/commit.rb', line 97 def initialize(start_id) @start_id, @end_id = CommitEntry.control_operations .limit(2) .where(:commit_id => start_id) .where('id >= ?', start_id) .reorder(:id => :asc) .pluck(:id) return if @start_id && @end_id missing = [] missing << CommitEntry::START_OPERATION unless @start_id == start_id missing << CommitEntry::END_OPERATION if @start_id == start_id raise CommitNotFound, "Couldn't find #{missing.join(', ')} entry for Commit #{start_id}" end |
Class Method Details
.all ⇒ Object
4 5 6 |
# File 'lib/stagehand/staging/commit.rb', line 4 def self.all CommitEntry.end_operations.pluck(:commit_id).collect {|id| find(id) }.compact end |
.capture(subject_record = nil, except: [], &block) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/stagehand/staging/commit.rb', line 16 def self.capture(subject_record = nil, except: [], &block) @capturing = true start_operation = start_commit(subject_record) init_session!(start_operation) begin block.call(start_operation) rescue => e end_commit(start_operation, except) unless e.is_a?(CommitError) || e.is_a?(ActiveRecord::Rollback) raise(e) else return end_commit(start_operation, except) end ensure @capturing = false end |
.capturing? ⇒ Boolean
12 13 14 |
# File 'lib/stagehand/staging/commit.rb', line 12 def self.capturing? !!@capturing end |
.containing(record) ⇒ Object
33 34 35 |
# File 'lib/stagehand/staging/commit.rb', line 33 def self.containing(record) find(CommitEntry.contained.matching(record).pluck(:commit_id)) end |
.empty ⇒ Object
8 9 10 |
# File 'lib/stagehand/staging/commit.rb', line 8 def self.empty all.select(&:empty?) end |
.find(start_ids) ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/stagehand/staging/commit.rb', line 37 def self.find(start_ids) if start_ids.respond_to?(:each) start_ids.to_a.uniq.collect {|id| find(id) }.compact else new(start_ids) end rescue CommitNotFound end |
Instance Method Details
#==(other) ⇒ Object
130 131 132 |
# File 'lib/stagehand/staging/commit.rb', line 130 def ==(other) id == other.id end |
#destroy ⇒ Object
146 147 148 |
# File 'lib/stagehand/staging/commit.rb', line 146 def destroy entries.delete_all end |
#empty? ⇒ Boolean
142 143 144 |
# File 'lib/stagehand/staging/commit.rb', line 142 def empty? entries.content_operations.empty? end |
#entries ⇒ Object
134 135 136 |
# File 'lib/stagehand/staging/commit.rb', line 134 def entries CommitEntry.where(:id => @start_id..@end_id).where(:commit_id => id) end |
#eql?(other) ⇒ Boolean
126 127 128 |
# File 'lib/stagehand/staging/commit.rb', line 126 def eql?(other) self == other end |
#hash ⇒ Object
122 123 124 |
# File 'lib/stagehand/staging/commit.rb', line 122 def hash id end |
#id ⇒ Object
114 115 116 |
# File 'lib/stagehand/staging/commit.rb', line 114 def id @start_id end |
#include?(record) ⇒ Boolean
118 119 120 |
# File 'lib/stagehand/staging/commit.rb', line 118 def include?(record) entries.where(:record_id => record.id, :table_name => record.class.table_name).exists? end |
#subject ⇒ Object
138 139 140 |
# File 'lib/stagehand/staging/commit.rb', line 138 def subject entries.sort_by(&:id).first.record end |