module ThreeScaleToolbox::Helper

Public Class Methods

application_plan_mapping(source_app_plans, target_app_plans) click to toggle source
# 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) { |ary_elem, other_ary_elem| ... } click to toggle source

Compute array difference with custom comparator

# 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) click to toggle source
# 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) click to toggle source

Returns new hash object with not nil valid params

# 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) click to toggle source
# File lib/3scale_toolbox/helper.rb, line 36
def hash_deep_dup(hash)
  JSON.parse(JSON.generate(hash))
end
parse_uri(uri) click to toggle source
# File lib/3scale_toolbox/helper.rb, line 26
def parse_uri(uri)
  # raises error when remote_str is not string, but object or something else.
  uri_obj = URI(uri)
  # URI::HTTP is parent of URI::HTTPS
  # with single check both types are checked
  raise ThreeScaleToolbox::InvalidUrlError, "invalid url: #{uri}" unless uri_obj.kind_of?(URI::HTTP)

  uri_obj
end
period_already_taken_error?(error) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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