Syntax for gem list file when hosting own rubygems repository

Discussion in 'Ruby' started by James Britt, Mar 24, 2005.

  1. James Britt

    James Britt Guest

    James Britt, Mar 24, 2005
    #1
    1. Advertising

  2. 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" <> wrote:

    > Are there online docs for creating the YAML file needed when
    > self-hosting gems?
    >
    > Thanks,
    >
    > James
     
    Richard Kilmer, Mar 24, 2005
    #2
    1. Advertising

  3. George Moschovitis, Mar 24, 2005
    #3
  4. James Britt

    James Britt Guest

    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
     
    James Britt, Mar 24, 2005
    #4
  5. James Britt

    Chad Fowler Guest

    On Thu, 24 Mar 2005 23:39:30 +0900, 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...):
    >
    > 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" <> wrote:
    >
    > > 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!)
     
    Chad Fowler, Mar 25, 2005
    #5
  6. James Britt

    James Britt Guest

    James Britt, Mar 25, 2005
    #6
  7. James Britt

    Jim Weirich Guest

    On Thursday 24 March 2005 10:59 am, James Britt 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

    --
    -- Jim Weirich 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, Mar 25, 2005
    #7
  8. James Britt

    James Britt Guest

    Jim Weirich wrote:
    > On Thursday 24 March 2005 10:59 am, James Britt 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
     
    James Britt, Mar 25, 2005
    #8
  9. James Britt

    Jim Weirich Guest

    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.

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

    --
    -- Jim Weirich 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, Mar 25, 2005
    #9
  10. James Britt

    James Britt Guest

    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
     
    James Britt, Mar 25, 2005
    #10
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. han
    Replies:
    1
    Views:
    123
    Lyle Johnson
    Oct 24, 2005
  2. Austin 7873
    Replies:
    5
    Views:
    191
    Eric Hodel
    Jan 27, 2007
  3. kazaam
    Replies:
    1
    Views:
    144
  4. teo1991
    Replies:
    0
    Views:
    606
    teo1991
    Apr 2, 2009
  5. Tom Cloyd
    Replies:
    0
    Views:
    182
    Tom Cloyd
    Sep 3, 2009
Loading...

Share This Page