Class: Indexer::Repository

Inherits:
Model
  • Object
show all
Defined in:
lib/indexer/components/repository.rb

Overview

The Repository class models a packages SCM repository location. It consists of two parts, the scm type of repository, it's url.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Model

#[], #[]=, attr_reader, attr_writer, #initialize_attributes, #key?, #merge!, #method_missing, #store, #to_h, #to_yaml, #validate

Constructor Details

#initialize(data = {}) ⇒ Repository

Initialize new Repository instance.



38
39
40
41
42
# File 'lib/indexer/components/repository.rb', line 38

def initialize(data={})
  super(data)

  self.scm = infer_scm(uri) unless scm
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Indexer::Model

Instance Attribute Details

#nameObject

A name that can be used to identify the purpose of a particular repository.



48
49
50
# File 'lib/indexer/components/repository.rb', line 48

def name
  @name
end

#scmObject

Returns the value of attribute scm.



78
79
80
# File 'lib/indexer/components/repository.rb', line 78

def scm
  @scm
end

#uriObject

The repository's URI.



63
64
65
# File 'lib/indexer/components/repository.rb', line 63

def uri
  @uri
end

#webcvsObject Also known as: web

Prefix URI that can be used to link to source code.

This name is the traditional one from a time when CVS was the most popular SCM.



103
104
105
# File 'lib/indexer/components/repository.rb', line 103

def webcvs
  @webcvs
end

Class Method Details

.parse(data) ⇒ Repository

Parse data returning a new Repository instance.

-- TODO: Should String be allowed, and thus no id? ++

Parameters:

  • data (String, Array<String>, Array<Hash>, Hash)

    Repository information.

Returns:



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/indexer/components/repository.rb', line 17

def self.parse(data)
  case data
  when String
    new('uri'=>data)
  when Array
    h, d = {}, data.dup  # TODO: data.rekey(&:to_s)
    h.update(d.pop) while Hash === d.last
    h['name'] = d.shift.to_s unless d.empty?
    h['uri']  = d.shift.to_s unless d.empty?
    h['scm']  = d.shift.to_s unless d.empty?
    new(h)
  when Hash
    new(data)
  else
    raise(ValidationError, "not a valid repository")
  end
end

Instance Method Details

#infer_scm(uri) ⇒ Object (private)



123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/indexer/components/repository.rb', line 123

def infer_scm(uri)
  case uri
  when /^git:/, /\.git$/
    'git'
  when /^hg:/, /\.hg$/
    'hg'
  when /^svn:/
    'svn'
  when /darcs/
    'darcs'
  else
    nil
  end
end