In a Ruby gem, is it possible to have executables written in other languages?
I guess it's simply in the specification of RubyGems:
https://github.com/zzak/rubygems/commit/709c5aae7ffd9958cc2ea89dc2caf6b7e02c56b7
+ # Executables included may only be ruby scripts, not scripts for other
+ # languages or compiled binaries.
+ #
Accessing files packaged into a Ruby Gem
There are basically two ways,
1) You can load resources relative to a Ruby file in your gem using __FILE__
:
def path_to_resources
File.join(File.dirname(File.expand_path(__FILE__)), '../path/to/resources')
end
2) You can add arbitrary paths from your Gem to the $LOAD_PATH
variable and then walk the $LOAD_PATH
to find resources, e.g.,
Gem::Specification.new do |spec|
spec.name = 'the-name-of-your-gem'
spec.version ='0.0.1'
# this is important - it specifies which files to include in the gem.
spec.files = Dir.glob("lib/**/*") + %w{History.txt Manifest.txt} +
Dir.glob("path/to/resources/**/*")
# If you have resources in other directories than 'lib'
spec.require_paths << 'path/to/resources'
# optional, but useful to your users
spec.summary = "A more longwinded description of your gem"
spec.author = 'Your Name'
spec.email = 'you@yourdomain.com'
spec.homepage = 'http://www.yourpage.com'
# you did document with RDoc, right?
spec.has_rdoc = true
# if you have any dependencies on other gems, list them thusly
spec.add_dependency('hpricot')
spec.add_dependency('log4r', '>= 1.0.5')
end
and then,
$LOAD_PATH.each { |dir| ... look for resources relative to dir ... }
Getting started with gems and jeweler
- jeweler was created before RubyGems became what it is, so it still reflects the split. I'm not sure when jeweler was last updated, either. (I think it also still recognizes building gems on Github, which is now disabled.)
- I'm not sure I follow what you're saying. The specification in the Rakefile details what the spec that gets written should look like. The spec that gets written details what should be installed and how, I believe.
- A manifest is a list of all the files that your gem should ship with. Not everyone uses one. See the hoe documentation for some pro-manifest discussion.
- Many Ruby gems are only libraries. If you want yours to also have a program like
jeweler
orrake
orrails
that you can call, you have to write the callable program, put it inbin
in your gem's layout and specify (in your gemspec) that it should be packaged and installed. See the Gem::Specification reference underfiles
andexecutable
. - Not sure. Consult both jeweler's docs and the docs for RubyGems.
- You can give an email address or use a name (a 'handle', like I use Telemachus here), which is all they mean by 'handle'.
For the record, if you are just learning how to write gems, you do not need to upload your first attempts using RubyGems or anything like it. You can simply install the gem on your machine only.
Arbitrary Sprockets asset path in assets only gem for Rails/Sprockets
class Engine < ::Rails::Engine
config.paths['app/assets'] = "source"
end
How to add a (pre/post)_install_hook to ruby gems
The answer is presently (2015-11-11) NO you cannot execute arbitrary code at install time for a specific gem. The hooks mentioned in your question are for use by the RubyGem installer itself and are not gem specific. See: How can I make a Ruby gem package copy files to arbitrary locations? for additional details.
These files:
lib/rubygems/defaults/defaults.rb
lib/rubygems/defaults/operating_system.rb
rubygems/defaults.rb
Are not called from your gem directory. They are found in the RubyGems system location.
If you wish to execute the same code for every gem before any are installed then you can use the pre_install hooks by placing the code in /usr/lib64/ruby/2.2.0/rubygems/defaults.rb
or wherever your version of Ruby is installed on your system. The operating_system.rb
file will get loaded from the same location as well.
How do I add documentation to my gem that will show up on rubygems.org?
Here is the response that I received from someone in the RubyDoc community:
Hi there,
New gems can take up to a day to make it into RubyGems' master gem
list. Not much we can do about this one. From then on, it's about an
hour for new versions of your gem to be populated into the list (we
run a cron job at *:15 to update our copy).
It was a matter of letting enough time elapse.
Related Topics
Ruby: Too Many Open Files @ Rb_Sysopen
Differencebetween Unicorn and Unicorn_Rails
What Are the Meanings of the Hash Keys When Calling Objectspace.Count_Objects
Error When Installing Libv8 3.11.8.3
What Are Fast Xml Parsers for Ruby
Capybara Trouble Filling in Js Modal
Why Does 'Puts(Nil or 4)' Fail in Ruby
Ruby on Rails: Converting "Somewordhere" to "Some Word Here"
How to Replace the Characters in a String
Why Is the << Operation on an Array in Ruby Not Atomic
How to Assign a Has_Many/Belongs_To Relation Properly in Rails Activerecord
Ruby Error Reading in Certificate File with Openssl
Svg Files in Raphael, Can They Be Used
How Is Ruby Tcpsocket Timeout Defined
How to Convert 1 to "First", 2 to "Second", and So On, in Ruby