Skip to content

Commit

Permalink
re #41 cleanup moving the pipe operator
Browse files Browse the repository at this point in the history
  • Loading branch information
Low Kian Seong committed Nov 7, 2016
1 parent d9ad0a8 commit c3fc62e
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 53 deletions.
37 changes: 18 additions & 19 deletions lib/Radpath/files.ex
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ defmodule Radpath.Files do
end
expanded_path = Path.expand(path)
case File.exists? expanded_path do
true -> Finder.new() |>
Finder.only_files() |>
Finder.with_file_endings(file_ext) |>
Finder.find(expanded_path) |>
Enum.to_list
true -> Finder.new()
|> Finder.only_files()
|> Finder.with_file_endings(file_ext)
|> Finder.find(expanded_path)
|> Enum.to_list
false -> []
end
end
Expand All @@ -80,10 +80,10 @@ Listing down all files in the "ci" folder without filtering:
def files(path) when is_bitstring(path) do
expanded_path = Path.expand(path)
case File.exists? expanded_path do
true -> Finder.new() |>
Finder.only_files() |>
Finder.find(expanded_path) |>
Enum.to_list
true -> Finder.new()
|> Finder.only_files()
|> Finder.find(expanded_path)
|> Enum.to_list
false -> []
end
end
Expand Down Expand Up @@ -136,26 +136,25 @@ Listing down all files in the "ci" folder without filtering:
defp ext_file_list(path, file_ext) do
expanded_path = Path.expand(path)
case File.exists? expanded_path do
true -> Finder.new() |>
Finder.only_files() |>
Finder.with_file_endings(file_ext) |>
Finder.find(expanded_path) |>
Enum.to_list
true -> Finder.new()
|> Finder.only_files()
|> Finder.with_file_endings(file_ext)
|> Finder.find(expanded_path)
|> Enum.to_list
false -> []
end
end

defp files_list(path) when is_bitstring(path) do
expanded_path = Path.expand(path)
case File.exists? expanded_path do
true -> Finder.new() |>
Finder.only_files() |>
Finder.find(expanded_path) |>
Enum.to_list
true -> Finder.new()
|> Finder.only_files()
|> Finder.find(expanded_path)
|> Enum.to_list
false -> []
end
end

end
end
end
12 changes: 2 additions & 10 deletions lib/Radpath/tempfs.ex
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,7 @@ defmodule Radpath.Tempfs do

@spec mktempdir :: none
def mktempdir do
# temp_name = Tempfile.get_name
# temp_name |> Path.rootname |> do_mkdir
# temp_name
{status, path_name} = Temp.mkdir %{basedir: "/tmp"}
path_name
Temp.mkdir(%{basedir: "/tmp"}) |> tap({_, path_name} ~> path_name)
end
@doc """
To create a temp dir at a specific location:
Expand All @@ -95,11 +91,7 @@ defmodule Radpath.Tempfs do

@spec mktempdir(bitstring) :: none
def mktempdir(path) when is_bitstring(path) do
# Tempfile.get_name([path: make_into_path(path)]) |>
# Path.rootname |>
# do_mkdir
{status, path_name} = Temp.mkdir %{basedir: path}
path_name
Temp.mkdir(%{basedir: path}) |> tap({_, path_name} ~> path_name)
end

end
Expand Down
3 changes: 2 additions & 1 deletion lib/radpath.ex
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
defmodule Radpath do
alias :file, as: F
alias :zip, as: Z
use PatternTap
use Application
use Radpath.Dirs
use Radpath.Files
use Radpath.Tempfs

def start(_type, _args) do
Radpath.Supervisor.start_link
end
Expand Down
Binary file added otp_src_18.0.tar.gz
Binary file not shown.
53 changes: 30 additions & 23 deletions test/radpath_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,26 @@ defmodule RadpathTests.RadpathFacts do
use PatternTap

import PathHelpers
import Path, only: [basename: 1]
import Path, only: [basename: 1]
import Enum, only: [map: 2]

alias :file, as: F

defmodule ZippingTest do

use ExUnit.Case
def path_exists(path) do
assert File.exists?(path)
end

test "zip" do
try do
Path.join(fixture_path, "Testdir1.zip") |> File.exists? |> refute
Radpath.zip([fixture_path], "Testdir1.zip")
"Testdir1.zip" |> File.exists?
System.cmd("zip",["-T","Testdir1.zip"]) |> (&(assert &1 = {"test of Testdir1.zip OK\n", 0})).()
System.cmd("zipinfo",["-1","Testdir1.zip"]) |>
tap({result_str, _} ~> result_str) |>
(&(String.contains?(&1, "testdir1"))).()

System.cmd("zipinfo",["-1","Testdir1.zip"])
|> tap({result_str, _} ~> result_str)
|> (&(String.contains?(&1, "testdir1"))).()

after
File.rm_rf("Testdir1.zip")
end
Expand All @@ -40,9 +39,9 @@ defmodule RadpathTests.RadpathFacts do
Radpath.zip([dir], "Testdir2.zip")
"Testdir2.zip" |> File.exists?

System.cmd("zip",["-T","Testdir2.zip"]) |>
tap({result_str, _} ~> result_str) |>
String.strip |> (&( assert &1 == "test of Testdir2.zip OK")).()
System.cmd("zip",["-T","Testdir2.zip"])
|> tap({result_str, _} ~> result_str)
|> String.strip |> (&(assert &1 == "test of Testdir2.zip OK")).()

System.cmd("zipinfo",["-1","Testdir2.zip"]) |>
tap({result_str2, _} ~> result_str2) |>
Expand Down Expand Up @@ -96,8 +95,9 @@ defmodule RadpathTests.RadpathFacts do

test "zip: path that does not exist" do
try do
Path.join(fixture_path, "Testdir-dont-exist.zip") |>
File.exists? |> refute
Path.join(fixture_path, "Testdir-dont-exist.zip")
|> File.exists?
|> refute
Radpath.zip(["/gogo/I/don/exist"], "Testdir-dont-exist.zip")
after
"Testdir-dont-exist.zip" |> File.exists? |> refute
Expand All @@ -107,7 +107,7 @@ defmodule RadpathTests.RadpathFacts do
end

defmodule FilteringTest do
use ExUnit.Case
use ExUnit.Case

@dud_files ["testfile1.dud, file3.dud"]
@test_files ["testdir3", "testdir2", "testdir1"]
Expand Down Expand Up @@ -145,26 +145,37 @@ defmodule RadpathTests.RadpathFacts do
end

test "Filtering Files" do
Radpath.files(fixture_path, "log") |> map(&basename(&1)) |> (&(assert &1 == ["file3.log"])).()
Radpath.files(fixture_path, "log")
|> map(&basename(&1))
|> (&(assert &1 == ["file3.log"])).()
end

test "Filtering Files with Lists" do
Radpath.files(["test", "lib"], @file_ext) |> map(&basename(&1)) |> Enum.sort |> (&(assert &1 == @long_file_list)).()
Radpath.files(["test", "lib"], @file_ext)
|> map(&basename(&1))
|> Enum.sort
|> (&(assert &1 == @long_file_list)).()
end

test "Filtering with Expanded Paths" do
Radpath.files("test/fixtures", "log") |> map(&basename(&1)) |> (&(assert &1 == ["file3.log"])).()
Radpath.files("test/fixtures", "log")
|> map(&basename(&1))
|> (&(assert &1 == ["file3.log"])).()
end

test "Filtering Multiple filter for Files" do
files = Radpath.files(fixture_path, @file_ext) |> map(&basename(&1))
files |> Enum.sort |> (&(assert &1 == @long_file_list)).()
files
|> Enum.sort
|> (&(assert &1 == @long_file_list)).()
Enum.all?(@file_list, fn(x) -> Enum.member?(files, x) end)
end

test "Filtering long file list" do
files = Radpath.files(fixture_path, @file_ext) |> Enum.map(&Path.basename(&1))
files |> Enum.sort |> (&(assert &1 == @long_file_list)).()
files
|> Enum.sort
|> (&(assert &1 == @long_file_list)).()
Enum.all?(@file_list, fn(x) -> Enum.member?(files, x) end)
end

Expand Down Expand Up @@ -306,8 +317,6 @@ defmodule RadpathTests.RadpathFacts do
File.write("/tmp/hoho.txt", "test mv")
try do
"/tmp/hoho.txt" |> File.exists?
# md5sum_source = Radpath.md5sum(@source_file)
# original_md5sum = Radpath.md5sum("/tmp/hoho.txt")
File.cp("/tmp/hoho.txt", "/tmp/hihi.txt")
Radpath.mv("/tmp/hoho.txt", "/tmp/hehe.txt")
refute "/tmp/hoho.txt" |> File.exists?
Expand All @@ -320,7 +329,6 @@ defmodule RadpathTests.RadpathFacts do

test "Test rename: Source file does not exist" do
refute @source_file |> File.exists?
# Radpath.rename("/tmp/hoho.txt", "/tmp/hehe.txt")
Radpath.rename(@source_file, @dest_file)
refute @source_file |> File.exists?
end
Expand Down Expand Up @@ -353,8 +361,7 @@ defmodule RadpathTests.RadpathFacts do
end

defmodule TestEnsure do
use ExUnit.Case

use ExUnit.Case
test "Test ensure: Ensure Directory is created" do
test_dir_path = Path.join(fixture_path, "gogo/gaga")
refute test_dir_path |> File.exists?
Expand Down

0 comments on commit c3fc62e

Please sign in to comment.