Class: Limber::Helper::RequestTypeConstructor

Inherits:
Object
  • Object
show all
Defined in:
lib/limber/helper.rb

Overview

Build a Limber library creation request type

Instance Method Summary collapse

Constructor Details

#initialize(prefix, request_class: DEFAULT_REQUEST_CLASS, library_types: DEFAULT_LIBRARY_TYPES, default_purposes: DEFAULT_PURPOSES, for_multiplexing: false, product_line: PRODUCTLINE) ⇒ RequestTypeConstructor

Returns a new instance of RequestTypeConstructor


13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/limber/helper.rb', line 13

def initialize(prefix,
               request_class: DEFAULT_REQUEST_CLASS,
               library_types: DEFAULT_LIBRARY_TYPES,
               default_purposes: DEFAULT_PURPOSES,
               for_multiplexing: false,
               product_line: PRODUCTLINE)
  @prefix = prefix
  @request_class = request_class
  @library_types = library_types
  @default_purposes = default_purposes
  @for_multiplexing = for_multiplexing
  @product_line = product_line
end

Instance Method Details

#build!Object

Builds the corresponding request type, unless it already exists.


33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/limber/helper.rb', line 33

def build!
  rt = RequestType.create_with(
    name: "Limber #{@prefix}",
    request_class_name: @request_class,
    asset_type: 'Well',
    order: 1,
    initial_state: 'pending',
    billable: true,
    product_line: ProductLine.find_or_create_by!(name: @product_line),
    request_purpose: :standard,
    for_multiplexing: @for_multiplexing
  ).find_or_create_by!(key: key) do |rt|
    rt.acceptable_plate_purposes = Purpose.where(name: @default_purposes)
  end

  rt_lts = rt.library_types.pluck(:name)
  @library_types.each do |name|
    rt.library_types << LibraryType.find_or_create_by!(name: name) unless rt_lts.include?(name)
  end

  return true if rt.request_type_validators.where(request_option: 'library_type').exists?

  RequestType::Validator.create!(
    request_type: rt,
    request_option: 'library_type',
    valid_options: RequestType::Validator::LibraryTypeValidator.new(rt.id)
  )
end

#keyObject


27
28
29
# File 'lib/limber/helper.rb', line 27

def key
  "limber_#{@prefix.downcase.tr(' ', '_')}"
end