Current section
2 Versions
Jump to
Current section
2 Versions
Compare versions
6
files changed
+46
additions
-6
deletions
| @@ -1,15 +1,24 @@ | |
| 1 1 | Changelog for Socket Address |
| 2 2 | ============================ |
| 3 3 | |
| 4 | - All notable changes to this project will be documented in this file. |
| 4 | + All notable changes to the project will be documented in this file. |
| 5 5 | |
| 6 6 | [HEAD][] / unreleased |
| 7 7 | --------------------- |
| 8 8 | |
| 9 | + [v0.2.0][] / 2017-01-03 |
| 10 | + ----------------------- |
| 11 | + |
| 12 | + ### Added |
| 13 | + |
| 14 | + * `SocketAddress.to_opts/2` helper function for generating Cowboy options. |
| 15 | + * Repository metadata so documentation will automatically link to source files. |
| 16 | + |
| 9 17 | [v0.1.0][] / 2016-12-30 |
| 10 18 | ----------------------- |
| 11 19 | |
| 12 20 | * Initial project release. |
| 13 21 | |
| 14 | - [HEAD]: https://github.com/elasticdog/socket_address/compare/v0.1.0...master |
| 22 | + [HEAD]: https://github.com/elasticdog/socket_address/compare/v0.2.0...master |
| 23 | + [v0.2.0]: https://github.com/elasticdog/socket_address/compare/v0.1.0...v0.2.0 |
| 15 24 | [v0.1.0]: https://github.com/elasticdog/socket_address/tree/v0.1.0 |
| @@ -1,4 +1,4 @@ | |
| 1 | - Copyright (c) 2016, Aaron Bull Schaefer <aaron@elasticdog.com> |
| 1 | + Copyright (c) 2016-2017, Aaron Bull Schaefer <aaron@elasticdog.com> |
| 2 2 | |
| 3 3 | Permission to use, copy, modify, and/or distribute this software for any |
| 4 4 | purpose with or without fee is hereby granted, provided that the above |
| @@ -20,6 +20,8 @@ iex> socket_address.ip | |
| 20 20 | {127, 0, 0, 1} |
| 21 21 | iex> socket_address.port |
| 22 22 | 80 |
| 23 | + iex> SocketAddress.to_opts(socket_address, [compress: true]) |
| 24 | + [ip: {127, 0, 0, 1}, port: 80, compress: true] |
| 23 25 | |
| 24 26 | iex> {:ok, socket_address} = SocketAddress.new("fe80::204:acff:fe17:bf38", 80) |
| 25 27 | iex> socket_address |
| @@ -105,4 +107,4 @@ License | |
| 105 107 | Socket Address is provided under the terms of the |
| 106 108 | [ISC License](https://en.wikipedia.org/wiki/ISC_license). |
| 107 109 | |
| 108 | - Copyright © 2016, [Aaron Bull Schaefer](mailto:aaron@elasticdog.com). |
| 110 | + Copyright © 2016-2017, [Aaron Bull Schaefer](mailto:aaron@elasticdog.com). |
| @@ -12,4 +12,4 @@ | |
| 12 12 | {<<"maintainers">>,[<<"Aaron Bull Schaefer">>]}. |
| 13 13 | {<<"name">>,<<"socket_address">>}. |
| 14 14 | {<<"requirements">>,[]}. |
| 15 | - {<<"version">>,<<"0.1.0">>}. |
| 15 | + {<<"version">>,<<"0.2.0">>}. |
| @@ -98,6 +98,33 @@ defmodule SocketAddress do | |
| 98 98 | end |
| 99 99 | end |
| 100 100 | defp parse(_), do: nil |
| 101 | + |
| 102 | + @doc """ |
| 103 | + Converts a socket address to an options keyword list. |
| 104 | + |
| 105 | + Returns a keyword list of the socket address `ip` and `port` fields merged |
| 106 | + with any provided `opts`. All keys, including duplicated keys, given in |
| 107 | + `opts` will be added to the socket address fields, overriding any existing |
| 108 | + one. |
| 109 | + |
| 110 | + ## Examples |
| 111 | + |
| 112 | + iex> {:ok, socket_address} = SocketAddress.new("127.0.0.1", 80) |
| 113 | + iex> SocketAddress.to_opts(socket_address) |
| 114 | + [ip: {127, 0, 0, 1}, port: 80] |
| 115 | + |
| 116 | + iex> {:ok, socket_address} = SocketAddress.new("127.0.0.1", 80) |
| 117 | + iex> SocketAddress.to_opts(socket_address, [compress: true]) |
| 118 | + [ip: {127, 0, 0, 1}, port: 80, compress: true] |
| 119 | + |
| 120 | + iex> {:ok, socket_address} = SocketAddress.new("127.0.0.1", 80) |
| 121 | + iex> SocketAddress.to_opts(socket_address, [port: 8888]) |
| 122 | + [ip: {127, 0, 0, 1}, port: 8888] |
| 123 | + """ |
| 124 | + @spec to_opts(t, Keyword.t) :: Keyword.t |
| 125 | + def to_opts(%SocketAddress{ip: ip, port: port}, opts \\ []) do |
| 126 | + Keyword.merge([ip: ip, port: port], opts) |
| 127 | + end |
| 101 128 | end |
Loading more files…