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

rubocop:todo Metrics/ParameterLists


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

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.


38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/limber/helper.rb', line 38

def build! # rubocop:todo Metrics/AbcSize
  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)

  rt.acceptable_plate_purposes = Purpose.where(name: @default_purposes)
  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.exists?(request_option: 'library_type')

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

#keyObject

rubocop:enable Metrics/ParameterLists


32
33
34
# File 'lib/limber/helper.rb', line 32

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