class Gitomator::Util::Repo::NameResolver
Convenience class dealing with repo names of the format `NAMESPACE/REPO:BRANCH`.
Attributes
default_namespace[R]
Public Class Methods
new(default_namespace=nil)
click to toggle source
# File lib/gitomator/util/repo/name_resolver.rb, line 13 def initialize(default_namespace=nil) @default_namespace = default_namespace end
Public Instance Methods
branch(name)
click to toggle source
# File lib/gitomator/util/repo/name_resolver.rb, line 35 def branch(name) tokenize(name)[2] end
full_name(repo_name)
click to toggle source
# File lib/gitomator/util/repo/name_resolver.rb, line 18 def full_name(repo_name) namespace, name = tokenize(repo_name) if namespace.nil? return name else return "#{namespace}/#{name}" end end
name_only(name)
click to toggle source
# File lib/gitomator/util/repo/name_resolver.rb, line 31 def name_only(name) tokenize(name)[1] end
namespace(name)
click to toggle source
# File lib/gitomator/util/repo/name_resolver.rb, line 27 def namespace(name) tokenize(name)[0] end
tokenize(name)
click to toggle source
Given a string of the format “namespace/name:branch”, return an array with three strings:
1. Namespace 2. Repo-name 3. branch
If the namespace is missing, self's default namespace will be used.
@param name [String] - The name of the repo in the format “namespace/name:branch”.
# File lib/gitomator/util/repo/name_resolver.rb, line 50 def tokenize(name) m = /^([\w-]+\/)?([\w-]+)(\:[\w-]+)?$/.match(name) raise "Invalid repo name, '#{name}'." if m.nil? namespace = m[1] || @default_namespace namespace = namespace.gsub('/', '') unless namespace.nil? repo = m[2] branch = m[3] branch = branch.gsub(':', '') unless branch.nil? return [namespace, repo, branch] end