File tree Expand file tree Collapse file tree 3 files changed +15
-12
lines changed Expand file tree Collapse file tree 3 files changed +15
-12
lines changed Original file line number Diff line number Diff line change @@ -44,7 +44,7 @@ Start a mix session with `iex -S mix` and type the following instructions
4444path = Path .expand (" ~/workspace/elixir-docker-guide" )
4545
4646{:ok , image_id} = Path .join ([path, " Dockerfile" ]) |>
47- ExDockerBuild .DockerfileParser .parse ! () |>
47+ ExDockerBuild .DockerfileParser .parse_file ! () |>
4848 ExDockerBuild .DockerBuild .build (path)
4949```
5050
@@ -68,7 +68,7 @@ $> mkdir ~/test
6868path = Path .expand (" ./test/fixtures" )
6969
7070{:ok , image_id} = Path .join ([path, " Dockerfile_bind.dockerfile" ]) |>
71- ExDockerBuild .DockerfileParser .parse ! () |>
71+ ExDockerBuild .DockerfileParser .parse_file ! () |>
7272 ExDockerBuild .DockerBuild .build (path)
7373```
7474
Original file line number Diff line number Diff line change @@ -3,15 +3,18 @@ defmodule ExDockerBuild.DockerfileParser do
33 @ continuation ~r/ ^.*\\ \s *$/
44 @ instruction ~r/ ^\s *(\w +)\s +(.*)$/
55
6- @ spec parse! ( Path . t ( ) | String . t ( ) ) :: list ( String . t ( ) ) | no_return ( )
7- def parse! ( path_or_content ) do
8- content =
9- if File . exists? ( path_or_content ) do
10- File . read! ( path_or_content )
11- else
12- path_or_content
13- end
6+ @ spec parse_file! ( Path . t ( ) ) :: list ( String . t ( ) ) | no_return ( )
7+ def parse_file! ( path ) do
8+ path
9+ |> File . read! ( )
10+ |> do_parse ( )
11+ end
12+
13+ @ spec parse_content! ( String . t ( ) ) :: list ( String . t ( ) ) | no_return ( )
14+ def parse_content! ( content ) , do: do_parse ( content )
1415
16+ @ spec do_parse ( String . t ( ) ) :: list ( String . t ( ) )
17+ defp do_parse ( content ) do
1518 { parsed_lines , _ } =
1619 content
1720 |> String . split ( "\n " )
Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ defmodule ExDockerBuild.DockerfileParserTest do
1010
1111 def parse ( base_dir , file ) do
1212 Path . join ( [ base_dir , file ] )
13- |> Parser . parse !( )
13+ |> Parser . parse_file !( )
1414 end
1515
1616 test "parses correctly a simple Dockerfile" , % { base_dir: base_dir } do
@@ -67,7 +67,7 @@ defmodule ExDockerBuild.DockerfileParserTest do
6767 CMD ["cat", "/data/myfile.txt"]
6868 """
6969
70- result = Parser . parse !( content )
70+ result = Parser . parse_content !( content )
7171
7272 assert result == [
7373 { "FROM" , "elixir:1.7.3" } ,
You can’t perform that action at this time.
0 commit comments