Class: Popo::Sync
Constant Summary
Constants included
from Constants
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
Instance Method Summary
collapse
Constructor Details
#initialize(popo_path, args, db) ⇒ Sync
Returns a new instance of Sync.
5
6
7
8
9
10
11
12
|
# File 'lib/popo/sync.rb', line 5
def initialize(popo_path, args, db)
@db = db
@sync_list = @db.get(POPO_DIR_KEY).split(',')
@popo_path = popo_path
@cwd = Dir.pwd
@projects = args
@info = {}
end
|
Instance Method Details
#convert_to_key(project) ⇒ Object
84
85
86
87
88
89
90
|
# File 'lib/popo/sync.rb', line 84
def convert_to_key(project)
if project.is_a? String
project.split('/').join('.')
else
project.join('.')
end
end
|
#get_values(key) ⇒ Object
78
79
80
81
82
|
# File 'lib/popo/sync.rb', line 78
def get_values(key)
POPO_KEY_VALUES.each do |v|
@info[v] = @db.get("#{key}.#{v}")
end
end
|
#sync ⇒ Object
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/popo/sync.rb', line 14
def sync
@projects.each do |project|
if project =~ /\//
@info['key'] = convert_to_key(project)
@info['path'] = File.join(@popo_path, project)
get_values(@info['key'])
get_project
else
sync_all(project)
end
end
if @projects.empty?
if @cwd.eql? @popo_path
@sync_list.each { |p| sync_all(p) }
else
project = @cwd.split('/') - @popo_path.split('/')
sync_all(convert_to_key(project))
end
end
end
|
#sync_all(project) ⇒ Object
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/popo/sync.rb', line 39
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(@popo_path, project.gsub('.','/'), c)
get_project
end
else
get_values(project)
@info['path'] = File.join(@popo_path, project.gsub('.','/'))
get_project
end
end
|