Syntax for gem list file when hosting own rubygems repository

R

Richard Kilmer

Well...documentation...no, but its a good idea to document. Here is what
you need to do in a nutshell (what kind of nut...):

You need webserver/virtual host where you can have two files in the root:

www.whatever.com/yaml
www.whatever.com/yaml.Z

Then you place the gem files in a subdirectory:

www.whatever.com/gems/whatever.gem

If you have a set of gem files that you want to host and you want to build
the yaml and yaml.Z file use the following code:

require 'optparse'
require 'rubygems'
require 'zlib'

Gem.manage_gems

class Indexer

def initialize(directory)
@directory = directory
end

def gem_file_list
Dir.glob(File.join(@directory, "*.gem"))
end

def build_index
File.open(File.join(@directory, "yaml"), "w") do |file|
file.puts "--- !ruby/object:Gem::Cache"
file.puts "gems:"
gem_file_list.each do |gemfile|
spec = Gem::Format.from_file_by_path(gemfile).spec
file.puts " #{spec.full_name}: #{spec.to_yaml.gsub(/\n/, "\n
")[4..-1]}"
end
end
build_compressed_index
end

def build_compressed_index
File.open(File.join(@directory, "yaml.Z"), "w") do |file|
file.write(Zlib::Deflate.deflate(File.read(File.join(@directory,
"yaml"))))
end
end
end

##
#
# Build index
#
#

Indexer.new(".").build_index

_______

If that code is to hard to extract from the email, let me know and I will
post it. Note that the directory that you pass in to the indexer is
location of the gem files. You need to chmod the yaml and yaml.Z files so
they are readable from a web client, yada yada yada.

To use it you then do:

gem install whatever.gem --source http://www.whatever.com

Hope that helps,

Rich
 
J

James Britt

Richard said:
Well...documentation...no, but its a good idea to document. Here is what
you need to do in a nutshell (what kind of nut...):


Ah, very nice.


...
If that code is to hard to extract from the email, let me know and I will
post it. Note that the directory that you pass in to the indexer is
location of the gem files. You need to chmod the yaml and yaml.Z files so
they are readable from a web client, yada yada yada.

Perhaps this could be added to the RubyGems bookshelf?

Thanks,


James
 
C

Chad Fowler

Well...documentation...no, but its a good idea to document. Here is what
you need to do in a nutshell (what kind of nut...):

You need webserver/virtual host where you can have two files in the root:

www.whatever.com/yaml
www.whatever.com/yaml.Z

Then you place the gem files in a subdirectory:

www.whatever.com/gems/whatever.gem

If you have a set of gem files that you want to host and you want to build
the yaml and yaml.Z file use the following code:

require 'optparse'
require 'rubygems'
require 'zlib'

Gem.manage_gems

class Indexer

def initialize(directory)
@directory = directory
end

def gem_file_list
Dir.glob(File.join(@directory, "*.gem"))
end

def build_index
File.open(File.join(@directory, "yaml"), "w") do |file|
file.puts "--- !ruby/object:Gem::Cache"
file.puts "gems:"
gem_file_list.each do |gemfile|
spec = Gem::Format.from_file_by_path(gemfile).spec
file.puts " #{spec.full_name}: #{spec.to_yaml.gsub(/\n/, "\n
")[4..-1]}"
end
end
build_compressed_index
end

def build_compressed_index
File.open(File.join(@directory, "yaml.Z"), "w") do |file|
file.write(Zlib::Deflate.deflate(File.read(File.join(@directory,
"yaml"))))
end
end
end

##
#
# Build index
#
#

Indexer.new(".").build_index

_______

If that code is to hard to extract from the email, let me know and I will
post it. Note that the directory that you pass in to the indexer is
location of the gem files. You need to chmod the yaml and yaml.Z files so
they are readable from a web client, yada yada yada.

To use it you then do:

gem install whatever.gem --source http://www.whatever.com

Hope that helps,

Rich

Are there online docs for creating the YAML file needed when
self-hosting gems?

Thanks,

James

At risk of stating the obvious, If you don't mind running webrick, you
can also just start up gem_server.

--

Chad Fowler
http://chadfowler.com
http://rubycentral.org
http://rubygarden.org
http://rubygems.rubyforge.org (over 100,000 gems served!)
 
J

James Britt

Jim said:
Richard said:
Well...documentation...no, but its a good idea to document. Here is what
you need to do in a nutshell (what kind of nut...):
[...]

Perhaps this could be added to the RubyGems bookshelf?


Done: http://docs.rubygems.org/read/chapter/18#page81

Fast.

Here's another request or suggestion or something: Can that bit of code
be bundled up as a command-line script that ships with RubyGems, so that
one could run it on some specific directory and generate the gem distro
files?

For example, if I have a beta gem I want to offer up on my own gem
server site, I might run

% gem_host /usr/local/dev/james/stuff/beta

and create the proper gem server files for all gems in the given directory.

Basically, this is what I have right now, thanks to the provided code,
and it seems like it would make a handy addition to the base rubygems
feature set.

James
 
J

Jim Weirich

Fast.

Here's another request or suggestion or something: Can that bit of code
be bundled up as a command-line script that ships with RubyGems, so that
one could run it on some specific directory and generate the gem distro
files?

Done: See generate_yaml_index.rb in your existing RubyGems distribution.

(This actually has been distributed with RubyGems for the past year ... Rich
probably forgot he commited the code in the CVS repository).
 
J

James Britt

Jim said:
Done: See generate_yaml_index.rb in your existing RubyGems distribution.


Wow.

You know, I hear people say, "Good, fast, inexpensive: pick two."

But that restraint doesn't seem to be an issue here.


Thanks,


James
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top