Class: Gitomator::ServiceProvider::HostingLocal
- Inherits:
-
Object
- Object
- Gitomator::ServiceProvider::HostingLocal
- Defined in:
- lib/gitomator/service_provider/hosting_local.rb
Overview
A hosting provider that manages repos in a directory on the local file-system.
Defined Under Namespace
Classes: ModelObject
Instance Attribute Summary collapse
-
#local_dir ⇒ Object
readonly
Returns the value of attribute local_dir.
-
#local_repos_dir ⇒ Object
readonly
Returns the value of attribute local_repos_dir.
Instance Method Summary collapse
- #_rename_repo(old_name, new_name) ⇒ Object
-
#create_repo(name, opts) ⇒ Object
———————————————————————.
- #delete_repo(name) ⇒ Object
-
#initialize(git_service, local_dir, opts = {}) ⇒ HostingLocal
constructor
A new instance of HostingLocal.
-
#name ⇒ Object
———————————————————————.
- #read_repo(name) ⇒ Object
- #repo_root(name) ⇒ Object
- #update_repo(name, opts = {}) ⇒ Object
Constructor Details
#initialize(git_service, local_dir, opts = {}) ⇒ HostingLocal
34 35 36 37 38 39 40 41 42 |
# 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 |
Instance Attribute Details
#local_dir ⇒ Object (readonly)
Returns the value of attribute local_dir.
32 33 34 |
# File 'lib/gitomator/service_provider/hosting_local.rb', line 32 def local_dir @local_dir end |
#local_repos_dir ⇒ Object (readonly)
Returns the value of attribute local_repos_dir.
32 33 34 |
# File 'lib/gitomator/service_provider/hosting_local.rb', line 32 def local_repos_dir @local_repos_dir end |
Instance Method Details
#_rename_repo(old_name, new_name) ⇒ Object
95 96 97 98 |
# 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) ⇒ Object
57 58 59 60 61 62 63 |
# 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) ⇒ Object
85 86 87 88 89 90 91 92 |
# 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 ⇒ Object
46 47 48 |
# File 'lib/gitomator/service_provider/hosting_local.rb', line 46 def name :local end |
#read_repo(name) ⇒ Object
66 67 68 69 70 71 72 73 74 |
# 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) ⇒ Object
51 52 53 |
# 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 = {}) ⇒ Object
77 78 79 80 81 82 |
# 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 |