Class: Stagehand::Staging::CommitEntry
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Stagehand::Staging::CommitEntry
- Defined in:
- lib/stagehand/staging/commit_entry.rb
Constant Summary collapse
- START_OPERATION =
'commit_start'- END_OPERATION =
'commit_end'- INSERT_OPERATION =
'insert'- UPDATE_OPERATION =
'update'- DELETE_OPERATION =
'delete'- CONTROL_OPERATIONS =
[START_OPERATION, END_OPERATION]
- CONTENT_OPERATIONS =
[INSERT_OPERATION, UPDATE_OPERATION, DELETE_OPERATION]
- SAVE_OPERATIONS =
[INSERT_OPERATION, UPDATE_OPERATION]
Instance Attribute Summary collapse
Class Method Summary collapse
Instance Method Summary collapse
- #content_operation? ⇒ Boolean
- #control_operation? ⇒ Boolean
- #delete_operation? ⇒ Boolean
- #end_operation? ⇒ Boolean
- #insert_operation? ⇒ Boolean
- #key ⇒ Object
- #matches?(others) ⇒ Boolean
- #record_class ⇒ Object
- #save_operation? ⇒ Boolean
- #start_operation? ⇒ Boolean
- #update_operation? ⇒ Boolean
Instance Attribute Details
#record ⇒ Object
54 55 56 |
# File 'lib/stagehand/staging/commit_entry.rb', line 54 def record @record ||= delete_operation? ? build_production_record : record_class.find_by_id(record_id) if content_operation? end |
Class Method Details
.infer_class(table_name) ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/stagehand/staging/commit_entry.rb', line 46 def self.infer_class(table_name) klass = ActiveRecord::Base.descendants.detect {|klass| klass.table_name == table_name && klass != Stagehand::Production::Record } klass ||= table_name.classify.constantize # Try loading the class if it isn't loaded yet rescue NameError raise(IndeterminateRecordClass, "Can't determine class from table name: #{table_name}") end |
.matching(object) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/stagehand/staging/commit_entry.rb', line 32 def self.matching(object) keys = Array.wrap(object).collect {|entry| Stagehand::Key.generate(entry) }.compact sql = [] interpolates = [] keys.group_by(&:first).each do |table_name, keys| sql << "(table_name = ? AND record_id IN (?))" interpolates << table_name interpolates << keys.collect(&:last) end return keys.present? ? where(sql.join(' OR '), *interpolates) : none end |
Instance Method Details
#content_operation? ⇒ Boolean
62 63 64 |
# File 'lib/stagehand/staging/commit_entry.rb', line 62 def content_operation? operation.in?(CONTENT_OPERATIONS) end |
#control_operation? ⇒ Boolean
58 59 60 |
# File 'lib/stagehand/staging/commit_entry.rb', line 58 def control_operation? operation.in?(CONTROL_OPERATIONS) end |
#delete_operation? ⇒ Boolean
78 79 80 |
# File 'lib/stagehand/staging/commit_entry.rb', line 78 def delete_operation? operation == DELETE_OPERATION end |
#end_operation? ⇒ Boolean
86 87 88 |
# File 'lib/stagehand/staging/commit_entry.rb', line 86 def end_operation? operation == END_OPERATION end |
#insert_operation? ⇒ Boolean
70 71 72 |
# File 'lib/stagehand/staging/commit_entry.rb', line 70 def insert_operation? operation == INSERT_OPERATION end |
#key ⇒ Object
94 95 96 |
# File 'lib/stagehand/staging/commit_entry.rb', line 94 def key @key ||= Stagehand::Key.generate(self) end |
#matches?(others) ⇒ Boolean
90 91 92 |
# File 'lib/stagehand/staging/commit_entry.rb', line 90 def matches?(others) Array.wrap(others).any? {|other| key == Stagehand::Key.generate(other) } end |
#record_class ⇒ Object
98 99 100 |
# File 'lib/stagehand/staging/commit_entry.rb', line 98 def record_class @record_class ||= self.class.infer_class(table_name) end |
#save_operation? ⇒ Boolean
66 67 68 |
# File 'lib/stagehand/staging/commit_entry.rb', line 66 def save_operation? operation.in?(SAVE_OPERATIONS) end |
#start_operation? ⇒ Boolean
82 83 84 |
# File 'lib/stagehand/staging/commit_entry.rb', line 82 def start_operation? operation == START_OPERATION end |
#update_operation? ⇒ Boolean
74 75 76 |
# File 'lib/stagehand/staging/commit_entry.rb', line 74 def update_operation? operation == UPDATE_OPERATION end |