Class: AsProject::ProjectArguments
- Inherits:
-
Hash
- Object
- Hash
- AsProject::ProjectArguments
- Defined in:
- lib/asproject_arguments.rb
Overview
ProjectArguments
Instance Attribute Summary collapse
-
#execution_dir ⇒ Object
Returns the value of attribute execution_dir.
-
#path_finder ⇒ Object
Returns the value of attribute path_finder.
-
#project_templates ⇒ Object
Returns the value of attribute project_templates.
-
#should_create ⇒ Object
Returns the value of attribute should_create.
Instance Method Summary collapse
- #clean_name(name) ⇒ Object
- #copy_to_home ⇒ Object
- #copy_to_project ⇒ Object
- #default_home_templates ⇒ Object
- #default_templates ⇒ Object
- #default_templates=(templates) ⇒ Object
- #force? ⇒ Boolean
-
#initialize ⇒ ProjectArguments
constructor
A new instance of ProjectArguments.
- #parse!(args) ⇒ Object
- #process_templates(str) ⇒ Object
- #project_name ⇒ Object
- #selected_templates ⇒ Object
- #selected_templates=(templates) ⇒ Object
- #verbose ⇒ Object
- #verify_templates(templates) ⇒ Object
Constructor Details
#initialize ⇒ ProjectArguments
Returns a new instance of ProjectArguments.
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/asproject_arguments.rb', line 12 def initialize self[:project_name] = '' self[:copy_to_project] = false self[:copy_to_home] = false self[:default_templates] = false self[:default_home_templates] = false self[:force] = false self[:should_create] = true self[:verbose] = true self[:selected_templates] = [] end |
Instance Attribute Details
#execution_dir ⇒ Object
Returns the value of attribute execution_dir.
7 8 9 |
# File 'lib/asproject_arguments.rb', line 7 def execution_dir @execution_dir end |
#path_finder ⇒ Object
Returns the value of attribute path_finder.
7 8 9 |
# File 'lib/asproject_arguments.rb', line 7 def path_finder @path_finder end |
#project_templates ⇒ Object
Returns the value of attribute project_templates.
7 8 9 |
# File 'lib/asproject_arguments.rb', line 7 def project_templates @project_templates end |
#should_create ⇒ Object
Returns the value of attribute should_create.
7 8 9 |
# File 'lib/asproject_arguments.rb', line 7 def should_create @should_create end |
Instance Method Details
#clean_name(name) ⇒ Object
174 175 176 177 178 179 |
# File 'lib/asproject_arguments.rb', line 174 def clean_name(name) if(name.index("/") || name.index(".")) raise ProjectError.new('Project Name must not contain slashes or dots') end return name end |
#copy_to_home ⇒ Object
205 206 207 |
# File 'lib/asproject_arguments.rb', line 205 def copy_to_home return self[:copy_to_home] end |
#copy_to_project ⇒ Object
209 210 211 |
# File 'lib/asproject_arguments.rb', line 209 def copy_to_project return self[:copy_to_project] end |
#default_home_templates ⇒ Object
201 202 203 |
# File 'lib/asproject_arguments.rb', line 201 def default_home_templates return self[:default_home_templates] end |
#default_templates ⇒ Object
197 198 199 |
# File 'lib/asproject_arguments.rb', line 197 def default_templates return self[:default_templates] end |
#default_templates=(templates) ⇒ Object
193 194 195 |
# File 'lib/asproject_arguments.rb', line 193 def default_templates=(templates) self[:default_templates] = templates end |
#force? ⇒ Boolean
217 218 219 |
# File 'lib/asproject_arguments.rb', line 217 def force? return self[:force] end |
#parse!(args) ⇒ Object
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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/asproject_arguments.rb', line 24 def parse!(args) if(@path_finder.nil?) raise ProjectError.new('ProjectArguments needs a path_finder in order to work properly') end opts = OptionParser.new do |opts| opts. = <<EOF Usage: #$0 [options] ProjectName Project templates are easily modified and extended, if the files and directories created aren't exactly what you want, use the -c or -C option and edit the templates in your current project or your home path. Using -c will place templates in: #{Dir.pwd}/(ProjectName)/config/templates Using -C will place templates in: #{@path_finder.user_asproject_home} (Changes will impact all projects that don't have local templates) Using -t requires one or more project templates. These values are passed in as a comma-delimited string. Available choices for this particular installation are: #{@project_templates.join(', ')} Templates will be used when found in the first folder of the following list: 1) ./{ProjectName}/config/templates 2) #{@path_finder.user_asproject_home}/templates 3) #{@path_finder.gem_asproject_home}/templates After you have created a project, you can use "asclass" to create Classes, Test Cases and Test Suites. (This utility should be in your path already, run "asclass -help" for more information...) Examples: 1) Simple Example: mkdir projects cd projects asproject MyProjectName cd MyProjectName/project asclass -s utils.MathUtil rake test rake 2) Specify Templates Example: mkdir projects cd projects asproject -t 'as2,asunit25,config,fdt' MyProjectName cd MyProjectName/project asclass -s utils.MathUtil rake test rake 3) Copy Templates to User Home Example: asproject -C 4) Copy Templates to Project Example: mkdir projects cd projects asproject MyProjectName cd MyProjectName/project asproject -c Options: EOF opts.on('-c', '--copy-templates', "Copy templates to {ProjectName}/config/templates") do self[:copy_to_project] = true end opts.on('-C', '--copy-templates-to-home', "Copy templates to this user account") do self[:copy_to_home] = true end # opts.on('-d', '--default-templates', "Set default templates for this project eg: 'mxml,fb2mxml,asunit'") do # self[:default_templates] = true # end # # opts.on('-D', '--default-templates-to-home', "Set the default templates for this user account") do # self[:default_home_templates] = true # end opts.on('-f', '--force', "Force creation - overwrite if necessary") do self[:force] = true end opts.on('-q', '--quiet', "Do not display created file names") do self[:verbose] = false end opts.on('-t', '--template(s) [STRING]', "Define which project template(s) to use.") do |str| # Handle space-delimited vs comma-delimited? Do I need to do this? self[:selected_templates] = process_templates(str) end opts.on_tail('-h', '--help', 'display this help and exit') do puts opts exit end if(args.length == 0) puts '' puts "[WARNING] Please enter a name for your new project, or use the 'c', 'C', 'd' or 'D' options" puts opts exit end end opts.parse!(args) if(self[:should_create]) while(args.size > 1) self[:selected_templates] << args.shift end self[:project_name] = clean_name(args.shift.to_s) else while(args.size > 0) self[:selected_templates] << args.shift end end if(self[:selected_templates].size == 0) self[:selected_templates] = self[:default_templates] end verify_templates(self[:selected_templates]) end |
#process_templates(str) ⇒ Object
150 151 152 153 154 155 156 157 |
# File 'lib/asproject_arguments.rb', line 150 def process_templates(str) str = str.split(', ').join(',') if(!str.index(' ').nil? && str.index(',').nil?) templates = str.split(' ') else templates = str.split(',') end end |
#project_name ⇒ Object
181 182 183 |
# File 'lib/asproject_arguments.rb', line 181 def project_name return self[:project_name] end |
#selected_templates ⇒ Object
189 190 191 |
# File 'lib/asproject_arguments.rb', line 189 def selected_templates return self[:selected_templates] end |
#selected_templates=(templates) ⇒ Object
185 186 187 |
# File 'lib/asproject_arguments.rb', line 185 def selected_templates=(templates) self[:selected_templates] = templates end |
#verbose ⇒ Object
213 214 215 |
# File 'lib/asproject_arguments.rb', line 213 def verbose return self[:verbose] end |
#verify_templates(templates) ⇒ Object
159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/asproject_arguments.rb', line 159 def verify_templates(templates) templates.each do |template| if(!@project_templates.index template) msg = <<EOF Template [#{template}] was not found! Please try again with one of the following available templates: #{@project_templates.join(', ')} EOF raise ProjectError.new(msg) end end end |