Class: AsProject::ProjectArguments

Inherits:
Hash
  • Object
show all
Defined in:
lib/asproject_arguments.rb

Overview

ProjectArguments

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeProjectArguments

Returns a new instance of ProjectArguments.



12
13
14
15
16
17
18
19
20
21
22
23
# 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]        = []
  self[:template_type]             = nil
end

Instance Attribute Details

#execution_dirObject

Returns the value of attribute execution_dir.



7
8
9
# File 'lib/asproject_arguments.rb', line 7

def execution_dir
  @execution_dir
end

#path_finderObject

Returns the value of attribute path_finder.



7
8
9
# File 'lib/asproject_arguments.rb', line 7

def path_finder
  @path_finder
end

#project_templatesObject

Returns the value of attribute project_templates.



7
8
9
# File 'lib/asproject_arguments.rb', line 7

def project_templates
  @project_templates
end

#should_createObject

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



202
203
204
205
206
207
# File 'lib/asproject_arguments.rb', line 202

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_homeObject



233
234
235
# File 'lib/asproject_arguments.rb', line 233

def copy_to_home
  return self[:copy_to_home]
end

#copy_to_projectObject



237
238
239
# File 'lib/asproject_arguments.rb', line 237

def copy_to_project
  return self[:copy_to_project]
end

#default_home_templatesObject



229
230
231
# File 'lib/asproject_arguments.rb', line 229

def default_home_templates
  return self[:default_home_templates]
end

#default_templatesObject



225
226
227
# File 'lib/asproject_arguments.rb', line 225

def default_templates
  return self[:default_templates]
end

#default_templates=(templates) ⇒ Object



221
222
223
# File 'lib/asproject_arguments.rb', line 221

def default_templates=(templates)
  self[:default_templates] = templates
end

#force?Boolean

Returns:

  • (Boolean)


249
250
251
# File 'lib/asproject_arguments.rb', line 249

def force?
  return self[:force]
end

#get_templates_by_type(type) ⇒ Object



168
169
170
171
172
173
174
175
176
# File 'lib/asproject_arguments.rb', line 168

def get_templates_by_type(type)
  if(type == 'as2')
    return ['as2', 'asunit25', 'fdt']
  elsif(type == 'as3')
    return ['as3', 'asunit3', 'fb2as']
  elsif(type == 'mxml')
    return ['mxml', 'asunit3', 'fb2as']
  end
end

#parse!(args) ⇒ Object



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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'lib/asproject_arguments.rb', line 25

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.banner = <<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:

asproject MyProjectName
cd MyProjectName/project
asproject -c

5) Specify templates by type Example:

asproject -T as3 MyProjectName
cd MyProjectName/project
rake

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('-T', '--template-type [STRING]', "Define which template type to use (as2, as3 or mxml).") do |str|
      # Handle space-delimited vs comma-delimited? Do I need to do this?
      if(str != 'as2' && str != 'as3' && str != 'mxml')
        msg = 'Template type must be as2, as3 or mxml'
        raise ProjectError.new(msg)
      end
      self[:template_type] = 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[:template_type].nil?)
    self[:selected_templates] = get_templates_by_type(self[:template_type])
  end
  
  if(self[:selected_templates].size == 0)
    self[:selected_templates] = self[:default_templates]
  end
  verify_templates(self[:selected_templates])
end

#process_templates(str) ⇒ Object



178
179
180
181
182
183
184
185
# File 'lib/asproject_arguments.rb', line 178

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_nameObject



209
210
211
# File 'lib/asproject_arguments.rb', line 209

def project_name
  return self[:project_name]
end

#selected_templatesObject



217
218
219
# File 'lib/asproject_arguments.rb', line 217

def selected_templates
  return self[:selected_templates]
end

#selected_templates=(templates) ⇒ Object



213
214
215
# File 'lib/asproject_arguments.rb', line 213

def selected_templates=(templates)
  self[:selected_templates] = templates
end

#template_typeObject



241
242
243
# File 'lib/asproject_arguments.rb', line 241

def template_type
  return self[:template_type]
end

#verboseObject



245
246
247
# File 'lib/asproject_arguments.rb', line 245

def verbose
  return self[:verbose]
end

#verify_templates(templates) ⇒ Object



187
188
189
190
191
192
193
194
195
196
197
198
199
200
# File 'lib/asproject_arguments.rb', line 187

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