Class: Stickler::Repository::Local
- Inherits:
-
Object
- Object
- Stickler::Repository::Local
- Defined in:
- lib/stickler/repository/local.rb
Overview
A local repository of gems. It implements the Repository::Api and stores all the gems and specifications local to a root directory.
It currently has two subdirectories:
gems/ -> holding the .gem files specifications/ -> holding the .gemspec files
Defined Under Namespace
Classes: Error
Instance Attribute Summary collapse
-
#gems_dir ⇒ Object
readonly
the directory containing the .gem files.
-
#index ⇒ Object
readonly
the index of the repository.
-
#root_dir ⇒ Object
readonly
the root directory of the repository.
-
#specifications_dir ⇒ Object
readonly
the directory containing the .gemspec files.
-
#temp_dir ⇒ Object
readonly
a temporary directory for odds and ends.
Instance Method Summary collapse
-
#add(io) ⇒ Object
:call-seq: repo.add( io ) -> Stickler::SpecLite.
-
#delete(spec) ⇒ Object
See Api#delete.
- #full_path_to_gem(spec) ⇒ Object
- #full_path_to_specification(spec) ⇒ Object
- #gem_file_exist?(spec) ⇒ Boolean
-
#gems_uri ⇒ Object
See Api#gems_uri.
-
#get(spec) ⇒ Object
See Api#get.
-
#initialize(root_dir) ⇒ Local
constructor
A new instance of Local.
-
#last_modified_time ⇒ Object
The last time this index was modified.
-
#latest_specs ⇒ Object
A list of just the latests specs in the repo.
-
#open(spec, &block) ⇒ Object
See Api#open.
-
#push(path) ⇒ Object
See Api#push.
-
#search_for(spec) ⇒ Object
See Api#search_for.
- #specification_file_exist?(spec) ⇒ Boolean
-
#specs ⇒ Object
A list of all the specs in the repo.
-
#uri ⇒ Object
See Api#uri.
-
#uri_for_gem(spec) ⇒ Object
See Api#uri_from_gem.
-
#yank(spec) ⇒ Object
See Api#yank.
Constructor Details
#initialize(root_dir) ⇒ Local
37 38 39 40 41 42 43 44 |
# File 'lib/stickler/repository/local.rb', line 37 def initialize( root_dir ) @root_dir = File.( root_dir ) + File::SEPARATOR @gems_dir = File.join( @root_dir, 'gems/' ) @specifications_dir = File.join( @root_dir, 'specifications/' ) @temp_dir = File.join( @root_dir, "tmp/" ) @index = ::Stickler::Repository::Index.new( @specifications_dir ) setup_dirs end |
Instance Attribute Details
#gems_dir ⇒ Object (readonly)
the directory containing the .gem files
26 27 28 |
# File 'lib/stickler/repository/local.rb', line 26 def gems_dir @gems_dir end |
#index ⇒ Object (readonly)
the index of the repository
35 36 37 |
# File 'lib/stickler/repository/local.rb', line 35 def index @index end |
#root_dir ⇒ Object (readonly)
the root directory of the repository
23 24 25 |
# File 'lib/stickler/repository/local.rb', line 23 def root_dir @root_dir end |
#specifications_dir ⇒ Object (readonly)
the directory containing the .gemspec files
29 30 31 |
# File 'lib/stickler/repository/local.rb', line 29 def specifications_dir @specifications_dir end |
#temp_dir ⇒ Object (readonly)
a temporary directory for odds and ends
32 33 34 |
# File 'lib/stickler/repository/local.rb', line 32 def temp_dir @temp_dir end |
Instance Method Details
#add(io) ⇒ Object
:call-seq:
repo.add( io ) -> Stickler::SpecLite
A lower level version of #push. The item passed in is an IO like object that contains the binary stream that is a .gem file. IO must respond to #read and #rewind.
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/stickler/repository/local.rb', line 120 def add( io ) # spooling to a temp file because Gem::Format.from_io() closes the io # stream it is sent. Why it does this, I do not know. tempfile = Tempfile.new( "uploaded-gem.", temp_dir ) tempfile.write( io.read ) tempfile.rewind format = Gem::Format.from_file_by_path( tempfile.path ) spec = Stickler::SpecLite.new( format.spec.name, format.spec.version, format.spec.platform ) specs = search_for( spec ) raise Error, "gem #{spec.full_name} already exists" unless specs.empty? tempfile.rewind return install( spec, tempfile ) ensure tempfile.close! end |
#delete(spec) ⇒ Object
See Api#delete
99 100 101 |
# File 'lib/stickler/repository/local.rb', line 99 def delete( spec ) uninstall( spec ) end |
#full_path_to_gem(spec) ⇒ Object
178 179 180 |
# File 'lib/stickler/repository/local.rb', line 178 def full_path_to_gem( spec ) File.join( gems_dir, spec.file_name ) end |
#full_path_to_specification(spec) ⇒ Object
182 183 184 |
# File 'lib/stickler/repository/local.rb', line 182 def full_path_to_specification( spec ) File.join( specifications_dir, spec.spec_file_name ) end |
#gem_file_exist?(spec) ⇒ Boolean
186 187 188 |
# File 'lib/stickler/repository/local.rb', line 186 def gem_file_exist?( spec ) File.exist?( full_path_to_gem( spec ) ) end |
#gems_uri ⇒ Object
See Api#gems_uri
56 57 58 |
# File 'lib/stickler/repository/local.rb', line 56 def gems_uri @gems_uri ||= Addressable::URI.convert_path( gems_dir ) end |
#get(spec) ⇒ Object
See Api#get
154 155 156 157 |
# File 'lib/stickler/repository/local.rb', line 154 def get( spec ) return IO.read( full_path_to_gem( spec ) ) if gem_file_exist?( spec ) return nil end |
#last_modified_time ⇒ Object
The last time this index was modified
85 86 87 |
# File 'lib/stickler/repository/local.rb', line 85 def last_modified_time @index.last_modified_time end |
#latest_specs ⇒ Object
A list of just the latests specs in the repo
78 79 80 |
# File 'lib/stickler/repository/local.rb', line 78 def latest_specs @index.latest_specs end |
#open(spec, &block) ⇒ Object
See Api#open
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/stickler/repository/local.rb', line 162 def open( spec, &block ) return nil unless gem_file_exist?( spec ) path = full_path_to_gem( spec ) f = File.open( path, "rb" ) if block_given? then begin yield f ensure f.close end else return f end return nil end |
#push(path) ⇒ Object
See Api#push
142 143 144 145 146 147 148 149 |
# File 'lib/stickler/repository/local.rb', line 142 def push( path ) spec = specification_from_gem_file( path ) result = nil File.open( path ) do |io| result = add( io ) end return result end |
#search_for(spec) ⇒ Object
See Api#search_for
92 93 94 |
# File 'lib/stickler/repository/local.rb', line 92 def search_for( spec ) return index.search( spec ) end |
#specification_file_exist?(spec) ⇒ Boolean
190 191 192 |
# File 'lib/stickler/repository/local.rb', line 190 def specification_file_exist?( spec ) File.exist?( full_path_to_specification( spec ) ) end |
#specs ⇒ Object
A list of all the specs in the repo
71 72 73 |
# File 'lib/stickler/repository/local.rb', line 71 def specs @index.specs end |
#uri ⇒ Object
See Api#uri
49 50 51 |
# File 'lib/stickler/repository/local.rb', line 49 def uri @uri ||= Addressable::URI.convert_path( root_dir ) end |
#uri_for_gem(spec) ⇒ Object
See Api#uri_from_gem
63 64 65 66 |
# File 'lib/stickler/repository/local.rb', line 63 def uri_for_gem( spec ) return nil unless gem_file_exist?( spec ) return self.gems_uri.join( spec.file_name ) end |
#yank(spec) ⇒ Object
See Api#yank
106 107 108 109 |
# File 'lib/stickler/repository/local.rb', line 106 def yank( spec ) uninstall_specification( spec ) if specification_file_exist?( spec ) return uri_for_gem( spec ) end |