Module: ControlRequestTypeCreation

Defined in:
lib/control_request_type_creation.rb

Instance Method Summary collapse

Instance Method Details

#add_control_request_typeObject

rubocop:todo Metrics/AbcSize, Metrics/MethodLength



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

def add_control_request_type # rubocop:todo Metrics/AbcSize, Metrics/MethodLength
  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 { |control_request_type| self.control_request_type = control_request_type }
  self
end

#control_type_nameObject



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

def control_type_name
  key_name.titleize
end

#find_control_typeObject



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

def find_control_type
  RequestType.find_by(key: key_name)
end

#key_nameObject



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

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

#last_request_typeObject



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

def last_request_type
  @last_request_type ||= request_types.last
end