Ideal Ruby project structure

前端 未结 4 1166
星月不相逢
星月不相逢 2020-12-04 04:55

I\'m after an overview/clarification of the ideal project structure for a ruby (non-rails/merb/etc) project. I\'m guessing it follows

app/
  bin/                     


        
相关标签:
4条回答
  • 2020-12-04 05:10

    I attempt to mimic the Rails project structure because my team, which usually deals with Rails, will understand the structure better than another configuration. Convention over Configuration - bleeding over from Rails.

    0 讨论(0)
  • 2020-12-04 05:14

    If you use bundler, running this command bundle gem app_name will give you the same directory structure.

    If you want to use rspec instead of unit tests you can then run this command rspec --init (Just make sure you cd app_name first)

    0 讨论(0)
  • 2020-12-04 05:23

    I think that is pretty much spot on. By default, Rubygems will add the lib directory to the loadpath, but you can push any directory you want onto that using the $: variable. i.e.

    $:.push File.expand_path(File.dirname(__FILE__) + '/../surfcompstuff')
    

    That means when you have say, surfer.rb in that dir, you can require "surfer" anywhere and the file will be found.

    Also, as a convention, classes and singletons get a file and modules get a directory. For instance, if you had the LolCatz module and the LolCatz::Moar class that would look like:

    lib/
      appname.rb
      lolcatz/
        moar.rb
    

    That is why there is an lib/appname folder because most libraries are in the appname namespace.

    Additionally, if you try running the command newgem --simple [projectname] that'll quickly generate a scaffold for you with just the bare essentials for a Ruby project (and by extension a Ruby Gem). There are other tools which do this, I know, but newgem is pretty common. I usually get rid of the TODO file and all the script stuff.

    0 讨论(0)
  • 2020-12-04 05:26

    See the following example from http://guides.rubygems.org/what-is-a-gem/

     % tree freewill
        freewill/
        ├── bin/
        │   └── freewill
        ├── lib/
        │   └── freewill.rb
        ├── test/
        │   └── test_freewill.rb
        ├── README
        ├── Rakefile
        └── freewill.gemspec
    
    0 讨论(0)
提交回复
热议问题