Module: Batch::RequestBehaviour
- Included in:
- Request
- Defined in:
- app/models/batch/request_behaviour.rb
Overview
rubocop:todo Style/Documentation
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.included(base) ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'app/models/batch/request_behaviour.rb', line 2 def self.included(base) base.class_eval do has_one :batch_request, inverse_of: :request, dependent: :destroy has_one :batch, through: :batch_request, inverse_of: :requests scope :include_for_batch_view, -> { includes(:batch_request, :asset, :target_asset, :request_metadata, :comments) } # For backwards compatibility def batch_requests; [batch_request].compact; end def batches; [batch].compact; end # Identifies all requests that are not part of a batch. # Note: we join, rather than includes due to custom select limitations. scope :unbatched, ->() { joins('LEFT OUTER JOIN batch_requests ON batch_requests.request_id = requests.id') .readonly(false) .where(batch_requests: { request_id: nil }) } delegate :position, to: :batch_request, allow_nil: true end end |
Instance Method Details
#recycle_from_batch! ⇒ Object
32 33 34 35 36 37 38 |
# File 'app/models/batch/request_behaviour.rb', line 32 def recycle_from_batch! ActiveRecord::Base.transaction do return_for_inbox! batch_request.destroy if batch_request.present? save! end end |
#return_for_inbox! ⇒ Object
40 41 42 43 44 45 |
# File 'app/models/batch/request_behaviour.rb', line 40 def return_for_inbox! # Valid for started, cancelled and pending batches # Will raise an exception outside of this cancel! if started? detach! unless pending? end |
#with_batch_id {|batch.id| ... } ⇒ Object
28 29 30 |
# File 'app/models/batch/request_behaviour.rb', line 28 def with_batch_id yield batch.id if batch.present? end |