Module: RuleInterface::Converter

Extended by:
Converter
Included in:
Converter
Defined in:
lib/rule-interface/converter.rb

Constant Summary collapse

OUT_IDENTIFIER_ID =
:rule_interface_out_identifier_id

Instance Method Summary collapse

Instance Method Details

#drool_to_hash(response_data:) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/rule-interface/converter.rb', line 37

def drool_to_hash(response_data:)
  result_hash = Hash.new {|h,k| h[k] = [] }
  response_data.each do |data|
    object_type = data[:value].keys[0].to_s.split('.').last.underscore.to_sym

    data_object = data[:value][data[:value].keys[0]]
    data_object = data_object.inject({}) { |m, (k,v)| m[k.to_s.underscore.to_sym] = v; m }

    result_hash[object_type] << data_object
  end
  result_hash
end

#hash_to_drool(data_hash:, namespace:, package:, session:) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/rule-interface/converter.rb', line 7

def hash_to_drool(data_hash:, namespace:, package:, session:)
  payload = {}
  payload[:lookup] = session
  payload[:commands] = []

  Thread.current[OUT_IDENTIFIER_ID] = 1

  #insert namespace object
  if namespace
    payload[:commands] << insert_object(
      data_object: {name: namespace},
      object_type: 'namespace',
      package: package,
      return_object: false
    )
  end

  data_hash.each do |object_type, data_objects|
    data_objects = [data_objects] unless data_objects.is_a? Array
    data_objects.each do |data_object|
      payload[:commands] << insert_object(
        data_object: data_object,
        object_type: object_type,
        package: package
      )
    end
  end
  payload
end