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
54
55
56
57
58
59
|
# File 'lib/3scale_toolbox/helper.rb', line 54
def application_plan_mapping(source_app_plans, target_app_plans)
target_app_plans.map do |target|
source = source_app_plans.find { |app_plan| app_plan.system_name == target.system_name }
[source, target]
end.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
|
.backend_metric_link_parser(link) ⇒ Object
65
66
67
68
69
|
# File 'lib/3scale_toolbox/helper.rb', line 65
def backend_metric_link_parser(link)
return if link.nil?
link.match(/admin\/api\/backend_apis\/(\d+)\/metrics/) { |m| m.captures[0] }
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
|
.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
|
.random_lowercase_name(length = 8) ⇒ Object
61
62
63
|
# File 'lib/3scale_toolbox/helper.rb', line 61
def random_lowercase_name(length=8)
[*('a'..'z')].sample(length).join
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
|