lib/3scale_toolbox/helper.rb in 3scale_toolbox-0.8.0 vs lib/3scale_toolbox/helper.rb in 3scale_toolbox-0.9.0

- old
+ new

@@ -31,12 +31,53 @@ raise ThreeScaleToolbox::InvalidUrlError, "invalid url: #{uri}" unless uri_obj.kind_of?(URI::HTTP) uri_obj end + def hash_deep_dup(hash) + JSON.parse(JSON.generate(hash)) + end + def service_invalid_deployment_option?(error) Array(Hash(error)['deployment_option']).any? do |msg| msg.match(/is not included in the list/) + end + end + + def system_name_already_taken_error?(error) + Array(Hash(error)['system_name']).any? { |msg| msg.match(/has already been taken/) } + end + + def period_already_taken_error?(error) + Array(Hash(error)['period']).any? { |msg| msg.match(/has already been taken/) } + end + end + + class BooleanTransformer + def call(param_str) + raise ArgumentError unless param_str.is_a?(String) + + return true if true?(param_str) + return false if false?(param_str) + + raise ArgumentError + end + + def true?(param_str) + case param_str + when 'true', '1' + true + else + false + end + end + + def false?(param_str) + case param_str + when 'false', '0' + true + else + false end end end end end