Class: WorkOrder::Factory

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Validations
Defined in:
app/models/work_order/factory.rb

Overview

Builds work orders for a given submission Currently only supports single request type submissions.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(submission) ⇒ Factory

Returns a new instance of Factory.



14
15
16
# File 'app/models/work_order/factory.rb', line 14

def initialize(submission)
  @submission = submission
end

Instance Attribute Details

#submissionObject (readonly)

Returns the value of attribute submission.



8
9
10
# File 'app/models/work_order/factory.rb', line 8

def submission
  @submission
end

Instance Method Details

#create_work_orders!Object



18
19
20
21
22
23
24
25
# File 'app/models/work_order/factory.rb', line 18

def create_work_orders!
  requests
    .group_by(&:asset_id)
    .map do |_asset_id, requests|
      state = requests.first.state
      WorkOrder.create!(work_order_type:, requests:, state:)
    end
end