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


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

def initialize(submission)
  @submission = submission
end

Instance Attribute Details

#submissionObject (readonly)

Returns the value of attribute submission


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

def submission
  @submission
end

Instance Method Details

#create_work_orders!Object


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

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