-
Notifications
You must be signed in to change notification settings - Fork 13
Gem Extraction Cheat Sheet
fiedl edited this page Jul 22, 2012
·
12 revisions
bundle gem gem_name
- edit
gem_name.gemspec
# ...
gem.add_dependency "rails", ">= 3.2"
gem.add_dependency "jquery-rails"
gem.add_development_dependency 'sass-rails'
gem.add_development_dependency 'coffee-rails'
gem.add_development_dependency "rake"
gem.add_development_dependency "bundler"
gem.add_development_dependency "rspec-rails", ">= 2.8.0"
gem.add_development_dependency "guard", "1.0.1"
gem.add_development_dependency "nokogiri", ">= 1.5.0"
gem.add_development_dependency "capybara"
gem.add_development_dependency 'rspec-rails', '2.10.0'
gem.add_development_dependency 'guard-rspec', '0.5.5'
gem.add_development_dependency 'execjs'
gem.add_development_dependency 'therubyracer'
bundle install
- edit
Rakefile
:
require 'bundler/gem_tasks'
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new( :spec )
task default: :spec
- edit
lib/gem_name/version.rb
(add.alpha
) - create
spec/spec_helper.rb
require 'gem_name'
- edit
README.md
- Copy the specs into the gem
- Copy the code into the gem
- ActiveRecord integration: see:
-
module GemName::ModelAdditions
# lib/gem_name/model_additions.rb module GemName module ModelAdditions def acts_as_something end end end ActiveRecord::Base.extend GemName::ModelAdditions
- require that file in
lib/gem_name.rb
- instead of direct ActiveRecord::Base extension, may use railtie:
# lib/gem_name/railtie.rb
module GemName
class Railtie < Rails::Railtie
initializer 'gem_name.model_additions' do
ActiveSupport.on_load :active_record do
extend ModelAdditions
end
end
end
end
- add to
lib/gem_name.rb
:
require "spec_name/railtie" if defined? Rails
- add the test app to a
test_app
folder:
~/rails/gem_name$ rails new test_app
- require the test_app's environment in the specs, e.g. in the
spec/spec_helper.rb
require File.expand_path('../../test_app/config/environment', __FILE__)
- configure javascript engine in
spec/spec_helper.rb
RSpec.configure do |config|
# ...
Capybara.javascript_driver = :webkit
end
- Add
pg
to the Gemfile:
gem 'sqlite3', group: :development
gem 'pg', group: :production
- Upload to heroku
$ cd test_app
$ git init
$ git add .
$ git commit -m "initial commit"
$ heroku create --stack cedar
$ heroku rename gem-name-test-app
$ git push heroku master
$ heroku run rake db:migrate # if database needed
- add it to the
Gemfile
of some test app:
gem 'gem_name', path: 'path/to/gem'
- add files to local repository if not done, yet.
$ cd gem_name
$ git add .
$ git commit -m "initial commit."
- Create repository "gem_name" on http://github.com
- Push it:
$ git remote add origin [email protected]:your_git_user_name/gem_name.git
$ git push -u origin master
- in the
Gemfile
:
gem 'gem_name', git: 'git://github.com/your_git_user_name/gem_name.git'
- Version number in
lib/gem_name/version.rb
- Changelog
- Commit changes: e.g. with message:
release v0.0.1
- Push it to http://rubygems.org:
$ rake release
- now remove
git
option fromGemfile
- bump version number in
lib/gem_name/version.rb
- sign in on http://travis-ci.org
- go to 'Profile' and turn on the switch of the corresponding github repository
- get image-url from the status page of the current build
# .travis.yml
env: "RAILS_ENV=test DISPLAY=:99.0"
before_script:
- "sh -c 'cd test_app && bundle && bundle exec rake db:drop db:migrate'"
- "sh -e /etc/init.d/xvfb start"
- add
rake
as an development dependency - only test in ruby 1.9: Add file
.travis.yml
:
rvm:
- 1.9.3
- just add the github repository on http://rubydoc.info
- link to that from the README
- See, for example, Railscasts #301