Class: RightScraper::Repositories::Base
- Inherits:
-
Object
- Object
- RightScraper::Repositories::Base
- Defined in:
- lib/right_scraper/repositories/base.rb
Overview
Description of remote repository that needs to be scraped.
Repository definitions inherit from this base class. A repository must register its #repo_type in @@types so that they can be used with Repositories::Base::from_hash, as follows:
class ARepository < Base
...
# Add this repository to the list of available types.
@@types[:arepository] = ARepository
end
Subclasses should override #repo_type, #retriever and #to_url; when sensible, #revision should also be overridden. The most important methods are #to_url, which will return a URI
that completely characterizes the repository, and #retriever which returns the appropriate RightScraper::Retrievers::Base to scan that repository.
Defined Under Namespace
Modules: PATTERN
Constant Summary collapse
- @@types =
(Hash) Lookup table from textual description of repository type (‘git’, ‘svn’ or ‘download’ currently) to the class that represents that repository.
{}
- @@okay_schemes =
(Set) list of acceptable URI schemes. Initially just http, https and ftp.
Set.new(["http", "https", "ftp"])
Instance Attribute Summary collapse
-
#display_name ⇒ Object
(String) Human readable repository name used for progress reports.
-
#resources_path ⇒ Object
(Array of String) Subdirectories in the repository to search for resources.
-
#url ⇒ Object
(String) URL to repository (e.g ‘git://github.com/rightscale/right_scraper.git’).
Class Method Summary collapse
-
.from_hash(opts) ⇒ Object
Initialize repository from given hash Hash keys should correspond to attributes of this class.
Instance Method Summary collapse
-
#==(other) ⇒ Object
Return true if this repository and
other
represent the same repository including the same checkout tag. -
#checkout_hash ⇒ Object
Return a unique identifier for this revision in this repository.
-
#equal_repo?(other) ⇒ Boolean
Return true if this repository and
other
represent the same repository, excluding the checkout tag. -
#repo_type ⇒ Object
(String) Type of the repository.
-
#repository_hash ⇒ Object
Return a unique identifier for this repository ignoring the tags to check out.
-
#retriever(options) ⇒ Object
(RightScraper::Retrievers::Base class) Appropriate class for retrieving this sort of repository.
-
#revision ⇒ Object
Return the revision this repository is currently looking at.
-
#to_s ⇒ Object
Unique representation for this repo, should resolve to the same string for repos that should be cloned in same directory.
-
#to_url ⇒ Object
Convert this repository to a URL in the style of resource URLs.
Instance Attribute Details
#display_name ⇒ Object
(String) Human readable repository name used for progress reports
77 78 79 |
# File 'lib/right_scraper/repositories/base.rb', line 77 def display_name @display_name end |
#resources_path ⇒ Object
(Array of String) Subdirectories in the repository to search for resources
80 81 82 |
# File 'lib/right_scraper/repositories/base.rb', line 80 def resources_path @resources_path end |
#url ⇒ Object
(String) URL to repository (e.g ‘git://github.com/rightscale/right_scraper.git’)
83 84 85 |
# File 'lib/right_scraper/repositories/base.rb', line 83 def url @url end |
Class Method Details
.from_hash(opts) ⇒ Object
Initialize repository from given hash Hash keys should correspond to attributes of this class
Parameters
- opts(Hash)
-
Hash to be converted into a RightScraper::Repositories::Base instance
Return
- repo(RightScraper::Repositories::Base)
-
Resulting repository instance
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/right_scraper/repositories/base.rb', line 59 def self.from_hash(opts) repo_class = @@types[opts[:repo_type]] raise "Can't understand how to make #{opts[:repo_type]} repos" if repo_class.nil? repo = repo_class.new unless ENV['DEVELOPMENT'] validate_uri opts[:url] end opts.each do |k, v| next if k == :repo_type if [:first_credential, :second_credential].include?(k) && is_useful?(v) v = useful_part(v) end repo.__send__("#{k.to_s}=".to_sym, v) end repo end |
Instance Method Details
#==(other) ⇒ Object
Return true if this repository and other
represent the same repository including the same checkout tag.
Parameters
- other(Repositories::Base)
-
repository to compare with
Returns
- Boolean
-
true iff this repository and
other
are the same
157 158 159 160 161 162 163 |
# File 'lib/right_scraper/repositories/base.rb', line 157 def ==(other) if other.is_a?(RightScraper::Repositories::Base) checkout_hash == other.checkout_hash else false end end |
#checkout_hash ⇒ Object
Return a unique identifier for this revision in this repository.
Returns
- String
-
opaque unique ID for this revision in this repository
128 129 130 |
# File 'lib/right_scraper/repositories/base.rb', line 128 def checkout_hash repository_hash end |
#equal_repo?(other) ⇒ Boolean
Return true if this repository and other
represent the same repository, excluding the checkout tag.
Parameters
- other(Repositories::Base)
-
repository to compare with
Returns
- Boolean
-
true iff this repository and
other
are the same
173 174 175 176 177 178 179 |
# File 'lib/right_scraper/repositories/base.rb', line 173 def equal_repo?(other) if other.is_a?(RightScraper::Repositories::Base) repository_hash == other.repository_hash else false end end |
#repo_type ⇒ Object
(String) Type of the repository. Currently one of ‘git’, ‘svn’ or ‘download’, implemented by the appropriate subclass. Needs to be overridden by subclasses.
88 89 90 |
# File 'lib/right_scraper/repositories/base.rb', line 88 def repo_type raise NotImplementedError end |
#repository_hash ⇒ Object
Return a unique identifier for this repository ignoring the tags to check out.
Returns
- String
-
opaque unique ID for this repository
120 121 122 |
# File 'lib/right_scraper/repositories/base.rb', line 120 def repository_hash digest("#{PROTOCOL_VERSION}\000#{repo_type}\000#{url}") end |
#retriever(options) ⇒ Object
(RightScraper::Retrievers::Base class) Appropriate class for retrieving this sort of repository. Needs to be overridden appropriately by subclasses.
Options
:max_bytes
-
Maximum number of bytes to read
:max_seconds
-
Maximum number of seconds to spend reading
:basedir
-
Destination directory, use temp dir if not specified
:logger
-
Logger to use
Returns
- retriever(Retrievers::Base)
-
Corresponding retriever instance
103 104 105 |
# File 'lib/right_scraper/repositories/base.rb', line 103 def retriever() raise NotImplementedError end |
#revision ⇒ Object
Return the revision this repository is currently looking at.
Returns
- String
-
opaque revision type
111 112 113 |
# File 'lib/right_scraper/repositories/base.rb', line 111 def revision nil end |
#to_s ⇒ Object
Unique representation for this repo, should resolve to the same string for repos that should be cloned in same directory
Returns
- res(String)
-
Unique representation for this repo
137 138 139 |
# File 'lib/right_scraper/repositories/base.rb', line 137 def to_s res = "#{repo_type} #{url}" end |
#to_url ⇒ Object
Convert this repository to a URL in the style of resource URLs.
Returns
- URI
-
URL representing this repository
145 146 147 |
# File 'lib/right_scraper/repositories/base.rb', line 145 def to_url URI.parse(url) end |