Class: Six::Repositories::Rsync::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/six/rsync/base.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Base

Returns a new instance of Base.



63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/six/rsync/base.rb', line 63

def initialize(options = {})
  if working_dir = options[:working_directory]
    options[:repository] ||= File.join(working_dir, '.rsync')
  end
  if options[:log]
    @logger = options[:log]
    @logger.debug("Starting Rsync on #{working_dir}")
  else
    @logger = nil
  end
  @working_directory = options[:working_directory] ? Rsync::WorkingDirectory.new(options[:working_directory]) : nil
  @repository = options[:repository] ? Rsync::Repository.new(options[:repository]) : nil

end

Instance Attribute Details

#repositoryObject (readonly)

Returns the value of attribute repository.



7
8
9
# File 'lib/six/rsync/base.rb', line 7

def repository
  @repository
end

Class Method Details

.clone(host, name, opts = {}) ⇒ Object

clones a rsync repository locally

repository - http://repo.or.cz/w/sinatra.git
name - sinatra

options:

:repository

 :bare
or
 :working_directory
 :index_file


53
54
55
56
57
58
59
60
61
# File 'lib/six/rsync/base.rb', line 53

def self.clone(host, name, opts = {})
  # run Rsync clone
  logger = if opts[:log]
    opts[:log]
  else
    nil
  end
  self.new(Rsync::Lib.new(nil, logger).clone(host, name, opts))
end

.init(working_dir, opts = {}) ⇒ Object

initializes a rsync repository

options:

:repository
:index_file


21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/six/rsync/base.rb', line 21

def self.init(working_dir, opts = {})
  opts = {
    :working_directory => working_dir,
    :repository => File.join(working_dir, '.rsync')
  }.merge(opts)

  #FileUtils.mkdir_p(opts[:working_directory]) if opts[:working_directory] && !File.directory?(opts[:working_directory])

  # run rsync_init there
  logger = if opts[:log]
    opts[:log]
  else
    nil
  end
  Rsync::Lib.new(opts, logger).init

  self.new(opts)
end

.open(working_dir, opts = {}) ⇒ Object

opens a new Rsync Project from a working directory you can specify non-standard rsync_dir and index file in the options



11
12
13
# File 'lib/six/rsync/base.rb', line 11

def self.open(working_dir, opts={})
  self.new({:working_directory => working_dir}.merge(opts))
end

Instance Method Details

#add(file = '') ⇒ Object



86
87
88
# File 'lib/six/rsync/base.rb', line 86

def add(file = '')
  lib.add(file)
end

#chdirObject

changes current working directory for a block to the rsync working directory

example

@rsync.chdir do
  # write files
  @rsync.add
  @rsync.commit('message')
end


125
126
127
128
129
# File 'lib/six/rsync/base.rb', line 125

def chdir # :yields: the Rsync::Path
  Dir.chdir(dir.path) do
    yield dir.path
  end
end

#commitObject



90
91
92
# File 'lib/six/rsync/base.rb', line 90

def commit
  lib.commit
end

#dirObject

returns a reference to the working directory

@rsync.dir.path
@rsync.dir.writeable?


101
102
103
# File 'lib/six/rsync/base.rb', line 101

def dir
  @working_directory
end

#libObject

this is a convenience method for accessing the class that wraps all the actual ‘git’ forked system calls. At some point I hope to replace the Git::Lib class with one that uses native methods or libgit C bindings



148
149
150
# File 'lib/six/rsync/base.rb', line 148

def lib
  @lib ||= Rsync::Lib.new(self, @logger)
end

#pushObject



94
95
96
# File 'lib/six/rsync/base.rb', line 94

def push
  lib.push
end

#repoObject

returns reference to the rsync repository directory

@rsync.dir.path


107
108
109
# File 'lib/six/rsync/base.rb', line 107

def repo
  @repository
end

#repo_sizeObject

returns the repository size in bytes



132
133
134
135
136
137
138
# File 'lib/six/rsync/base.rb', line 132

def repo_size
  size = 0
  Dir.chdir(repo.path) do
    (size, dot) = `du -s`.chomp.split
  end
  size.to_i
end

#reset(opts = {}) ⇒ Object



82
83
84
# File 'lib/six/rsync/base.rb', line 82

def reset(opts = {})
  lib.reset(opts)
end

#set_working(work_dir, check = true) ⇒ Object



111
112
113
114
# File 'lib/six/rsync/base.rb', line 111

def set_working(work_dir, check = true)
  @lib = nil
  @working_directory = Rsync::WorkingDirectory.new(work_dir.to_s, check)
end

#statusObject

returns a Rsync::Status object



141
142
143
# File 'lib/six/rsync/base.rb', line 141

def status
  lib.status
end

#updateObject



78
79
80
# File 'lib/six/rsync/base.rb', line 78

def update
  lib.update('')
end