我的 rails ./bin 目录中有什么? [英] What's inside my rails ./bin directory?

查看:42
本文介绍了我的 rails ./bin 目录中有什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Ruby on Rails 4 引入了* ./bin 目录../bin 里面有一些可执行文件:bundlerailsrakesetup, spring.

Ruby on Rails 4 introduced* the ./bin directory. Inside of ./bin are a few executables: bundle, rails, rake, setup, spring.

我的问题是:

  1. 这些可执行文件有什么作用?它们为什么存在?
  2. 什么时候调用它们?
  3. 我可以编辑它们吗?我为什么要编辑它们?

我已经阅读了这些文件的来源,并尝试在 Google 上搜索它们的用途,但我无法理解.我正在寻找深入的解释.

I've read the source of these files, and I've tried to Google their purpose, but I can't wrap my head around it. I'm looking for an in-depth explanation.

*我相信很多这些文件在 Rails 4 之前就已经存在,只是在不同的位置.

推荐答案

在 Rails 4 中引入,./bin 目录包含应用程序的binstubs".Binstubs 是 gem 可执行文件的包装器,如 railsbundle,可确保 gem 可执行文件在正确的 Rails 应用环境中运行.

Introduced in Rails 4, the ./bin directory contains your app's "binstubs." Binstubs are wrappers around gem executables, like rails or bundle, which ensures a gem executable is run inside the correct environment for your Rails app.

Binstubs 可以用来代替 bundle exec 在你的应用环境中运行 gem 的可执行文件.例如,您可以输入 bin/rails scaffold products,而不是输入 bundle exec rails scaffold products.使用 binstubs 比 bundle exec 更灵活,因为您不必cd 到应用程序的根目录并在一切之前键入 bundle exec.

Binstubs can be used in lieu of bundle exec to run a gem's executable inside your app's environment. For example, instead of typing bundle exec rails scaffold products you can type bin/rails scaffold products. Using binstubs is more flexible than bundle exec, because you don't have to cd to the app's root directory and type bundle exec before everything.

默认情况下,bundlerailsrakesetupspringbinstubs 是为新的 rails 项目自动创建的.要为 gem 可执行文件创建 binstub,只需键入 bundle binstubs name_of_gem_executable.您将在 ./bin 目录中找到新的 binstub.

By default, bundle, rails, rake, setup, spring binstubs are created automatically for new rails projects. To make a binstub for a gem executable, just type bundle binstubs name_of_gem_executable. You'll find the new binstub in your ./bin directory.

有些人建议将 ./bin 放在 shell 的搜索 $PATH 中,这样您就不必键入 bin/rails 和你可以输入rails.这是有风险的,因为它依赖于 ./bin 出现在 $PATH 中 gem 可执行文件的路径之前;如果您碰巧忘记了这个顺序并调整了 $PATH 以便在 binstub 包装器之前找到 gem 的可执行文件,您可以轻松调用 gem 的可执行文件——没有环境借口——而不会意识到它.

Some suggest putting ./bin in your shell's search $PATH, so that you don't have to type bin/rails and you can just type rails. This is risky because it depends on ./bin coming before the gem executable's path in $PATH; if you happen to forget this ordering and adjust $PATH such that the gem's executable is found before the binstub wrapper, you could easily invoke the gem's executable -- sans the environmental pretext -- without realizing it.

这篇关于我的 rails ./bin 目录中有什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆