27.02.2013 Views

Rails%203%20In%20Action

Rails%203%20In%20Action

Rails%203%20In%20Action

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Integrating with an application<br />

s.files = Dir["lib/**/*"] + ["MIT-LICENSE", "Rakefile", "README.rdoc"]<br />

This line will only include files from the lib directory, as well as the MIT-LICENSE, Rakefile,<br />

and README.rdoc files. But you’ve got much more than that in your application,<br />

such as the app folder for starters! To fix this little problem, you’ll replace that line<br />

with this one:<br />

s.files = `git ls-files`.split("\n")<br />

This will add all the files that have been added to your Git repository to the gem.<br />

When you run rake build again, it will create your gem with all the files.<br />

You’ll also need to set up some authors for your gem, which you can do by putting<br />

this line underneath s.version in the forem.gemspec:<br />

s.authors = ["youremail@example.com"]<br />

The next task you can run is rake install. This can be run without having rake<br />

build first, as it will run the build code first, then install. This will actually install the<br />

gem onto your system so that you can use it. That’s all well and good, but you want to<br />

show off your stuff to the world!<br />

That’s what rake release is for. This command will create a git tag for your current<br />

commit, then call git push to push your changes online. Next, it will call gem<br />

push, which will publish your gem to http://rubygems.org. You may have to set up an<br />

account on RubyGems.org first, though.<br />

Once this is done, your gem is released out into the world as version 0.0.1. To<br />

bump the version, you need only to alter this line in your-name-forem.gemspec:<br />

s.version = "0.0.1"<br />

It’s sensible to increment the last part of this number for minor corrections, such as<br />

typos or bug fixes, the middle part for minor breaking changes and additional feature<br />

releases, and the major version for major breaking changes or to represent the solidifying<br />

of the API.<br />

With your gem now live and out there, you can use it in your application. Exciting<br />

times!<br />

17.9 Integrating with an application<br />

Now you get to the best part of this chapter: linking Ticketee, your Rails application<br />

that you’ve built throughout the earlier chapters of this book, to the engine that you<br />

have just written, forem. This is a pretty easy process.<br />

The first thing you’re going to need is to add forem to your application’s Gemfile<br />

with this line:<br />

gem 'your-name-forem', :require => "forem"<br />

Then you’ll need to run bundle install to install the gem. To install the migrations<br />

for this gem, you’ll need to run this command:<br />

rake forem:install:migrations<br />

513

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!