Class: TemplateBuilder::App::New
- Inherits:
-
Command
- Object
- Command
- TemplateBuilder::App::New
show all
- Defined in:
- lib/template_builder/app/new.rb
Instance Attribute Summary
Attributes inherited from Command
#config, #stderr, #stdout
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Command
#ask_for, #force, inherited, #initialize, #name, #priority, #run_framework, #special_case_data_mapper, standard_options, #standard_options, #standard_parameters, standard_parameters, #verbose?
Class Method Details
.initialize_new ⇒ Object
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
# File 'lib/template_builder/app/new.rb', line 5
def self.initialize_new
synopsis 'template_builder new [name] [parameter type parameter type] [options]'
summary 'create a new template for your rails application.'
description <<-__
create a new template for your rails application. You can add a lot
of option as the database, the javascript framework etc ..
__
FileAnalyzer.all_parameters.each {|item|
parameter(standard_parameters[item])
}
option(standard_options[:verbose])
option(standard_options[:force])
end
|
Instance Method Details
#announce ⇒ Object
49
50
51
52
53
54
55
56
|
# File 'lib/template_builder/app/new.rb', line 49
def announce
complete_name = name.split("/")
file = complete_name.last
output_dir = complete_name[0..complete_name.length-2]
msg = "Created '#{file}'"
msg << " in directory '#{output_dir}'" if name.to_s != output_dir.to_s
stdout.puts msg
end
|
#parse(args) ⇒ Object
40
41
42
43
44
45
46
47
|
# File 'lib/template_builder/app/new.rb', line 40
def parse( args )
opts = super args
config[:name] = args.empty? ? nil : args.join('_')
if name.nil?
stdout.puts opts
exit 1
end
end
|
#run ⇒ Object
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/template_builder/app/new.rb', line 22
def run
raise Error, "File #{name} already exists." if !force and test ?e, name
file_manager = FileManager.new(
:file => name,
:stdout => stdout,
:stderr => stderr,
:verbose => verbose?
)
announce
sorted_param = @config_param.sort{|a,b| a[1].priority <=> b[1].priority }.map
sorted_param.each{ |k,v| ask_for k unless v.name }
file_manager.start_file sorted_param
sorted_param.each{ |k,v| run_framework file_manager, :type=>k, :name=>v.name unless v.name == "none"}
file_manager.end_file name, @command
end
|