I'm investigating what it might take to add Sorbet RBI files to gems that I maintain, and I'm trying to figure out the proper process for this. I don't want to have Sorbet as a runtime dependency for the gems, though, so that means having all the type information in a separate RBI file.
My current queries around this are:
Do I add my own rbi file at, say, ./sorbet/rbi/gemname.rbi? And is that where Sorbet will look by default if I package that into the published gem file?
Should I include the other auto-generated RBI files (in ./sorbet/rbi/sorbet-typed and ./sorbet/rbi/hidden-definitions) in the published gem file?
Should I include the typed pragma comment in my gem's files, even though the type information is separated into an RBI file? If so, should it reflect the type information that's present in the file the comment is in, or should it reflect the type information available via the RBI file?
My understanding (I'm in a similar boat) based reading through the custom RBI content is that they recommend writing the definitions in a rbi directory in the gem root directory. I don't think they should go in the the sorbet directory since that file gets quite large (and you don't want to have gem users having to download MBs of repeated definitions).
I've been putting the typed sigils in the library files that I have definitions for and having the RBI files separate. The srb tc picks up the definitions (and complains as appropriate). This means that I don't need to add sorbet as a gem dependency (other than for development).
Related
I'm using rdoc to generate API documentation for my Ruby program, but it's pulling in lots of files I don't care to include in the documentation. I see that there is an option to exclude files by pattern, but it would really be better for me to simply provide an explicit list of files and directories to include.
Is there an option to do this, or am I out of luck?
Let's say, I want to add a code-autogenerator for my gem/library. A code generator won't be a single executive cli file, but it'll contain source code as well as a cli file, and I'll be working on it too along with the main gem. Besides, it'll be written in a different language. I could move it into a different repository, but for now I've chosen to use a single repository. According to the convention, in what sub-directory in the main repository should I create that sub-project? opt, var, extra, tools....?
There is more likely no convention for a such situation and I think you already know the actually good solution: use a separate repository.
If this solution is not acceptable for now, a good option would be to put it in the folder with a name explaining its purpose. E.g. if it's a code generator, it could be inside "code_generator" or "tools/code_generator".
I have just started using cucumber and am seeking clarification whether the folder having my step definitions must be named exactly as step_defnitions or can it be anything (e.g. my_defs). I tried renaming in my local machine but sometimes it works and sometimes doesn't.
features/
|
|-- step_definitions/
Cucumber will automatically load any files within the features folder. This means that your step definition files can be located in any folder name/structure as long as they are in the features folder.
Note that it is possible to override this setting and explicitly state the location of your steps by doing:
cucumber -r your/steps/folder/location
For more details you can see the help - cucumber -h:
-r: Require files before executing the features. If this option is not specified, all *.rb files that are siblings or
below the features will be loaded auto-matically. Automatic loading is
disabled when this option is specified, and all loading becomes
explicit. Files under directories named "support" are always loaded
first. This option can be specified multiple times.
In every reference I've seen (including the RSpec Book), they always have a "step_definitions" folder for definitions. A lot of things in Ruby (and especially Rails) utilize a "convention over configuration" philosophy, and I believe this is one of those things. I think it'd be less hassle for you to just make the "step_definitions" folder inside the "features" folder and know that it should work than to try and figure out how to change the configuration.
As we all know, the common structure of rubygem assumes presence of lib directory. I noticed, that generally in this directory are two items: gem_name.rb and gem_name/ directory. The gem_name/ directory hold main sources of project. It is heart of application. So, the question is about gem_name.rb file. What does it stand for?
The reason it's structured like that is if you had files other than gem_name.rb in the lib/ directory (say another_file_name.rb), you'd be liable to cause problems if there was a gem with the name another_file_name and someone did require another_file_name - it'd load your file, rather than the other gem's file.
If your code is small enough it can all fit into gem_name.rb, then put it there, otherwise put it into gem_name/other_file_name.rb.
Typically that just requires everything from the gem_name/ directory that's needed. It's used to keep all the requires in a central location and separate from the actual code
I have written a module that has some generic, reusable code that I would like to be able to use in other projects. Is there a place I could put this file on computer so that Ruby can find it regardless of where I saved the file that is including it? I am using a Mac.
There's no standard place to put code like this. You could put all your code in a gem and install the gem, or create a directory to put this code in. Once you create the directory, alter the LOAD_PATH global variable to include this directory. You can do this either in each script that uses these, or with the RUBYOPT environment variable. For example, you could put ~/my_ruby_stuff in your path and put your files there. One warning if you do that, make sure the path you add is at the end of the gem path and try to avoid any name conflicts with existing Ruby libraries or gems.
Consider making a "gem" out of your code. The advantages are: separate project, better defined interface, separate source control, can share with other developers in your company, etc