我开始学习的红宝石。我也是一个日常C++开发。C++的项目中我通常会有下列dir结构

/
 -/bin <- built binaries
 -/build <- build time temporary object (eg. .obj, cmake intermediates)
 -/doc <- manuals and/or Doxygen docs
 -/src
 --/module-1
 --/module-2
 -- non module specific sources, like main.cpp
 - IDE project files (.sln), etc.

什么dir布局Ruby(非轨,非merb同时)将你的建议,以保持它的清洁、简单和易于维护的?

有帮助吗?

解决方案

捆包括必要的基础设施产生宝石:

$ bundle gem --coc --mit --test=minitest --exe spider
Creating gem 'spider'...
MIT License enabled in config
Code of conduct enabled in config
      create  spider/Gemfile
      create  spider/lib/spider.rb
      create  spider/lib/spider/version.rb
      create  spider/spider.gemspec
      create  spider/Rakefile
      create  spider/README.md
      create  spider/bin/console
      create  spider/bin/setup
      create  spider/.gitignore
      create  spider/.travis.yml
      create  spider/test/test_helper.rb
      create  spider/test/spider_test.rb
      create  spider/LICENSE.txt
      create  spider/CODE_OF_CONDUCT.md
      create  spider/exe/spider
Initializing git repo in /Users/francois/Projects/spider
Gem 'spider' was successfully created. For more information on making a RubyGem visit https://bundler.io/guides/creating_gem.html

然后,在lib/,你创建的模块作为需要:

lib/
  spider/
    base.rb
  crawler/
    base.rb
  spider.rb
    require "spider/base"
    require "crawler/base"

阅读手册页 捆绑的宝石 对于细节上 --coc, --exe--mit 选项。

其他提示

截至2011年,这是常见的使用 珠宝商 而不是newgem因为后者是有效的放弃。

核心的结构的一个标准的红宝石项目基本上是:

  lib/
    foo.rb
    foo/
  share/
    foo/
  test/
    helper.rb
    test_foo.rb
  HISTORY.md (or CHANGELOG.md)
  LICENSE.txt
  README.md
  foo.gemspec

share/ 是罕见的和有时被称为 data/ 代替。它是对于一般目的非的红宝石文件。大多数项目不需要它,但是甚至当他们做很多次一切都只是一直在 lib/, 虽然这可能不是最好的做法。

test/ 目录可以被称为 spec/ 如果BDD是被用来代替使用,尽管你可能还会看到 features/ 如果黄瓜是使用,或 demo/ 如果QED是使用。

这些天 foo.gemspec 可以只是 .gemspec -尤其是如果它不是手动保持。

如果项目具有可执行的命令行,然后添加:

  bin/
    foo
  man/
    foo.1
    foo.1.md or foo.1.ronn

此外,大多数的红宝石项目的有:

  Gemfile
  Rakefile

Gemfile 是为使用捆, Rakefile 是瑞克建立的工具。但还有其他的选择如果你想使用不同的工具。

其他一些不那么常见的文件:

  VERSION
  MANIFEST

VERSION 文件中包含的当前版本的编号。和 MANIFEST (或 Manifest.txt)包含一系列文件包括在该项目的包裹文件(s)(例如宝石包)。

还有什么你可能会看到的,但使用率是零星:

  config/
  doc/ (or docs/)
  script/
  log/
  pkg/
  task/ (or tasks/)
  vendor/
  web/ (or site/)

哪里 config/ 包含各种各样的配置文件; doc/ 包含或产生的文件,例如RDoc,或者有时是手动保持文件; script/ 包含壳脚本用的项目; log/ 包含生成项目的日志,例如测试的复盖范围的报告; pkg/ 举产生的包裹文件,例如: foo-1.0.0.gem; task/ 可以举行各种任务文件这样的 foo.rakefoo.watchr; vendor/ 含有副本的其他项目,例如git子模块;并最终 web/ 包含的项目的网站的文件。

然后一些工具的具体文件,这些文件也比较常见:

  .document
  .gitignore
  .yardopts
  .travis.yml

他们相当自明的。

最后,我将增加就我个人加一个 .index 文件和一个 var/ 目录,以建立的文件(搜索"Rubyworks索引"了解更多关于这一)和经常有一个 work 目录,这样的:

  work/
    NOTES.md
    consider/
    reference/
    sandbox/

只是一个废品场发展的目的。

@Dentharg:你的"包括一个包括所有子部分",是一种常见的模式。像什么,它都有其优点(容易得到你想要的东西)和它的缺点(许多可以包括污染的名字空间,你有没有控制他们)。你的图案看起来是这样的:

- src/
    some_ruby_file.rb:
      require 'spider'
      Spider.do_something

+ doc/

- lib/
  - spider/
      spider.rb:
        $: << File.expand_path(File.dirname(__FILE__))
        module Spider
          # anything that needs to be done before including submodules
        end

        require 'spider/some_helper'
        require 'spider/some/other_helper'
        ...

我可以推荐这种允许一个小小的更多控制:

- src/
    some_ruby_file.rb:
      require 'spider'
      Spider.include_all
      Spider.do_something

+ doc/

- lib
  - spider/
      spider.rb:
        $: << File.expand_path(File.dirname(__FILE__))
        module Spider
          def self.include_all
            require 'spider/some_helper'
            require 'spider/some/other_helper'
            ...
          end
        end

为什么不仅使用相同的布局?通常你不会需要建立因为没有编辑的步骤,但是其余部分似乎确定了我。

我不确定你是什么意思通过一个模块,但是如果它只是一个单一的类的一个单独的文件夹不是必要的,而且如果存在多个文件的通常写一个模块-1.rb文件(在名平作为模块-1文件夹),这并没有超过要求的一切都在模块1/.

哦,我建议使用 瑞克 管理任务(而非作出).

我会坚持到类似的东西到你熟悉的:有没有点被一个陌生人在你自己的项目目录。:-)

典型的事情我一直都是lib|src,bin,测试。

(我不喜欢这些怪物发电机:第一件事我想做个新项目是得到一些代码,而不是编写一个README文档,等等!)

所以我去了newgem.我去除所有不必要的RubyForge/gem的东西(锄头,安装,等等), 创建混帐回购协议、进口项目的成演讲视频。所有的花了20分钟,一切都在绿色的。甚至给了我一个基本瑞克的任务,对规格文件。

谢谢你们所有人。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top