Class: Ginatra::RepoList
- Inherits:
-
Object
- Object
- Ginatra::RepoList
- Includes:
- Logger, Singleton
- Defined in:
- lib/ginatra/repo_list.rb
Overview
A singleton class that lets us make and use a constantly updating list of repositories.
Instance Attribute Summary collapse
-
#list ⇒ Object
Returns the value of attribute list.
Class Method Summary collapse
-
.find(local_param) ⇒ Object
This just brings up the find method to the class scope.
-
.list ⇒ Array<Ginatra::Repo>
The preferred way to access the list publicly.
-
.method_missing(sym, *args, &block) ⇒ Object
allows missing methods to cascade to the instance,.
-
.respond_to?(sym) ⇒ Boolean
updated to correspond to the method_missing definition.
Instance Method Summary collapse
-
#add(path, param = File.split(path).last) ⇒ Object
adds a Repo corresponding to the path it found a git repo at in the configured globs.
-
#find(local_param) ⇒ Ginatra::Repo
quick way to look up if there is a repo with a given param in the list.
-
#has_repo?(local_param) ⇒ true, false
checks to see if the list contains a repo with a param matching the one passed in.
-
#initialize ⇒ RepoList
constructor
This creates the list, then does the first refresh to populate it.
-
#refresh ⇒ Object
searches through the configured directory globs to find all the repositories and adds them if they’re not already there.
Methods included from Logger
Constructor Details
#initialize ⇒ RepoList
This creates the list, then does the first refresh to populate it.
It returns what refresh returns.
15 16 17 18 |
# File 'lib/ginatra/repo_list.rb', line 15 def initialize self.list = [] self.refresh end |
Instance Attribute Details
#list ⇒ Object
Returns the value of attribute list.
9 10 11 |
# File 'lib/ginatra/repo_list.rb', line 9 def list @list end |
Class Method Details
.find(local_param) ⇒ Object
This just brings up the find method to the class scope.
95 96 97 |
# File 'lib/ginatra/repo_list.rb', line 95 def self.find(local_param) self.instance.find(local_param) end |
.list ⇒ Array<Ginatra::Repo>
The preferred way to access the list publicly.
23 24 25 26 |
# File 'lib/ginatra/repo_list.rb', line 23 def self.list self.instance.refresh self.instance.list end |
.method_missing(sym, *args, &block) ⇒ Object
allows missing methods to cascade to the instance,
100 101 102 |
# File 'lib/ginatra/repo_list.rb', line 100 def self.method_missing(sym, *args, &block) instance.send(sym, *args, &block) end |
.respond_to?(sym) ⇒ Boolean
updated to correspond to the method_missing definition
105 106 107 |
# File 'lib/ginatra/repo_list.rb', line 105 def self.respond_to?(sym) instance.respond_to?(sym) || super end |
Instance Method Details
#add(path, param = File.split(path).last) ⇒ Object
adds a Repo corresponding to the path it found a git repo at in the configured globs. Checks to see that it’s not there first
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/ginatra/repo_list.rb', line 54 def add(path, param=File.split(path).last) unless self.has_repo?(param) begin list << Repo.new(path) rescue Rugged::RepositoryError logger.warn "SKIPPING '#{path}' - not a git repository" end end list end |
#find(local_param) ⇒ Ginatra::Repo
quick way to look up if there is a repo with a given param in the list. If not, it refreshes the list and tries again.
81 82 83 84 85 86 87 88 89 90 |
# File 'lib/ginatra/repo_list.rb', line 81 def find(local_param) if repo = list.find { |r| r.param == local_param } repo else refresh repo = list.find { |r| r.param == local_param } raise Ginatra::RepoNotFound if repo.nil? repo end end |
#has_repo?(local_param) ⇒ true, false
checks to see if the list contains a repo with a param matching the one passed in.
71 72 73 |
# File 'lib/ginatra/repo_list.rb', line 71 def has_repo?(local_param) !list.find { |r| r.param == local_param }.nil? end |
#refresh ⇒ Object
searches through the configured directory globs to find all the repositories and adds them if they’re not already there.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/ginatra/repo_list.rb', line 30 def refresh list.clear Ginatra.load_config["git_dirs"].map do |git_dir| if Dir.exist?(git_dir.chop) dirs = Dir.glob(git_dir).sort else dir = File.("../../../#{git_dir}", __FILE__) dirs = Dir.glob(dir).sort end dirs = dirs.select {|f| File.directory? f } dirs.each {|d| add(d) } end list end |