Class: Databasion::GitCommitter

Inherits:
Object
  • Object
show all
Defined in:
lib/databasion/git_committer.rb

Defined Under Namespace

Classes: GitCommitterError

Constant Summary collapse

@@config =
nil

Class Method Summary collapse

Class Method Details

.check_lock?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/databasion/git_committer.rb', line 41

def self.check_lock?
  File.exist?('git.lock') ? true : false
end

.check_repo?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/databasion/git_committer.rb', line 37

def self.check_repo?
  File.exist?('.git') ? true : false
end

.commit(path = Dir.pwd) ⇒ Object

Raises:



21
22
23
24
25
26
27
28
# File 'lib/databasion/git_committer.rb', line 21

def self.commit(path=Dir.pwd)
  raise GitCommitterError, "A file lock is in place.  Cannot commit." if check_lock?
  create unless check_repo?
  create_lock
  Databasion::LOGGER.info 'running: git commit -am "databasion auto commit"'
  system git_path + ' commit -am "databasion auto commit"'
  remove_lock
end

.configObject



13
14
15
# File 'lib/databasion/git_committer.rb', line 13

def self.config
  @@config
end

.config=(config) ⇒ Object



9
10
11
# File 'lib/databasion/git_committer.rb', line 9

def self.config=(config)
  @@config = config
end

.createObject



30
31
32
33
34
35
# File 'lib/databasion/git_committer.rb', line 30

def self.create
  Databasion::LOGGER.info 'creating new git repository'
  Databasion::LOGGER.info 'running: git init'
  system git_path + ' init'
  system git_path + ' add .'
end

.create_lockObject



45
46
47
# File 'lib/databasion/git_committer.rb', line 45

def self.create_lock
  File.new('git.lock', 'w') unless check_lock?
end

.git_pathObject



17
18
19
# File 'lib/databasion/git_committer.rb', line 17

def self.git_path
  @@config['git']['bin']
end

.remove_lockObject



49
50
51
# File 'lib/databasion/git_committer.rb', line 49

def self.remove_lock
  FileUtils.rm 'git.lock'
end