21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/tengine/job/category.rb', line 21
def update_for(base_dir)
root_dir = File.basename(base_dir)
dic_dir_base = File.dirname(base_dir)
root_jobnets = Tengine::Job::RootJobnetTemplate.all
root_jobnets.each do |root_jobnet|
dirs = File.dirname(root_jobnet.dsl_filepath || "").split('/') - ['.', '..']
dirs.unshift(root_dir)
last_category = nil
dic_dir = dic_dir_base
dirs.each do |dir|
caption = nil
dic_path = File.expand_path("dictionary.yml", dic_dir)
if File.exist?(dic_path)
hash = YAML.load_file(dic_path)
caption = hash[dir]
end
category = Tengine::Job::Category.find_or_create_by(
:name => dir,
:caption => caption || dir,
:parent_id => last_category ? last_category.id : nil)
dic_dir = File.join(dic_dir, dir)
last_category = category
end
if last_category
root_jobnet.category_id = last_category.id
root_jobnet.save!
end
end
end
|