Class: Piston::Repository

Inherits:
Object
  • Object
show all
Defined in:
lib/piston/repository.rb

Direct Known Subclasses

Git::Repository, Svn::Repository

Defined Under Namespace

Classes: UnhandledUrl

Constant Summary collapse

@@handlers =
Array.new

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url) ⇒ Repository

Returns a new instance of Repository.



37
38
39
# File 'lib/piston/repository.rb', line 37

def initialize(url)
  @url = url
end

Instance Attribute Details

#urlObject (readonly)

Returns the value of attribute url.



35
36
37
# File 'lib/piston/repository.rb', line 35

def url
  @url
end

Class Method Details

.add_handler(handler) ⇒ Object



26
27
28
# File 'lib/piston/repository.rb', line 26

def add_handler(handler)
  @@handlers << handler
end

.guess(url) ⇒ Object

Raises:



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/piston/repository.rb', line 12

def guess(url)
  logger.info {"Guessing the repository type of #{url.inspect}"}
  
  handler = handlers.detect do |handler|
    logger.debug {"Asking #{handler}"}
    handler.understands_url?(url)
  end
  
  raise UnhandledUrl unless handler
  
  handler.new(url)
end

.handlersObject



30
31
32
# File 'lib/piston/repository.rb', line 30

def handlers
  @@handlers
end

.loggerObject



8
9
10
# File 'lib/piston/repository.rb', line 8

def logger
  @@logger ||= Log4r::Logger["handler"]
end

Instance Method Details

#==(other) ⇒ Object



53
54
55
# File 'lib/piston/repository.rb', line 53

def ==(other)
  url == other.url
end

#at(revision) ⇒ Object



45
46
47
# File 'lib/piston/repository.rb', line 45

def at(revision)
  raise SubclassResponsibilityError, "Piston::Repository#at should be implemented by a subclass."
end

#loggerObject



41
42
43
# File 'lib/piston/repository.rb', line 41

def logger
  self.class.logger
end

#to_sObject



49
50
51
# File 'lib/piston/repository.rb', line 49

def to_s
  "Piston::Repository(#{@url})"
end