Skip to content
This repository has been archived by the owner on May 26, 2021. It is now read-only.

Commit

Permalink
Merge pull request #7 from SmartColumbusOS/add_helper_functions
Browse files Browse the repository at this point in the history
Add helper functions for sourceType
  • Loading branch information
JarredOlson committed Mar 21, 2019
2 parents 1e5146f + 468e874 commit 4d54003
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 3 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const Dataset = {
"dataName": "", // ~r/[a-zA-Z_]+$/
"orgName": "", // ~r/[a-zA-Z_]+$/
"systemName": "", // ${orgName}__${dataName},
"stream": true,
"stream": true, //DEPRECATED - See sourceType
"schema": [
{
"name": "",
Expand All @@ -32,6 +32,7 @@ const Dataset = {
],
"sourceUrl": "",
"sourceFormat": "",
"sourceType": "", // remote|stream|batch
"cadence": "",
"queryParams": {
"key1": "",
Expand Down
21 changes: 21 additions & 0 deletions lib/smart_city/dataset.ex
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,27 @@ defmodule SmartCity.Dataset do
handle_ok_error(fn -> get_all() end)
end

@doc """
Returns true if `SmartCity.Dataset.Technical sourceType field is stream`
"""
def is_stream?(%__MODULE__{technical: %{sourceType: sourceType}}) do
"stream" == sourceType
end

@doc """
Returns true if `SmartCity.Dataset.Technical sourceType field is remote`
"""
def is_remote?(%__MODULE__{technical: %{sourceType: sourceType}}) do
"remote" == sourceType
end

@doc """
Returns true if `SmartCity.Dataset.Technical sourceType field is batch`
"""
def is_batch?(%__MODULE__{technical: %{sourceType: sourceType}}) do
"batch" == sourceType
end

defp add_to_history(%__MODULE__{id: id} = dataset) do
body = %{creation_ts: DateTime.utc_now() |> DateTime.to_iso8601(), dataset: dataset}
Redix.command!(@conn, ["RPUSH", history_key(id), Jason.encode!(body)])
Expand Down
5 changes: 3 additions & 2 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule SmartCity.Registry.MixProject do
def project do
[
app: :smart_city_registry,
version: "2.2.0",
version: "2.3.0",
elixir: "~> 1.8",
start_permanent: Mix.env() == :prod,
deps: deps(),
Expand Down Expand Up @@ -33,7 +33,8 @@ defmodule SmartCity.Registry.MixProject do
{:credo, "~> 0.10", only: [:dev, :test, :integration], runtime: false},
{:divo, "~> 1.0", organization: "smartcolumbus_os", only: [:dev, :test, :integration]},
{:placebo, "~> 1.2", only: [:dev, :test, :integration]},
{:mix_test_watch, "~> 0.9.0", only: :dev, runtime: false}
{:mix_test_watch, "~> 0.9.0", only: :dev, runtime: false},
{:checkov, "~> 0.4.0", only: :test}
]
end

Expand Down
1 change: 1 addition & 0 deletions mix.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
%{
"bunt": {:hex, :bunt, "0.2.0", "951c6e801e8b1d2cbe58ebbd3e616a869061ddadcc4863d0a2182541acae9a38", [:mix], [], "hexpm"},
"checkov": {:hex, :checkov, "0.4.0", "a1974a5885f62f8943a9059f0d5252b222271e0e58dd872ffb60323f2e376433", [:mix], [], "hexpm"},
"credo": {:hex, :credo, "0.10.2", "03ad3a1eff79a16664ed42fc2975b5e5d0ce243d69318060c626c34720a49512", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm"},
"dialyxir": {:hex, :dialyxir, "0.5.1", "b331b091720fd93e878137add264bac4f644e1ddae07a70bf7062c7862c4b952", [:mix], [], "hexpm"},
"divo": {:hex, :divo, "1.0.0", "58295174346d49f451b0c1a254096df5c83c1e93ed53c53c3ec4888c105ac4d6", [:mix], [{:jason, "~> 1.1", [hex: :jason, repo: "hexpm", optional: false]}, {:patiently, "~> 0.2.0", [hex: :patiently, repo: "hexpm", optional: false]}], "hexpm:smartcolumbus_os"},
Expand Down
29 changes: 29 additions & 0 deletions test/unit/smart_city/dataset_test.exs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
defmodule SmartCity.DatasetTest do
use ExUnit.Case
use Placebo
import Checkov
doctest SmartCity.Dataset
alias SmartCity.Dataset
alias SmartCity.Dataset.{Business, Technical}
Expand Down Expand Up @@ -114,4 +115,32 @@ defmodule SmartCity.DatasetTest do
end
end
end

describe "sourceType function:" do
data_test "#{inspect(func)} returns #{expected} when sourceType is #{sourceType}", %{message: msg} do
result =
msg
|> put_in(["technical", "sourceType"], sourceType)
|> Dataset.new()
|> ok()
|> func.()

assert result == expected

where([
[:func, :sourceType, :expected],
[&Dataset.is_stream?/1, "stream", true],
[&Dataset.is_stream?/1, "remote", false],
[&Dataset.is_stream?/1, "batch", false],
[&Dataset.is_batch?/1, "batch", true],
[&Dataset.is_batch?/1, "stream", false],
[&Dataset.is_batch?/1, "remote", false],
[&Dataset.is_remote?/1, "remote", true],
[&Dataset.is_remote?/1, "stream", false],
[&Dataset.is_remote?/1, "batch", false]
])
end
end

defp ok({:ok, value}), do: value
end

0 comments on commit 4d54003

Please sign in to comment.