Class: Fastlane::JSONReturnValueProcessor

Inherits:
Object
  • Object
show all
Defined in:
fastlane/lib/fastlane/server/json_return_value_processor.rb

Instance Method Summary collapse

Instance Method Details

#prepare_object(return_value: nil, return_value_type: nil) ⇒ Object


5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'fastlane/lib/fastlane/server/json_return_value_processor.rb', line 5

def prepare_object(return_value: nil, return_value_type: nil)
  case return_value_type
  when nil
    UI.verbose("return_value_type is nil value: #{return_value}")
    return process_value_as_string(return_value: return_value)
  when :string
    return process_value_as_string(return_value: return_value)
  when :int
    return process_value_as_int(return_value: return_value)
  when :bool
    return process_value_as_bool(return_value: return_value)
  when :array_of_strings
    return process_value_as_array_of_strings(return_value: return_value)
  when :hash_of_strings
    return process_value_as_hash_of_strings(return_value: return_value)
  when :hash
    return process_value_as_hash_of_strings(return_value: return_value)
  else
    UI.verbose("Unknown return type defined: #{return_value_type} for value: #{return_value}")
    return process_value_as_string(return_value: return_value)
  end
end

#process_value_as_array_of_strings(return_value: nil) ⇒ Object


36
37
38
39
40
41
42
43
# File 'fastlane/lib/fastlane/server/json_return_value_processor.rb', line 36

def process_value_as_array_of_strings(return_value: nil)
  if return_value.nil?
    return_value = []
  end

  # quirks_mode shouldn't be required for real objects
  return JSON.generate(return_value)
end

#process_value_as_bool(return_value: nil) ⇒ Object


54
55
56
57
58
59
60
61
# File 'fastlane/lib/fastlane/server/json_return_value_processor.rb', line 54

def process_value_as_bool(return_value: nil)
  if return_value.nil?
    return_value = false
  end

  # quirks_mode because sometimes the built-in library is used for some folks and that needs quirks_mode: true
  return JSON.generate(return_value.to_s, quirks_mode: true)
end

#process_value_as_hash_of_strings(return_value: nil) ⇒ Object


45
46
47
48
49
50
51
52
# File 'fastlane/lib/fastlane/server/json_return_value_processor.rb', line 45

def process_value_as_hash_of_strings(return_value: nil)
  if return_value.nil?
    return_value = {}
  end

  # quirks_mode shouldn't be required for real objects
  return JSON.generate(return_value)
end

#process_value_as_int(return_value: nil) ⇒ Object


63
64
65
66
67
68
69
70
# File 'fastlane/lib/fastlane/server/json_return_value_processor.rb', line 63

def process_value_as_int(return_value: nil)
  if return_value.nil?
    return_value = 0
  end

  # quirks_mode because sometimes the built-in library is used for some folks and that needs quirks_mode: true
  return JSON.generate(return_value.to_s, quirks_mode: true)
end

#process_value_as_string(return_value: nil) ⇒ Object


28
29
30
31
32
33
34
# File 'fastlane/lib/fastlane/server/json_return_value_processor.rb', line 28

def process_value_as_string(return_value: nil)
  if return_value.nil?
    return_value = ""
  end

  return_value
end