View Source ExAws.CodeDeploy.Utils (ex_aws_code_deploy v2.1.0)

Helper utility functions

Summary

Types

The camelize, camelize_list, and camelize_map take an argument that is a data structure providing rules for capitalization.

Types

@type camelize_rules() :: %{
  optional(:subkeys) => map(),
  optional(:keys) => map(),
  default: :upper | :lower
}

The camelize, camelize_list, and camelize_map take an argument that is a data structure providing rules for capitalization.

  • subkeys - this provides a map that indicates how keys found under this particular key should be camelized
  • keys - this provides a map that indicate how particular keys should be camelized
  • default - indicates whether :upper or :lower is used by default

Functions

Link to this function

camelize(val, camelize_rules \\ %{default: :lower, keys: %{}, subkeys: %{ec2_tag_filters: %{key: :upper, type: :upper, value: :upper}, ec2_tag_set: %{key: :upper, type: :upper, value: :upper}, on_premises_instance_tag_filters: %{key: :upper, type: :upper, value: :upper}, tag_filters: %{key: :upper, type: :upper, value: :upper}, tags: %{key: :upper, value: :upper}, target_filters: %{service_instance_label: :upper, target_status: :upper}}})

View Source
@spec camelize(atom() | binary(), camelize_rules()) :: binary()

Camelize an atom or string value

This works as expected if the val uses an underscore or hyphen to separate words. This only works for atoms and strings. Passing another value type (integer, list, map) will raise exception.

Example

iex> ExAws.CodeDeploy.Utils.camelize(:test_val)
"testVal"

iex> ExAws.CodeDeploy.Utils.camelize("test_val")
"testVal"

iex> ExAws.CodeDeploy.Utils.camelize("abc-def-a123")
"abcDefA123"

iex> ExAws.CodeDeploy.Utils.camelize(:A_test_of_initial_cap)
"aTestOfInitialCap"
Link to this function

camelize_map(val, camelize_rules \\ %{default: :lower, keys: %{}, subkeys: %{ec2_tag_filters: %{key: :upper, type: :upper, value: :upper}, ec2_tag_set: %{key: :upper, type: :upper, value: :upper}, on_premises_instance_tag_filters: %{key: :upper, type: :upper, value: :upper}, tag_filters: %{key: :upper, type: :upper, value: :upper}, tags: %{key: :upper, value: :upper}, target_filters: %{service_instance_label: :upper, target_status: :upper}}})

View Source

Camelize Map keys, including traversing values that are also Maps.

The caller can pass in an argument to indicate whether the first letter of a key for the map are downcased or capitalized.

Keys should be atoms and follow the rules listed for the camelize/2 function.

Example

iex> val = %{abc_def: 123, another_val: "val2"}
iex> ExAws.CodeDeploy.Utils.camelize_map(val)
%{"abcDef" => 123, "anotherVal" => "val2"}

iex> val = %{abc_def: 123, another_val: %{embed_value: "val2"}}
iex> ExAws.CodeDeploy.Utils.camelize_map(val)
%{"abcDef" => 123, "anotherVal" => %{"embedValue" => "val2"}}

iex> val = %{abc_def: 123, another_val: %{embed_value: "val2"}}
iex> ExAws.CodeDeploy.Utils.camelize_map(val, %{subkeys: %{}, keys: %{}, default: :upper})
%{"AbcDef" => 123, "AnotherVal" => %{"EmbedValue" => "val2"}}
@spec camelize_rules() :: camelize_rules()

Return the default camelize rules

A caller can override this by creating a camelize_rules/0 and passing it into functions instead of the default.

If val is a Keyword then convert to a Map, else return val

Examples

iex> ExAws.CodeDeploy.Utils.keyword_to_map([{:a, 7}, {:b, "abc"}])
%{a: 7, b: "abc"}

iex> ExAws.CodeDeploy.Utils.keyword_to_map(%{a: 7, b: %{c: "abc"}})
%{a: 7, b: %{c: "abc"}}

iex> ExAws.CodeDeploy.Utils.keyword_to_map([1, 2, 3])
[1, 2, 3]

Take the various forms of allowed paging options and create a %{next_token: val}

Examples

# Passing an unexpected value (no paging found) returns an empty map
iex> ExAws.CodeDeploy.Utils.normalize_paging([])
%{}

# Different approaches to defining Keyword list work
iex> ExAws.CodeDeploy.Utils.normalize_paging([{:next_token, "123"}])
%{next_token: "123"}

iex> ExAws.CodeDeploy.Utils.normalize_paging([next_token: "123"])
%{next_token: "123"}

# Pass a tuple, no list
iex> ExAws.CodeDeploy.Utils.normalize_paging({:next_token, "123"})
%{next_token: "123"}

# Pass in data already formatted, returns the same data
iex> ExAws.CodeDeploy.Utils.normalize_paging(%{next_token: "123"})
%{next_token:  "123"}

Take a list of tag and convert it into a list where each elemet is a map with atom keys.

Examples

iex> ExAws.CodeDeploy.Utils.normalize_tags([])
[]

iex> ExAws.CodeDeploy.Utils.normalize_tags([{"my_key", "value1"}])
[%{key: "my_key", value: "value1"}]