I'm new to ruby gems and I'm wondering.. if I was using an API from Ruby gems to write a script and I then exported the script to a server for it to run there, would I have to install the gem on the server? Is there know way for me to bundle it up into 1 file I 开发者_StackOverflow社区just run? (like a Java jar)
Simply include your gem in your gem file, then when you deploy and run bundle install
on the server it will get all your dependencies including your gem
bundle package
will package all your gems into your rails app.
Bundler install your gem for you , but it dosn't include the gem in your script. if you dont have many dependencies you could try to simple unpack the gem in to a folder , you have to require the gem following your relative path , the main problem is if some of your gem have to compile native code (like hpricot) . use
gem unpack GEMNAME
into your script folder and then locate the main file to require in your code (usualy in a lib direcotory into the unpacked gem) . this work easly only for simple gems without chain dependencies.
I usually just create a vendor directory in my application and extract your gems there. gem unpack gem_name
will do it for you or you can use Rails' rake gem:unpack GEM=gem_name
.
Bundler is another great solution but if you just want a quick and dirty solution then just unpack the gem into your application and be done with it.
精彩评论