Module: Gync

Extended by:
Gync
Included in:
Gync
Defined in:
lib/gync.rb,
lib/gync/git.rb

Defined Under Namespace

Classes: Git

Instance Method Summary collapse

Instance Method Details

#config_fileObject



39
40
41
# File 'lib/gync.rb', line 39

def config_file
  ENV['GYNC_CONFIG'] || File.join(home_dir, '.gync.yml')
end

#home_dirObject



35
36
37
# File 'lib/gync.rb', line 35

def home_dir
  ENV['HOME']
end

#opts_for(command) ⇒ Object



43
44
45
46
47
48
49
50
# File 'lib/gync.rb', line 43

def opts_for(command)
  opts = YAML.load_file(config_file)
  # validate
  result = opts[command] || raise("There is no `#{command}` section #{config_file}")
  result['local']        || raise("There is no `#{command}.local` section #{config_file}")
  result['remote']       || raise("There is no `#{command}.remote` section #{config_file}")
  OpenStruct.new(result)
end


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

def print_help
  puts <<-HELP
Synchronizes application data using git.
Usage:
  gync COMMAND <command_options>
  gync --help

For more help please visit https://github.com/greyblake/gync
  HELP
end

#run(args) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/gync.rb', line 22

def run(args)
  @opts = opts_for args.first
  git = Gync::Git.new(@opts.local, @opts.remote)
  git.pull
  system Shellwords.shelljoin args
  git.push
rescue Exception => err
  log = Logger.new '/tmp/gync.log'
  log.error err
  STDERR.puts err
  exit 1
end