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.



82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/six/rsync/base.rb', line 82

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


72
73
74
75
76
77
78
79
80
# File 'lib/six/rsync/base.rb', line 72

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

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



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/six/rsync/base.rb', line 40

def self.convert(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_convert there
  logger = if opts[:log]
    opts[:log]
  else
    nil
  end
  Rsync::Lib.new(opts, logger).convert

  self.new(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



105
106
107
# File 'lib/six/rsync/base.rb', line 105

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


144
145
146
147
148
# File 'lib/six/rsync/base.rb', line 144

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

#commitObject



109
110
111
# File 'lib/six/rsync/base.rb', line 109

def commit
  lib.commit
end

#dirObject

returns a reference to the working directory

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


120
121
122
# File 'lib/six/rsync/base.rb', line 120

def dir
  @working_directory
end

#infoObject



164
165
166
# File 'lib/six/rsync/base.rb', line 164

def info
  lib.info
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



171
172
173
# File 'lib/six/rsync/base.rb', line 171

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

#pushObject



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

def push
  lib.push
end

#repoObject

returns reference to the rsync repository directory

@rsync.dir.path


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

def repo
  @repository
end

#repo_sizeObject

returns the repository size in bytes



151
152
153
154
155
156
157
# File 'lib/six/rsync/base.rb', line 151

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

#reset(opts = {}) ⇒ Object



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

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

#set_working(work_dir, check = true) ⇒ Object



130
131
132
133
# File 'lib/six/rsync/base.rb', line 130

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



160
161
162
# File 'lib/six/rsync/base.rb', line 160

def status
  lib.status
end

#update(opts = {}) ⇒ Object



97
98
99
# File 'lib/six/rsync/base.rb', line 97

def update(opts = {})
  lib.update('', [], opts)
end