Class: Smeagol::Repository

Inherits:
Object
  • Object
show all
Defined in:
lib/smeagol/repository.rb

Overview

Repostiory encapsulation. This class serves two needs, as a wiki repo (for Config) and as a site repo (for Settings). Which fields are actually used depends on which of these two use cases is at play.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Repository

Returns a new instance of Repository.


11
12
13
14
15
16
17
18
19
20
# File 'lib/smeagol/repository.rb', line 11

def initialize(opts={})
  opts = OpenStruct.new(opts)
  @path   = opts.path
  @origin = opts.origin
  @ref    = opts.ref || opts.tag || opts.branch || 'master'
  @bare   = opts.bare
  @secret = opts.secret
  @cname  = opts.cname
  @update = opts.update
end

Instance Attribute Details

#bareObject

Is the repository bare?


46
47
48
# File 'lib/smeagol/repository.rb', line 46

def bare
  @bare
end

#cnameObject

Returns the value of attribute cname


49
50
51
# File 'lib/smeagol/repository.rb', line 49

def cname
  @cname
end

#originObject

Site's git repo uri. e.g. `[email protected]:trans/trans.github.com.git`


27
28
29
# File 'lib/smeagol/repository.rb', line 27

def origin
  @origin
end

#pathObject

Returns the value of attribute path


23
24
25
# File 'lib/smeagol/repository.rb', line 23

def path
  @path
end

#refObject Also known as: tag, branch

For deployment site, if the repo is using detached branch approach, then specify the branch name here. This will typically be used for GitHub projects using `gh-pages`. Default is `master`.


32
33
34
# File 'lib/smeagol/repository.rb', line 32

def ref
  @ref
end

#secretObject

Passcode, if needed to interact with repo.


43
44
45
# File 'lib/smeagol/repository.rb', line 43

def secret
  @secret
end

Instance Method Details

#auto_update?Boolean

Returns:

  • (Boolean)

52
53
54
# File 'lib/smeagol/repository.rb', line 52

def auto_update?
  @update
end

#cloneObject

Clone repo to path.


76
77
78
79
80
81
# File 'lib/smeagol/repository.rb', line 76

def clone
  # dummy location
  tmp = ::File.join(::Dir.tmpdir, 'smeagol', Time.to_i)
  git = Grit::Git.new(tmp)
  git.clone({:quiet=>false, :verbose=>true, :progress=>true, :branch=>branch}, origin, path)
end

#pullObject Also known as: update

Pull down any changes.


64
65
66
# File 'lib/smeagol/repository.rb', line 64

def pull
  repo.git.pull({}, 'origin', branch)
end

#repoObject


57
58
59
# File 'lib/smeagol/repository.rb', line 57

def repo
  @repo ||= Grit::Repo.new(path, :is_bare=>bare)
end