Skip to content
Browse files

savepoint while working on list command

  • Loading branch information...
1 parent 159d712 commit 18d4bf37bf4c0e0d54831049d738ee3ea700fd0a @copiousfreetime committed Nov 16, 2010
Showing with 56 additions and 8 deletions.
  1. +1 −1 lib/stickler/middleware/helpers.rb
  2. +3 −6 lib/stickler/repository/index.rb
  3. +52 −1 lib/stickler/repository/local.rb
View
2 lib/stickler/middleware/helpers.rb
@@ -106,7 +106,7 @@ def append_specs
#
# The Class that includes this module and wants to use +append_specs+ MUST
# have a +repo+ method. The +repo+ method must +respond_to+ both
- # +root_dir+ and +specs+.
+ # +root_dir+ and +latest_specs+.
#
def append_latest_specs
append_spec( self.repo.root_dir, self.repo.latest_specs )
View
9 lib/stickler/repository/index.rb
@@ -18,8 +18,6 @@ class Error < ::Stickler::Repository::Error; end
# The directory the specs live
attr_reader :spec_dir
- #
-
def initialize( spec_dir )
@specs = []
@spec_dir = spec_dir
@@ -50,10 +48,9 @@ def load_specs
end
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 )
+ return true unless @last_modified_time
+ current_modified_time = File.stat( self.spec_dir ).mtime
+ return (current_modified_time > @last_modified_time )
end
def last_modified_time
View
53 lib/stickler/repository/local.rb
@@ -19,6 +19,9 @@ module Stickler::Repository
class Local
class Error < ::Stickler::Repository::Error; end
+ # The name to give to this repository
+ attr_reader :name
+
# the root directory of the repository
attr_reader :root_dir
@@ -34,8 +37,56 @@ class Error < ::Stickler::Repository::Error; end
# the index of the repository
attr_reader :index
- def initialize( root_dir )
+ # mutex for synchronizing local instance allocations
+ @mutex = Mutex.new
+
+ # The list of repos keyd by root_dir
+ @repos = Hash.new
+
+ #
+ # Return the list of all the Local repositories
+ #
+ def self.repos
+ return @repos
+ end
+
+ #
+ # :call-seq:
+ # Local.new( '/tmp/repo' )
+ # Local.new( '/tmp/repo', "Temporary Repo" )
+ #
+ # Create a new Local repository. Local repository instances
+ # are shared if the +root_dir+ is the same. That is
+ #
+ # repo1 = Local.new( '/foo/bar' )
+ # repo2 = Local.new( '/foo/bar' )
+ #
+ # repo1 and repo2 will be references to the sname object
+ #
+ # If a new is called for an already existing repo, and the +name+
+ # of the repo is not nil, and different than the existing repo
+ # an exception is raised.
+ #
+ def self.new( root_dir, name = nil )
+ repo = nil
+ @mutex.syncrhonize do
+ local_key = File.expand_path( root_dir ) + File::SEPARATOR
+ repo = @repos[local_key]
+ if repo.nil? then
+ repo = super( local_key, name )
+ @repos[root_dir] = repo
+ else
+ if repo.name != name then
+ raise Error, "A repository already exists for #{root_dir} with name has the name #{repo.name} which conflicts with the given name #{name}"
+ end
+ end
+ end
+ repo
+ end
+
+ def initialize( root_dir, name = nil )
@root_dir = File.expand_path( root_dir ) + File::SEPARATOR
+ @name = name || @root_dir
@gems_dir = File.join( @root_dir, 'gems/' )
@specifications_dir = File.join( @root_dir, 'specifications/' )
@temp_dir = File.join( @root_dir, "tmp/" )

0 comments on commit 18d4bf3

Please sign in to comment.
Something went wrong with that request. Please try again.