我的根目录中有一个.exs脚本,我希望能够在命令行上执行elixir my_script.exs.在我的项目中初始化Mix之前,我的脚本正在运行,但现在它不起作用.我可以看到Mix将.beam文件放在ebin/目录中,但显然我的脚本没有在那里查找.
将自定义模块加载到.exs脚本的正确方法是什么?
我缺少Phoenix特定的混音任务,例如mix phoenix.gen.html
$ mix help | grep -i phoenix
mix local.phoenix#更新凤凰本地
mix phoenix.new#创建一个新的Phoenix v1.2.1应用程序
$ mix -v
Erlang/OTP 19 [erts-8.1] [source] [64-bit] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]
混合1.3.4
$ elixir -v
Erlang/OTP 19 [erts-8.1] [source] [64-bit] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]
Elixir 1.3.4
我在我的Mac上重新安装了Erlang,Node,Elixir,Phoenix(使用brew),似乎没有解决问题.
以下是从Phoenix app目录运行它的输出
$ mix phoenix.new hello
$ cd hello
$ ls
README.md brunch-config.js deps mix.exs node_modules priv web _build config lib mix.lock package.json test
$ mix -h | fgrep phoenix
mix local.phoenix # Updates Phoenix locally …Run Code Online (Sandbox Code Playgroud) 目前,我正在寻找在运行mix任务时添加 SQL 语句日志记录的方法。例如,这样的命令mix ecto.rollback和mix ecto.migrate输出信息:
...
13:45:53.016 [info] == Running Repo.Migrations.AddAmountToUserResources.change/0 backward
13:45:53.016 [info] alter table user_resources
...
Run Code Online (Sandbox Code Playgroud)
然而,alter table user_resources我希望看到ecto命中 DB生成的确切 SQL 语句,而不是神秘的。有没有办法做到这一点?
我已经检查了几个看起来相关的 SO 答案(例如Disable Elixir Ecto Debug output)。不幸的是,在我上面的情况下,他们没有帮助我。提前致谢。
在Elixir上工作时我遇到了一些问题.这是我的mix.exs......
defmodule FlockTest.Mixfile do
use Mix.Project
def project do
[app: :flock_test,
version: "0.1.0",
elixir: "~> 1.4",
build_embedded: Mix.env == :prod,
start_permanent: Mix.env == :prod,
deps: deps()]
end
# Configuration for the OTP application
#
# Type "mix help compile.app" for more information
def application do
# Specify extra applications you'll use from Erlang/Elixir
[
extra_applications: [:logger],
mod: {FlockTest, []}
]
end
...
...
Run Code Online (Sandbox Code Playgroud)
这是代码FlockTest.
defmodule FlockTest do
@moduledoc """
Documentation for FlockTest.
"""
def start(_type, _args) …Run Code Online (Sandbox Code Playgroud) 无法弄清楚这个错误。
我有这个文件:
test/support/conn_case.ex
defmodule ProjectWeb.ConnCase do
@moduledoc """
This module defines the test case to be used by
tests that require setting up a connection.
Such tests rely on `Phoenix.ConnTest` and also
import other functionality to make it easier
to build common datastructures and query the data layer.
Finally, if the test case interacts with the database,
it cannot be async. For this reason, every test runs
inside a transaction which is reset at the beginning
of the test unless …Run Code Online (Sandbox Code Playgroud) 我目前正在学习 Elixir,并且正在阅读《使用 Elixir、OTP 和 Phoenix 进行功能性 Web 开发》,在我看来这是一本很棒的书。在状态机章节中,我想出了以下代码:
defmodule IslandsEngine.Rules do
alias __MODULE__
defstruct state: :initialized
def new(), do: %Rules{}
def check(%Rules{state: :initialized} = rules, :add_player), do:
{:ok, %Rules{rules | state: :players_set}}
def check(_state, _action), do: :error
end
Run Code Online (Sandbox Code Playgroud)
上面的代码应该作为一个功能齐全的状态机工作。我将在上面粘贴一些iex命令:
iex(1)> alias IslandsEngine.Rules
IslandsEngine.Rules
iex(2)> rules = Rules.new()
%IslandsEngine.Rules{state: :initialized}
iex(3)> {:ok, rules} = Rules.check(rules, :add_player)
{:ok, %IslandsEngine.Rules{state: :players_set}}
iex(4)> rules.state
:players_set
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,状态结构已从 更改:initialized为:add_player。伟大的。
我的问题是:state:struct 真的是不可变的吗?我的意思是,该方法check/1返回带有语句的结构副本state: :players_set,该语句遵循正确的功能模式......但是它如何“覆盖”当前状态而不直接修改它? …
我有一个启动应用程序的依赖项,但我只想使用其模块并且不希望其主管运行。如何将其从启动中排除?
Mix.Project我在 app.start、run 或模块中没有找到与此相关的任何内容
我有一个使用混合的Elixir项目.我已经使用了一些内置的erlang模块,但现在我需要使用我在Github上找到的第三方模块.
如何从Elixir导入,构建和调用第三方Erlang模块?
编辑:我现在感兴趣的模块位于https://github.com/aggelgian/erlang-algorithms,特别是edmonds_karp模块.
是否有相当于npm install --save快速添加hex模块到mix.exs?
我知道粘贴十六进制模块引用的mix.exs deps功能如下:
defp deps do
[
{:asn, "~> 0.2.1"},
{:mix_docker, "~> 0.3.0"}
]
end
Run Code Online (Sandbox Code Playgroud)
不应该是一个大问题,但我已经习惯了惯例
npm install --save xyz
Run Code Online (Sandbox Code Playgroud)
并将模块下载并安装在packages.json配置文件中.非常便利.
如何为混合项目生成文档?怎么做呢?
使用Elixir混合项目的过程:
mix new greeter命令生成一个项目。 greeter.ex文件中添加了一块注释。 mix.exs文件中。 mix docs
命令生成文档。mix help 无法docs在可能的选项列表中提供任务:
mix # Runs the default task (current: "mix run")
mix app.start # Starts all registered apps
mix app.tree # Prints the application tree
mix archive # Lists installed archives
mix archive.build # Archives this project into a .ez file
mix archive.install # Installs an archive locally
mix archive.uninstall # Uninstalls archives
mix clean # Deletes generated application files …Run Code Online (Sandbox Code Playgroud) elixir-mix ×10
elixir ×9
erlang ×2
ecto ×1
elixir-iex ×1
generator ×1
module ×1
shell ×1
struct ×1
testing ×1