Skip to content

Commit

Permalink
Simplyfying and updating code
Browse files Browse the repository at this point in the history
  • Loading branch information
lowks committed Feb 2, 2015
1 parent c804c22 commit fb8b91d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 20 deletions.
13 changes: 3 additions & 10 deletions lib/Radpath/directory.ex
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ defmodule Radpath.Dirs do
"""

def dirs(path, regex_dir \\ "") when (is_bitstring(path) or is_list(path)) do
def dirs(path, regex_dir \\ ".+") when (is_bitstring(path) or is_list(path)) do
file_path = case String.valid? path do
true -> [path]
false -> path
Expand All @@ -39,21 +39,14 @@ defmodule Radpath.Dirs do
end

defp dirs_list(path, regex_dir) when is_bitstring(path) do
if regex_dir |> String.length == 0 do
Finder.new()
|> Finder.only_directories()
|> Finder.find(Path.expand(path))
|> Enum.to_list
|> Enum.sort
else
Finder.new()
|> Finder.with_directory_regex(Regex.compile!(regex_dir))
|> Finder.only_directories()
|> Finder.find(Path.expand(path))
|> Enum.to_list
|> Enum.sort
end
end
end

end
end
end
25 changes: 15 additions & 10 deletions lib/radpath.ex
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ defmodule Radpath do
F.rename(source, destination)
end

@doc ~S"""
@doc """
Gives you back the relative path:
## Arguments
Expand Down Expand Up @@ -173,26 +173,27 @@ defmodule Radpath do
## Arguments
* `path` - The path which you want parent_path returned.
- `path` - The path which you want parent_path returned.
## Usage
Radpath.parent_path(path).
"""
def parent_path(path) when is_bitstring(path) do
Path.absname(path) |>
String.split(Path.basename(path)) |>
List.first
Path.absname(path)
|> String.split(Path.basename(path))
|> List.first
end

@doc """
Ensures that a directory/file is created. If is_file is set to true then file is created.
## Arguments
* `path` - Path that is to be created
* `is_file` - Boolean, indicating if path is a file, if true then ensure will create file. Default false (directory).
- `path` - Path that is to be created
- `is_file` - Boolean, indicating if path is a file, if true then ensure will create file. Default false (directory).
## Usage
Expand Down Expand Up @@ -256,7 +257,9 @@ defmodule Radpath do
true ->
case File.dir?(path) do
true -> :error
false -> File.read!(path) |> :ec_file.md5sum |> to_string
false -> File.read!(path)
|> :ec_file.md5sum
|> to_string
end
false -> :error
end
Expand All @@ -283,7 +286,9 @@ defmodule Radpath do
true ->
case File.dir?(path) do
true -> :error
false -> File.read!(path) |> :ec_file.sha1sum |> to_string
false -> File.read!(path)
|> :ec_file.sha1sum
|> to_string
end
false -> :error
end
Expand All @@ -302,4 +307,4 @@ defmodule Radpath do
Path.absname(path_str) <> "/"
end

end
end

0 comments on commit fb8b91d

Please sign in to comment.