/var/log/messages

Feb 9, 2019 - 2 minute read - Comments - programming

プログラミング Elixir (17)

12 章の制御フローはスルーして 13 章確認着手。OrganizingAProject-1 をテキスト確認しつつすすめてみます。

mix でプロジェクト作成

$ mix new issues
* creating README.md
* creating .formatter.exs
* creating .gitignore
* creating mix.exs
* creating config
* creating config/config.exs
* creating lib
* creating lib/issues.ex
* creating test
* creating test/test_helper.exs
* creating test/issues_test.exs

Your Mix project was created successfully.
You can use "mix" to compile it, test it, and more:

    cd issues
    mix test

Run "mix help" for more commands.

ディレクトリ移動して find してみました。

$ find .
.
./.formatter.exs
./.gitignore
./config
./config/config.exs
./lib
./lib/issues.ex
./mix.exs
./README.md
./test
./test/issues_test.exs
./test/test_helper.exs

git init する模様

以下。

$ git init
$ git add .
$ git commit -m 'initialize repository'
[master (root-commit) 947b567] initialize repository
 8 files changed, 134 insertions(+)
 create mode 100644 .formatter.exs
 create mode 100644 .gitignore
 create mode 100644 README.md
 create mode 100644 config/config.exs
 create mode 100644 lib/issues.ex
 create mode 100644 mix.exs
 create mode 100644 test/issues_test.exs
 create mode 100644 test/test_helper.exs

テキストによれば

  • config にはアプリケーション特有の設定を書く、とのこと
  • lib にはソースコードが置かれる、とのこと
  • test には試験が置かれる (スデにプロトタイプが置かれている)

コマンドライン解析

規約で色々決まっているみたい。コマンドラインから始めるとのことでポイント? が列挙されています。

  • コマンドラインオプションの取り扱いはプログラムのメイン部分に結びつけることは避けたい
  • 橋渡しする独立したモジュールを書く
  • このモジュールは Project.CLI (今回は Issues.CLI) でエントリポイントは run という手続きとのこと
  • lib の中にプロジェクトと同じ名前のディレクトリを掘る
  • このディレクトリの中にアプリケーションの主なソースコードが一つのモジュールごとに一つのファイルとして置かれる

ということで lib/issues ディレクトリを掘って、その中に cli.ex を投入するのか。

defmodule Issues.CLI do
end

中身も書きます。

試験も書いた

こうして

    { _, [ user, project, count ], _ }
      -> { user, project, String.to_integer(count) }

試験もパス。ここまでが練習問題 1 ですね。commit 作成しておきます。

はじめての UI デザイン Metaprogramming Elixir (1)

comments powered by Disqus