Posted about 9 years ago. Visible to the public. Linked content.

Creating a gem in lib folder

Go to lib folder and use bundler to generate main files for a gem:

Copy
$ bundle gem test_gem create test_gem/Gemfile create test_gem/Rakefile create test_gem/LICENSE create test_gem/README.md create test_gem/.gitignore create test_gem/test_gem.gemspec create test_gem/lib/test_gem.rb create test_gem/lib/test_gem/version.rb Initializating git repo in /path/to/webapp/HouseTrip-Web-App/lib/test_gem

cd in to created directory

Copy
$ cd test_gem/

Bundler automatically created git repository for us, but we do not need it. Lets remove it:

Copy
$ rm -rf .git/

And we need to remove git dependency from gemspec file, open test_gem.gemspec file and change this line :

Copy
gem.files = `git ls-files`.split($\)

to this :

Copy
gem.files = Dir.glob("{bin,lib}/**/*")

Next step is to configure rake to include gem files properly and to include all rake files from a gem.
Open Rakefile file and overwrite it with this code:

Copy
#!/usr/bin/env rake require "bundler/gem_tasks" $LOAD_PATH << File.join(File.dirname(__FILE__), 'lib') $LOAD_PATH << File.join(File.dirname(__FILE__)) # load custom tasks Dir.glob(["lib/**/*.rake", "tasks/**/*.rake"]).each do |file| Kernel.load file end

And the last step is to add our gem in to project, open Gemfile from main web app and add this line:

Copy
gem 'test_gem', :path => File.join(File.dirname(__FILE__), '/lib/test_gem')

DONE :)

Owner of this card:

Avatar
fragalla
Last edit:
over 8 years ago
Posted by fragalla to HouseTrip Deck
This website uses short-lived cookies to improve usability.
Accept or learn more