Syntax for gem list file when hosting own rubygems repository

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

Thanks,

James

···

--

http://www.ruby-doc.org
http://www.rubyxml.com
http://catapult.rubyforge.com
http://orbjson.rubyforge.com
http://ooo4r.rubyforge.com
http://www.jamesbritt.com

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

On 3/24/05 8:56 AM, "James Britt" <james_b@neurogami.com> wrote:

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

Thanks,

James

thanks for the info,

George.

···

--
Nitro + Og: http://nitro.rubyforge.org

Richard Kilmer wrote:

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

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

···

On Thu, 24 Mar 2005 23:39:30 +0900, Richard Kilmer <rich@infoether.com> wrote:

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

On 3/24/05 8:56 AM, "James Britt" <james_b@neurogami.com> wrote:

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

--

Chad Fowler
http://chadfowler.com

http://rubygems.rubyforge.org (over 100,000 gems served!)

Chad Fowler wrote:

...

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

Um, obvious?

Surely a relative thing :slight_smile:

Quite a nice feature, though.

James

···

--

http://www.rubyxml.com
http://catapult.rubyforge.com
http://orbjson.rubyforge.com
http://ooo4r.rubyforge.com
http://www.jamesbritt.com

Richard Kilmer wrote:
> 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

···

On Thursday 24 March 2005 10:59 am, James Britt wrote:

--
-- Jim Weirich jim@weirichhouse.org http://onestepback.org
-----------------------------------------------------------------
"Beware of bugs in the above code; I have only proved it correct,
not tried it." -- Donald Knuth (in a memo to Peter van Emde Boas)

Jim Weirich wrote:

Richard Kilmer wrote:

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

···

On Thursday 24 March 2005 10:59 am, James Britt wrote:

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).

···

On Friday 25 March 2005 11:52 am, James Britt wrote:

>>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?

--
-- Jim Weirich jim@weirichhouse.org http://onestepback.org
-----------------------------------------------------------------
"Beware of bugs in the above code; I have only proved it correct,
not tried it." -- Donald Knuth (in a memo to Peter van Emde Boas)

Jim Weirich wrote:

···

On Friday 25 March 2005 11:52 am, James Britt wrote:

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?

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