Class: Popo::Sync

Inherits:
Object
  • Object
show all
Includes:
Constants
Defined in:
lib/popo/sync.rb

Constant Summary

Constants included from Constants

Constants::COLOR_GREEN, Constants::COLOR_NONE, Constants::COLOR_RED, Constants::COLOR_YELLOW, Constants::DEFAULT_CONFIG_FILE, Constants::DEFAULT_POPO_TARGET, Constants::POPORC, Constants::POPO_COMMANDS, Constants::POPO_CONFIG, Constants::POPO_DIR_KEY, Constants::POPO_KEY_VALUES, Constants::POPO_WORK_PATH, Constants::POPO_YML_FILE, Constants::POST_INSTALL_NOTE, Constants::REQUIRED_COMMANDS

Instance Method Summary collapse

Constructor Details

#initialize(runner) ⇒ Sync

Returns a new instance of Sync.



5
6
7
8
9
10
11
12
13
# File 'lib/popo/sync.rb', line 5

def initialize(runner)
  @db        = runner.database
  @cwd       = Dir.pwd
  @info      = {}
  @projects  = runner.args
  @options   = runner.options
  @sync_list = @db.get(POPO_DIR_KEY).split(',')
  @app_root = runner.app_root
end

Instance Method Details

#convert_to_key(project) ⇒ Object



85
86
87
88
89
90
91
# File 'lib/popo/sync.rb', line 85

def convert_to_key(project)
  if project.is_a? String
    project.split('/').join('.')
  else
    project.join('.')
  end
end

#get_projectObject



67
68
69
70
71
72
73
74
75
76
77
# File 'lib/popo/sync.rb', line 67

def get_project
  if !File.exists?(@info[:path])
    GitUtils.git_clone(@info[:repo], @info[:path], @info[:branch])
  else
    if POPO_CONFIG['target'] == DEFAULT_POPO_TARGET and !@options[:reset]
      GitUtils.git_stash(@info[:path])
    end

    GitUtils.git_update(@info[:path], @info[:branch])
  end
end

#get_values(key) ⇒ Object



79
80
81
82
83
# File 'lib/popo/sync.rb', line 79

def get_values(key)
  POPO_KEY_VALUES.each do |v|
    @info[v.to_sym] = @db.get("#{key}.#{v}")
  end
end

#syncObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/popo/sync.rb', line 15

def sync
  @projects.each do |project|
    if project =~ /\//
      @info[:key] = convert_to_key(project)
      @info[:path] = File.join(@app_root, project)

      get_values(@info[:key])

      get_project
    else
      sync_all(project)
    end
  end

  if @projects.empty?
    if @cwd.eql? @app_root
      @sync_list.each { |p| sync_all(p) }
    else
      key = @cwd.split('/')
      key.shift(@app_root.split('/').count)

      sync_all(convert_to_key(key))
    end
  end
end

#sync_all(project) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/popo/sync.rb', line 41

def sync_all(project)
  if @sync_list.include? project
    children = @db.get_children(project)

    if children.empty?
      Error.say "No values for parent key \'#{project}\'."
    end

    children.each do |c|
      @info[:key] = [project, c].join('.')

      get_values(@info[:key])

      @info[:path] = File.join(@app_root, project.gsub('.','/'), c)

      get_project
    end
  else
    get_values(project)

    @info[:path] = File.join(@app_root, project.gsub('.','/'))

    get_project
  end
end