Class: Stickler::Repository::Index
- Inherits:
-
Object
- Object
- Stickler::Repository::Index
- Defined in:
- lib/stickler/repository/index.rb
Overview
A repository index is a container holding all the SpecLite elements in the repository. All the gem specs that this index holds are derived from actual files on the file system.
It is modelled somewhat like a Gem::SourceIndex.
Defined Under Namespace
Classes: Error
Instance Attribute Summary collapse
-
#spec_dir ⇒ Object
The directory the specs live.
-
#specs ⇒ Object
readonly
The list of specs in the index.
Instance Method Summary collapse
- #add_spec_from_file(path) ⇒ Object
-
#initialize(spec_dir) ⇒ Index
constructor
A new instance of Index.
- #last_modified_time ⇒ Object
- #latest_specs ⇒ Object
- #load_specs ⇒ Object
- #load_specs_in_dir(spec_dir) ⇒ Object
- #reload_necessary? ⇒ Boolean
- #search(find_spec) ⇒ Object
Constructor Details
#initialize(spec_dir) ⇒ Index
Returns a new instance of Index.
23 24 25 26 27 |
# File 'lib/stickler/repository/index.rb', line 23 def initialize( spec_dir ) @specs = [] @spec_dir = spec_dir load_specs end |
Instance Attribute Details
#spec_dir ⇒ Object
The directory the specs live
19 20 21 |
# File 'lib/stickler/repository/index.rb', line 19 def spec_dir @spec_dir end |
#specs ⇒ Object (readonly)
The list of specs in the index
16 17 18 |
# File 'lib/stickler/repository/index.rb', line 16 def specs @specs end |
Instance Method Details
#add_spec_from_file(path) ⇒ Object
80 81 82 83 84 85 86 87 88 89 |
# File 'lib/stickler/repository/index.rb', line 80 def add_spec_from_file( path ) return nil unless File.exist?( path ) code = File.read( path ) full_spec = eval( code, binding, path ) raise Error, "File #{path} is not Gem::Specification in ruby format" unless full_spec.is_a?( Gem::Specification ) full_spec.untaint spec = Stickler::SpecLite.new( full_spec.name, full_spec.version, full_spec.platform ) @specs << spec end |
#last_modified_time ⇒ Object
59 60 61 |
# File 'lib/stickler/repository/index.rb', line 59 def last_modified_time File.stat( self.spec_dir ).mtime end |
#latest_specs ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/stickler/repository/index.rb', line 34 def latest_specs latest = {} specs.each do |s| if old_spec = latest[s.name] then if old_spec.version < s.version then latest[s.name] = s end else latest[s.name] = s end end latest.values end |
#load_specs ⇒ Object
48 49 50 |
# File 'lib/stickler/repository/index.rb', line 48 def load_specs load_specs_in_dir( self.spec_dir ) end |
#load_specs_in_dir(spec_dir) ⇒ Object
69 70 71 72 73 74 75 76 77 78 |
# File 'lib/stickler/repository/index.rb', line 69 def load_specs_in_dir( spec_dir ) return nil unless File.directory?( spec_dir ) @specs.clear self.spec_dir = spec_dir Dir.foreach( spec_dir ) do |entry| next unless entry =~ /\.gemspec\Z/ add_spec_from_file( File.join( spec_dir, entry ) ) end end |
#reload_necessary? ⇒ Boolean
52 53 54 55 56 57 |
# File 'lib/stickler/repository/index.rb', line 52 def reload_necessary? return true # return true unless @last_modified_time # current_modified_time = File.stat( self.spec_dir ).mtime # return (current_modified_time > @last_modified_time ) end |
#search(find_spec) ⇒ Object
91 92 93 94 95 |
# File 'lib/stickler/repository/index.rb', line 91 def search( find_spec ) specs.select do |spec| spec =~ find_spec end end |