Module: ThreeScaleToolbox::Helper
- Defined in:
- lib/3scale_toolbox/helper.rb
Defined Under Namespace
Classes: BooleanTransformer
Class Method Summary
collapse
Class Method Details
.application_plan_mapping(source_app_plans, target_app_plans) ⇒ Object
64
65
66
67
68
69
70
71
72
|
# File 'lib/3scale_toolbox/helper.rb', line 64
def application_plan_mapping(source_app_plans, target_app_plans)
mapping = target_app_plans.map do |target|
source = source_app_plans.find do |app_plan|
compare_hashes(app_plan, target, ['system_name'])
end || {}
[source['id'], target]
end
mapping.reject { |key, _| key.nil? }
end
|
.array_difference(ary, other_ary) ⇒ Object
Compute array difference with custom comparator
10
11
12
13
14
15
16
|
# File 'lib/3scale_toolbox/helper.rb', line 10
def array_difference(ary, other_ary)
ary.reject do |ary_elem|
other_ary.find do |other_ary_elem|
yield(ary_elem, other_ary_elem)
end
end
end
|
.compare_hashes(first, second, keys) ⇒ Object
4
5
6
|
# File 'lib/3scale_toolbox/helper.rb', line 4
def compare_hashes(first, second, keys)
keys.map { |key| first.fetch(key, nil) } == keys.map { |key| second.fetch(key, nil) }
end
|
.filter_params(valid_params, source) ⇒ Object
Returns new hash object with not nil valid params
20
21
22
23
24
|
# File 'lib/3scale_toolbox/helper.rb', line 20
def filter_params(valid_params, source)
valid_params.each_with_object({}) do |key, target|
target[key] = source[key] unless source[key].nil?
end
end
|
.hash_deep_dup(hash) ⇒ Object
36
37
38
|
# File 'lib/3scale_toolbox/helper.rb', line 36
def hash_deep_dup(hash)
JSON.parse(JSON.generate(hash))
end
|
.metrics_mapping(source_metrics, target_metrics) ⇒ Object
54
55
56
57
58
59
60
61
62
|
# File 'lib/3scale_toolbox/helper.rb', line 54
def metrics_mapping(source_metrics, target_metrics)
target_metrics.map do |target|
source = source_metrics.find do |m|
compare_hashes(m, target, ['system_name'])
end || {}
[source['id'], target['id']]
end.to_h
end
|
.parse_uri(uri) ⇒ Object
26
27
28
29
30
31
32
33
34
|
# File 'lib/3scale_toolbox/helper.rb', line 26
def parse_uri(uri)
uri_obj = URI(uri)
raise ThreeScaleToolbox::InvalidUrlError, "invalid url: #{uri}" unless uri_obj.kind_of?(URI::HTTP)
uri_obj
end
|
.period_already_taken_error?(error) ⇒ Boolean
50
51
52
|
# File 'lib/3scale_toolbox/helper.rb', line 50
def period_already_taken_error?(error)
Array(Hash(error)['period']).any? { |msg| msg.match(/has already been taken/) }
end
|
.service_invalid_deployment_option?(error) ⇒ Boolean
40
41
42
43
44
|
# File 'lib/3scale_toolbox/helper.rb', line 40
def service_invalid_deployment_option?(error)
Array(Hash(error)['deployment_option']).any? do |msg|
msg.match(/is not included in the list/)
end
end
|
.system_name_already_taken_error?(error) ⇒ Boolean
46
47
48
|
# File 'lib/3scale_toolbox/helper.rb', line 46
def system_name_already_taken_error?(error)
Array(Hash(error)['system_name']).any? { |msg| msg.match(/has already been taken/) }
end
|