Module: ControlRequestTypeCreation

Defined in:
lib/control_request_type_creation.rb

Instance Method Summary collapse

Instance Method Details

#add_control_request_typeObject


18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/control_request_type_creation.rb', line 18

def add_control_request_type
  RequestType.find_or_create_by(key: key_name) do |crt|
    crt.name               = control_type_name
    crt.request_class_name = 'ControlRequest'
    crt.multiples_allowed  = last_request_type.multiples_allowed
    crt.initial_state      = last_request_type.initial_state
    crt.asset_type         = last_request_type.asset_type
    crt.order              = last_request_type.order
    crt.request_purpose    = :control
  end.tap do |control_request_type|
    self.control_request_type = control_request_type
  end
  self
end

#control_type_nameObject


2
3
4
# File 'lib/control_request_type_creation.rb', line 2

def control_type_name
  key_name.titleize
end

#find_control_typeObject


6
7
8
# File 'lib/control_request_type_creation.rb', line 6

def find_control_type
  RequestType.find_by(key: key_name)
end

#key_nameObject


10
11
12
# File 'lib/control_request_type_creation.rb', line 10

def key_name
  (last_request_type.key || last_request_type.name.gsub(/\s/, '_').downcase) + '_control'
end

#last_request_typeObject


14
15
16
# File 'lib/control_request_type_creation.rb', line 14

def last_request_type
  @last_request_type ||= request_types.last
end