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
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/dca/commands/area.rb', line 15
def create name, title, description, url
@name = name
@class_name = name.camelize
template 'area/analyzer.rb.erb', "lib/areas/#{name.downcase}/analyzer.rb"
template 'area/position.rb.erb', "lib/areas/#{name.downcase}/models/position.rb"
template 'area/page.rb.erb', "lib/areas/#{name.downcase}/models/page.rb"
template 'area/models.rb.erb', "lib/areas/#{name.downcase}/models.rb"
template 'area/area.rb.erb', "lib/areas/#{name.downcase}.rb"
template 'spec/analyzer_spec.rb.erb', "spec/areas/#{name.downcase}/analyzer_spec.rb"
template 'spec/spec_helper.rb.erb', "spec/areas/#{name.downcase}/spec_helper.rb"
empty_directory 'config'
area_file = 'config/areas.yml'
areas = {}
areas = YAML.load_file(area_file) if File.exist? area_file
area_hash = {'title' => title, 'description' => description, 'url' => url}
if areas.has_key? name
if areas[name] == area_hash
shell.say_status :identical, area_file, :blue
else
areas[name] = area_hash
shell.say_status :conflict, area_file, :red
if shell.file_collision(area_file) { areas.to_yaml }
open(area_file, 'w:utf-8') { |file| file.write areas.to_yaml }
shell.say_status :force, area_file, :yellow
end
end
else
status = areas.empty? ? :create : :update
areas[name] = area_hash
open(area_file, 'w:utf-8') { |file| file.write areas.to_yaml }
shell.say_status status, area_file, :green
end
end
|