Class: Nabokov::Syncer

Inherits:
Runner
  • Object
show all
Defined in:
lib/nabokov/commands/syncers/syncer.rb

Direct Known Subclasses

LocalizationsRepoSyncer, ProjectSyncer

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Runner

#ui

Constructor Details

#initialize(argv) ⇒ Syncer

Returns a new instance of Syncer.



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/nabokov/commands/syncers/syncer.rb', line 15

def initialize(argv)
  nabokovfile = argv.option("nabokovfile")
  unless nabokovfile
    pwd_nabokovfile = Pathname.pwd + "Nabokovfile.yaml"
    nabokovfile = pwd_nabokovfile if File.exist?(pwd_nabokovfile)
  end
  raise "--nabokovfile is a required parameter and could not be nil" if nabokovfile.nil?

  @nabokovfile_path = nabokovfile if File.exist?(nabokovfile)
  super
end

Instance Attribute Details

#git_repoObject (readonly)

Returns the value of attribute git_repo.



9
10
11
# File 'lib/nabokov/commands/syncers/syncer.rb', line 9

def git_repo
  @git_repo
end

#nabokovfileObject (readonly)

Returns the value of attribute nabokovfile.



8
9
10
# File 'lib/nabokov/commands/syncers/syncer.rb', line 8

def nabokovfile
  @nabokovfile
end

Class Method Details

.optionsObject



34
35
36
37
38
# File 'lib/nabokov/commands/syncers/syncer.rb', line 34

def self.options
  [
    ["--nabokovfile=<path/to/nabokovfile>", "The location of your Nabokovfile"]
  ].concat(super)
end

Instance Method Details

#checkout_master_branchObject



63
64
65
66
# File 'lib/nabokov/commands/syncers/syncer.rb', line 63

def checkout_master_branch
  ui.say("Checkout master branch...") if self.verbose
  @git_repo.checkout_branch(@nabokovfile.localizations_repo_master_branch)
end

#init_git_repoObject



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/nabokov/commands/syncers/syncer.rb', line 51

def init_git_repo
  @git_repo = GitRepo.new(@nabokovfile.localizations_repo_local_path, @nabokovfile.localizations_repo_url)
  if Dir.exist?(@git_repo.local_path)
    ui.say("Found existed repo at #{@git_repo.local_path}...") if self.verbose
    @git_repo.init
  else
    ui.say("Cloning the localization repo from #{@git_repo.remote_url} into #{@git_repo.local_path}...") if self.verbose
    @git_repo.clone
  end
  checkout_master_branch
end

#initialize_nabokov_fileObject



46
47
48
49
# File 'lib/nabokov/commands/syncers/syncer.rb', line 46

def initialize_nabokov_file
  @nabokovfile = Nabokovfile.new(@nabokovfile_path)
  ui.say("Hooray, your Nabokovfile is valid...") if self.verbose
end

#runObject



40
41
42
43
44
# File 'lib/nabokov/commands/syncers/syncer.rb', line 40

def run
  initialize_nabokov_file
  init_git_repo
  self
end

#validate!Object



27
28
29
30
31
32
# File 'lib/nabokov/commands/syncers/syncer.rb', line 27

def validate!
  super
  if self.class == Syncer && !@nabokovfile_path
    help! "Could not find a Nabokovfile."
  end
end