class Gitomator::ServiceProvider::HostingLocal
A hosting provider that manages repos in a directory on the local file-system.
Attributes
local_dir[R]
local_repos_dir[R]
Public Class Methods
new(git_service, local_dir, opts = {})
click to toggle source
# File lib/gitomator/service_provider/hosting_local.rb, line 34 def initialize(git_service, local_dir, opts = {}) @git = git_service raise "Local directory doesn't exist, #{local_dir}" unless Dir.exist? local_dir @local_dir = local_dir @local_repos_dir = File.join(@local_dir, opts[:repos_dir] || 'repos') Dir.mkdir @local_repos_dir unless Dir.exist? @local_repos_dir end
Public Instance Methods
_rename_repo(old_name, new_name)
click to toggle source
# File lib/gitomator/service_provider/hosting_local.rb, line 95 def _rename_repo(old_name, new_name) raise "No such repo '#{old_name}'" unless Dir.exist? repo_root(old_name) FileUtils.mv repo_root(old_name), repo_root(new_name) end
create_repo(name, opts)
click to toggle source
# File lib/gitomator/service_provider/hosting_local.rb, line 57 def create_repo(name, opts) raise "Directory exists, #{repo_root(name)}" if Dir.exist? repo_root(name) @git.init(repo_root(name), opts) return ModelObject.new({ :name => name, :full_name => name, :url => "#{repo_root(name)}/.git" }) end
delete_repo(name)
click to toggle source
# File lib/gitomator/service_provider/hosting_local.rb, line 85 def delete_repo(name) if Dir.exist? repo_root(name) FileUtils.rm_rf repo_root(name) else raise "No such repo, '#{name}'" end return nil end
name()
click to toggle source
# File lib/gitomator/service_provider/hosting_local.rb, line 46 def name :local end
read_repo(name)
click to toggle source
# File lib/gitomator/service_provider/hosting_local.rb, line 66 def read_repo(name) if Dir.exist? repo_root(name) return ModelObject.new({ :name => name, :full_name => name, :url => "#{repo_root(name)}/.git" }) else return nil end end
repo_root(name)
click to toggle source
# File lib/gitomator/service_provider/hosting_local.rb, line 51 def repo_root(name) File.join(local_repos_dir, name) end
update_repo(name, opts={})
click to toggle source
# File lib/gitomator/service_provider/hosting_local.rb, line 77 def update_repo(name, opts={}) if opts[:name] _rename_repo(name, opts[:name]) end return read_repo(name) end