Skip to content

Commit acfc8a3

Browse files
authored
Misc doc changes (#73)
List of changes: - Mix format module config - Add common sourse url - Set and use latest ex_doc - Set source reference by tagged version - Fix markdown - Revise documentation - Add license section - Mix format module config - Badges and more badges! - Update gitignore
1 parent 94e5a20 commit acfc8a3

File tree

9 files changed

+224
-104
lines changed

9 files changed

+224
-104
lines changed

.gitignore

+27-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,31 @@
1-
/_build
2-
/deps
3-
/doc
4-
/docs
1+
# The directory Mix will write compiled artifacts to.
2+
/_build/
3+
4+
# If you run "mix test --cover", coverage assets end up here.
5+
/cover/
6+
7+
# The directory Mix downloads your dependencies sources to.
8+
/deps/
9+
10+
# Where third-party dependencies like ExDoc output generated docs.
11+
/doc/
12+
13+
# Ignore .fetch files in case you like to edit your project deps locally.
14+
/.fetch
15+
16+
# If the VM crashes, it generates a dump, let's ignore it too.
517
erl_crash.dump
18+
19+
# Also ignore archive artifacts (built via "mix archive.build").
620
*.ez
7-
mix.lock
21+
22+
# Ignore package tarball (built via "mix hex.build").
23+
file_system-*.tar
24+
25+
# Temporary files for e.g. tests
26+
/tmp
27+
28+
# Misc
829
/priv/mac_listener
930
/priv/kqueue
31+
mix.lock

README.md

+43-22
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,29 @@
1-
FileSystem
2-
=========
1+
# FileSystem
32

4-
A file change watcher wrapper based on [fs](https://github.com/synrc/fs)
3+
[![Module Version](https://img.shields.io/hexpm/v/file_system.svg)](https://hex.pm/packages/file_system)
4+
[![Hex Docs](https://img.shields.io/badge/hex-docs-lightgreen.svg)](https://hexdocs.pm/file_system/)
5+
[![Total Download](https://img.shields.io/hexpm/dt/file_system.svg)](https://hex.pm/packages/file_system)
6+
[![License](https://img.shields.io/hexpm/l/file_system.svg)](https://github.com/falood/file_system/blob/master/LICENSE)
7+
[![Last Updated](https://img.shields.io/github/last-commit/falood/file_system.svg)](https://github.com/falood/file_system/commits/master)
8+
9+
An Elixir file change watcher wrapper based on
10+
[FS](https://github.com/synrc/fs), the native file system listener.
511

612
## System Support
713

8-
- Mac fsevent
9-
- Linux, FreeBSD and OpenBSD inotify
10-
- Windows inotify-win
14+
- MacOS - [fsevent](https://github.com/thibaudgg/rb-fsevent)
15+
- GNU/Linux, FreeBSD and OpenBSD - [inotify](https://github.com/rvoicilas/inotify-tools/wiki)
16+
- Windows - [inotify-win](https://github.com/thekid/inotify-win)
1117

12-
NOTE:
18+
On MacOS 10.14, to compile `mac_listener`, run:
1319

14-
On Linux, FreeBSD and OpenBSD you need to install inotify-tools.
15-
On Macos 10.14, you need run `open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg` to compile `mac_listener`.
20+
```console
21+
open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg
22+
```
1623

1724
## Usage
1825

19-
Put `file_system` in the `deps` and `application` part of your mix.exs
26+
Put `:file_system` in the `deps` and `application` part of your `mix.exs`:
2027

2128
``` elixir
2229
defmodule Excellent.Mixfile do
@@ -35,7 +42,6 @@ defmodule Excellent.Mixfile do
3542
end
3643
```
3744

38-
3945
### Subscription API
4046

4147
You can spawn a worker and subscribe to events from it:
@@ -52,17 +58,18 @@ or
5258
FileSystem.subscribe(:my_monitor_name)
5359
```
5460

55-
The pid you subscribed from will now receive messages like
61+
The `pid` you subscribed from will now receive messages like:
5662

5763
```
5864
{:file_event, worker_pid, {file_path, events}}
5965
```
6066
and
67+
6168
```
6269
{:file_event, worker_pid, :stop}
6370
```
6471

65-
### Example with GenServer
72+
### Example Using GenServer
6673

6774
```elixir
6875
defmodule Watcher do
@@ -78,27 +85,41 @@ defmodule Watcher do
7885
{:ok, %{watcher_pid: watcher_pid}}
7986
end
8087

81-
def handle_info({:file_event, watcher_pid, {path, events}}, %{watcher_pid: watcher_pid}=state) do
82-
# YOUR OWN LOGIC FOR PATH AND EVENTS
88+
def handle_info({:file_event, watcher_pid, {path, events}}, %{watcher_pid: watcher_pid} = state) do
89+
# Your own logic for path and events
8390
{:noreply, state}
8491
end
8592

86-
def handle_info({:file_event, watcher_pid, :stop}, %{watcher_pid: watcher_pid}=state) do
87-
# YOUR OWN LOGIC WHEN MONITOR STOP
93+
def handle_info({:file_event, watcher_pid, :stop}, %{watcher_pid: watcher_pid} = state) do
94+
# Your own logic when monitor stop
8895
{:noreply, state}
8996
end
9097
end
9198
```
9299

100+
## Backend Options
93101

94-
## Tweaking behaviour via extra arguments
95-
96-
For each platform, you can pass extra arguments to the underlying listener process.
102+
For each platform, you can pass extra options to the underlying listener
103+
process.
97104

98-
Each backend support different extra arguments, check backend module documentation for more information.
105+
Each backend supports different extra options, check backend module
106+
documentation for more details.
99107

100-
Here is an example to get instant notifications on file changes for Mac OS X:
108+
Here is an example to get instant notifications on file changes for MacOS:
101109

102110
```elixir
103111
FileSystem.start_link(dirs: ["/path/to/some/files"], latency: 0, watch_root: true)
104112
```
113+
114+
## License
115+
116+
Copyright (C) 2016 Xiangrong Hao
117+
118+
Everyone is permitted to copy and distribute verbatim or modified
119+
copies of this license document, and changing it is allowed as long
120+
as the name is changed.
121+
122+
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
123+
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
124+
125+
0. You just DO WHAT THE FUCK YOU WANT TO.

lib/file_system.ex

+26-16
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,59 @@
11
defmodule FileSystem do
2-
@moduledoc File.read!("README.md")
2+
@moduledoc """
3+
A `GenServer` process to watch file system changes.
4+
5+
The process receives data from Port, parse event, and send it to the worker
6+
process.
7+
"""
38

49
@doc """
10+
Starts a `GenServer` process and linked to the current process.
11+
512
## Options
613
7-
* `:dirs` ([string], required), the dir list to monitor
14+
* `:dirs` ([string], required), the list of directory to monitor.
815
9-
* `:backend` (atom, optional), default backends: `:fs_mac`
10-
for `macos`, `:fs_inotify` for `linux`, `freebsd` and `openbsd`,
11-
`:fs_windows` for `windows`
16+
* `:backend` (atom, optional), default backends: `:fs_mac`. Available
17+
backends: `:fs_mac`, `:fs_inotify`, and `:fs_windows`.
1218
13-
* `:name` (atom, optional), `name` can be used to subscribe as
14-
the same as pid when the `name` is given. The `name` should
15-
be the name of worker process.
19+
* `:name` (atom, optional), the `name` of the worker process to subscribe
20+
to the file system listerner. Alternative to using `pid` of the worker
21+
process.
1622
17-
* All rest options will treated as backend options. See backend
18-
module documents for more details.
23+
* Additional backend implementation options. See backend module documents
24+
for more details.
1925
20-
## Example
26+
## Examples
2127
22-
Simple usage:
28+
Start monitoring `/tmp/fs` directory using the default `:fs_mac` backend of
29+
the current process:
2330
2431
iex> {:ok, pid} = FileSystem.start_link(dirs: ["/tmp/fs"])
2532
iex> FileSystem.subscribe(pid)
2633
27-
Get instant notifications on file changes for Mac OS X:
34+
Get instant (`latench: 0`) notifications on file changes:
2835
2936
iex> FileSystem.start_link(dirs: ["/path/to/some/files"], latency: 0)
3037
31-
Named monitor with specified backend:
38+
Minitor a directory by a process name:
3239
3340
iex> FileSystem.start_link(backend: :fs_mac, dirs: ["/tmp/fs"], name: :worker)
3441
iex> FileSystem.subscribe(:worker)
42+
3543
"""
3644
@spec start_link(Keyword.t) :: GenServer.on_start()
3745
def start_link(options) do
3846
FileSystem.Worker.start_link(options)
3947
end
4048

4149
@doc """
42-
Register the current process as a subscriber of a file_system worker.
43-
The pid you subscribed from will now receive messages like
50+
Register the current process as a subscriber of a `file_system` worker.
51+
52+
The `pid` you subscribed from will now receive messages like:
4453
4554
{:file_event, worker_pid, {file_path, events}}
4655
{:file_event, worker_pid, :stop}
56+
4757
"""
4858
@spec subscribe(GenServer.server) :: :ok
4959
def subscribe(pid) do

lib/file_system/backend.ex

+8-4
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,21 @@ require Logger
22

33
defmodule FileSystem.Backend do
44
@moduledoc """
5-
FileSystem Backend Behaviour.
5+
A behaviour module for implementing different file system backend.
66
"""
77

88
@callback bootstrap() :: :ok | {:error, atom()}
99
@callback supported_systems() :: [{atom(), atom()}]
1010
@callback known_events() :: [atom()]
1111

1212
@doc """
13-
Get and validate backend module, return `{:ok, backend_module}` when success and
14-
return `{:error, reason}` when fail.
15-
When `nil` is given, will return default backend by os.
13+
Get and validate backend module.
14+
15+
Returns `{:ok, backend_module}` upon success and `{:error, reason}` upon
16+
failure.
17+
18+
When `nil` is given, will return default backend by OS.
19+
1620
When a custom module is given, make sure `start_link/1`, `bootstrap/0` and
1721
`supported_system/0` are defnied.
1822
"""

lib/file_system/backends/fs_inotify.ex

+20-9
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,35 @@ require Logger
22

33
defmodule FileSystem.Backends.FSInotify do
44
@moduledoc """
5+
File system backend for GNU/Linux, FreeBSD, and OpenBSD.
6+
57
This file is a fork from https://github.com/synrc/fs.
6-
FileSystem backend for linux, freebsd and openbsd, a GenServer receive data from Port, parse event
7-
and send it to the worker process.
8-
Need `inotify-tools` installed to use this backend.
98
109
## Backend Options
1110
12-
* `:recursive` (bool, default: true), monitor directories and their contents recursively
11+
* `:recursive` (bool, default: true), monitor directories and their contents recursively.
1312
1413
## Executable File Path
1514
16-
The default behaivour to find executable file is finding `inotifywait` from `$PATH`, there're two ways to custom it, useful when run `:file_system` with escript.
15+
Useful when running `:file_system` with escript.
16+
17+
The default listener executable file is found through finding `inotifywait` from
18+
`$PATH`.
19+
20+
Two ways to customize the executable file path:
21+
22+
* Module config with `config.exs`:
23+
24+
```elixir
25+
config :file_system, :fs_inotify,
26+
executable_file: "YOUR_EXECUTABLE_FILE_PATH"`
27+
```
1728
18-
* config with `config.exs`
19-
`config :file_system, :fs_inotify, executable_file: "YOUR_EXECUTABLE_FILE_PATH"`
29+
* System environment variable:
2030
21-
* config with `FILESYSTEM_FSINOTIFY_EXECUTABLE_FILE` os environment
22-
FILESYSTEM_FSINOTIFY_EXECUTABLE_FILE=YOUR_EXECUTABLE_FILE_PATH
31+
```
32+
export FILESYSTEM_FSINOTIFY_EXECUTABLE_FILE="YOUR_EXECUTABLE_FILE_PATH"`
33+
```
2334
"""
2435

2536
use GenServer

lib/file_system/backends/fs_mac.ex

+30-13
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,52 @@ require Logger
22

33
defmodule FileSystem.Backends.FSMac do
44
@moduledoc """
5+
File system backend for MacOS.
6+
7+
The built-in executable file will be compile upon first use.
8+
59
This file is a fork from https://github.com/synrc/fs.
6-
FileSysetm backend for macos, a GenServer receive data from Port, parse event
7-
and send it to the worker process.
8-
Will compile executable the buildin executable file when file the first time it is used.
910
1011
## Backend Options
1112
1213
* `:latency` (float, default: 0.5), latency period.
1314
1415
* `:no_defer` (bool, default: false), enable no-defer latency modifier.
15-
Works with latency parameter, Also check apple `FSEvent` api documents
16-
https://developer.apple.com/documentation/coreservices/kfseventstreamcreateflagnodefer
16+
Works with latency parameter.
17+
18+
See `FSEvent` API documents
19+
https://developer.apple.com/documentation/coreservices/kfseventstreamcreateflagnodefer.
1720
1821
* `:watch_root` (bool, default: false), watch for when the root path has changed.
1922
Set the flag `true` to monitor events when watching `/tmp/fs/dir` and run
20-
`mv /tmp/fs /tmp/fx`. Also check apple `FSEvent` api documents
21-
https://developer.apple.com/documentation/coreservices/kfseventstreamcreateflagwatchroot
23+
`mv /tmp/fs /tmp/fx`.
24+
25+
See `FSEvent` API documents
26+
https://developer.apple.com/documentation/coreservices/kfseventstreamcreateflagwatchroot.
2227
23-
* recursive is enabled by default, no option to disable it for now.
28+
* recursive is enabled by default and it can'b be disabled for now.
2429
2530
## Executable File Path
2631
27-
The default executable file is `mac_listener` in `priv` dir of `:file_system` application, there're two ways to custom it, useful when run `:file_system` with escript.
32+
Useful when running `:file_system` with escript.
33+
34+
The default listener executable file is `priv/mac_listener` within the folder of
35+
`:file_system` application.
36+
37+
Two ways to customize the executable file path:
38+
39+
* Module config with `config.exs`:
40+
41+
```elixir
42+
config :file_system, :fs_mac,
43+
executable_file: "YOUR_EXECUTABLE_FILE_PATH"`
44+
```
2845
29-
* config with `config.exs`
30-
`config :file_system, :fs_mac, executable_file: "YOUR_EXECUTABLE_FILE_PATH"`
46+
* System environment variable:
3147
32-
* config with `FILESYSTEM_FSMAC_EXECUTABLE_FILE` os environment
33-
FILESYSTEM_FSMAC_EXECUTABLE_FILE=YOUR_EXECUTABLE_FILE_PATH
48+
```
49+
export FILESYSTEM_FSMAC_EXECUTABLE_FILE="YOUR_EXECUTABLE_FILE_PATH"`
50+
```
3451
"""
3552

3653
use GenServer

lib/file_system/backends/fs_poll.ex

+2-3
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@ require Logger
22

33
defmodule FileSystem.Backends.FSPoll do
44
@moduledoc """
5-
FileSysetm backend for any OS, a GenServer that regularly scans file system to
6-
detect changes and send them to the worker process.
5+
File system backend for any OS.
76
87
## Backend Options
98
109
* `:interval` (integer, default: 1000), polling interval
1110
12-
## Use FSPoll Backend
11+
## Using FSPoll Backend
1312
1413
Unlike other backends, polling backend is never automatically chosen in any
1514
OS environment, despite being usable on all platforms.

0 commit comments

Comments
 (0)