-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove GenServer dependency & update pattern file (#10)
* Latest patterns.yml and remove GenServer dep * Clean-up adqio changes
- Loading branch information
Showing
10 changed files
with
80 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,21 @@ | ||
defmodule UAParser.Storage do | ||
@moduledoc """ | ||
Storage of User-Agent regular expressions. | ||
Load pattern data at compile time. Recompiling the application is necessary after updating the pattern file. | ||
""" | ||
|
||
use GenServer | ||
|
||
alias __MODULE__, as: Storage | ||
alias UAParser.Processor | ||
|
||
@doc """ | ||
Start our GenServer. | ||
""" | ||
def start_link(opts \\ []) do | ||
GenServer.start_link(Storage, opts, name: Storage) | ||
end | ||
|
||
@doc """ | ||
Initialize storage | ||
""" | ||
def init(opts), do: load_patterns(opts) | ||
|
||
@doc """ | ||
Look for a matching User-Agent | ||
""" | ||
def handle_call(:list, _from, opts), | ||
do: {:reply, opts[:data], opts} | ||
|
||
@doc """ | ||
""" | ||
def list, do: GenServer.call(Storage, :list) | ||
Application.start(:yamerl) | ||
|
||
defp load_patterns(opts) do | ||
data = | ||
:ua_parser | ||
|> Application.get_env(:patterns) | ||
|> :yamerl_constr.file | ||
|> Processor.process | ||
data = | ||
:ua_parser | ||
|> :code.priv_dir | ||
|> Kernel.++('/patterns.yml') | ||
|> to_string | ||
|> :yamerl_constr.file([]) | ||
|> Processor.process | ||
|
||
opts = | ||
opts | ||
|> Keyword.put(:data, data) | ||
@data data | ||
|
||
{:ok, opts} | ||
end | ||
def list, do: @data | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters