Skip to content
This repository has been archived by the owner on Dec 11, 2021. It is now read-only.

Latest commit

 

History

History
69 lines (49 loc) · 1.41 KB

gems.md

File metadata and controls

69 lines (49 loc) · 1.41 KB

Gems

Rubygems

  • Sign in: gem signin
  • Sign out: gem signout

Snippets

  • [[Gemspec]]
  • [[Gem Actions]]

Must Haves for [[Rails]] Devs

Performance

Notes

Loading

If you have a gem with a lib/ folder structured like:

├── lib
│   ├── foobar
│   │   ├── version.rb
│   │   ├── foo.rb
│   │   ├── bar
│   │   │   └── baz.rb

Then you can make this change in your gemspec:

# foobar.gemspec
lib = File.expand_path("../lib", __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require "foobar/version"

Gem::Specification.new do |spec|
  # ...
-  spec.require_paths = ["lib"]
+  spec.require_paths = ["lib", "lib/foobar"]
  # ...
end

Setting your require paths from lib to lib and lib/foobar allows you to leave off foobar/ when requiring files.

# lib/foobar.rb

- require "foobar/version"
- require "foobar/foo"
- require "foobar/bar/baz"
+ require "version"
+ require "foo"
+ require "bar/baz"

Get version number from external file:

VERSION = File.open("version.toml", File::RDONLY).read.strip