Class: Indexer::Repository
- 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
-
#name ⇒ Object
A name that can be used to identify the purpose of a particular repository.
-
#scm ⇒ Object
Returns the value of attribute scm.
-
#uri ⇒ Object
The repository's URI.
-
#webcvs ⇒ Object
(also: #web)
Prefix URI that can be used to link to source code.
Class Method Summary collapse
-
.parse(data) ⇒ Repository
Parse
data
returning a new Repository instance.
Instance Method Summary collapse
- #infer_scm(uri) ⇒ Object private
-
#initialize(data = {}) ⇒ Repository
constructor
Initialize new Repository instance.
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
#name ⇒ Object
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 |
#scm ⇒ Object
Returns the value of attribute scm.
78 79 80 |
# File 'lib/indexer/components/repository.rb', line 78 def scm @scm end |
#uri ⇒ Object
The repository's URI.
63 64 65 |
# File 'lib/indexer/components/repository.rb', line 63 def uri @uri end |
#webcvs ⇒ Object 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
?
++
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 |