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.

[View source]

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

def initialize(submission)
  @submission = submission
end

Instance Attribute Details

#submissionObject (readonly)

Returns the value of attribute submission.


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

def submission
  @submission
end

Instance Method Details

#create_work_orders!Object

[View source]

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

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