Class: GemGrep::Index
- Inherits:
-
Object
- Object
- GemGrep::Index
- Defined in:
- lib/gem_grep.rb
Instance Attribute Summary collapse
-
#server ⇒ Object
Returns the value of attribute server.
Instance Method Summary collapse
- #download_marshal_index ⇒ Object
- #gem_index ⇒ Object
- #gem_server ⇒ Object
-
#initialize(server) ⇒ Index
constructor
A new instance of Index.
- #marshal_compressed_file ⇒ Object
- #marshal_file ⇒ Object
- #marshal_url ⇒ Object
- #setup_marshal_index(name = nil) ⇒ Object
Constructor Details
#initialize(server) ⇒ Index
Returns a new instance of Index.
30 31 32 33 |
# File 'lib/gem_grep.rb', line 30 def initialize(server) @server = server setup_marshal_index unless File.exists?(marshal_file) end |
Instance Attribute Details
#server ⇒ Object
Returns the value of attribute server.
29 30 31 |
# File 'lib/gem_grep.rb', line 29 def server @server end |
Instance Method Details
#download_marshal_index ⇒ Object
53 54 55 56 57 |
# File 'lib/gem_grep.rb', line 53 def download_marshal_index puts "Downloading compressed Marshal gemspec index to ~/.gem_grep. Patience is a bitch..." FileUtils.mkdir_p("~/.gem_grep") system("curl #{marshal_url} > #{marshal_compressed_file}") end |
#gem_index ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/gem_grep.rb', line 39 def gem_index @gem_index ||= begin puts "Loading large gem index. Patience is a bitch ..." spec_hash = Hash[*Marshal.load(File.read(marshal_file)).flatten] Gem::SourceIndex.new(spec_hash).extend(Gem::SuperSearch) end end |
#gem_server ⇒ Object
35 36 37 |
# File 'lib/gem_grep.rb', line 35 def gem_server {:rubygems=>"http://rubygems.org", :github=>"http://gems.github.com"} end |
#marshal_compressed_file ⇒ Object
63 64 65 |
# File 'lib/gem_grep.rb', line 63 def marshal_compressed_file File. "~/.gem_grep/marshal_#{server}.Z" end |
#marshal_file ⇒ Object
59 60 61 |
# File 'lib/gem_grep.rb', line 59 def marshal_file File. "~/.gem_grep/marshal_#{server}" end |
#marshal_url ⇒ Object
67 68 69 |
# File 'lib/gem_grep.rb', line 67 def marshal_url gem_server[server] + "/Marshal.#{Marshal::MAJOR_VERSION}.#{Marshal::MINOR_VERSION}.Z" end |
#setup_marshal_index(name = nil) ⇒ Object
47 48 49 50 51 |
# File 'lib/gem_grep.rb', line 47 def setup_marshal_index(name=nil) server = name if name download_marshal_index unless File.exists?(marshal_compressed_file) File.open(marshal_file, 'w') {|f| f.write Zlib::Inflate.inflate(File.read(marshal_compressed_file)) } end |