Class: AsProject::AsClassArguments

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

Overview

ProjectArguments

Constant Summary collapse

@@TEMPLATE_TYPE =
'asclass'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dir = nil) ⇒ AsClassArguments

Returns a new instance of AsClassArguments.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/asclass_arguments.rb', line 14

def initialize(dir=nil)
  if(dir.nil?)
    @execution_dir           = Dir.pwd
  else
    @execution_dir           = dir
  end
  @path_finder               = PathFinder.new(@execution_dir)
  @force                     = false
  @mxml                      = false
  @component                 = false
  @template                  = nil
  self[:name]                = nil
  self[:build_test_suites]   = false # -s == --build-test-suites
  self[:build_test_case]     = true # -n == --no-test-case ?
  self[:verbose]             = true

  @class_templates           = @path_finder.get_available_templates(@@TEMPLATE_TYPE)
end

Instance Attribute Details

#componentObject

Returns the value of attribute component.



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

def component
  @component
end

#display_objectObject

Returns the value of attribute display_object.



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

def display_object
  @display_object
end

#execution_dirObject

Returns the value of attribute execution_dir.



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

def execution_dir
  @execution_dir
end

#forceObject

Returns the value of attribute force.



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

def force
  @force
end

#mxmlObject

Returns the value of attribute mxml.



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

def mxml
  @mxml
end

Instance Method Details

#build_test_caseObject



154
155
156
# File 'lib/asclass_arguments.rb', line 154

def build_test_case
  return self[:build_test_case]
end

#build_test_suitesObject



158
159
160
# File 'lib/asclass_arguments.rb', line 158

def build_test_suites
  return self[:build_test_suites]
end

#force?Boolean

Returns:

  • (Boolean)


162
163
164
# File 'lib/asclass_arguments.rb', line 162

def force?
  return self[:force]
end

#nameObject



146
147
148
# File 'lib/asclass_arguments.rb', line 146

def name
  return self[:name]
end

#parse!(args) ⇒ Object



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
# File 'lib/asclass_arguments.rb', line 33

def parse!(args)
  opts = OptionParser.new do |opts|
    opts.banner = <<EOF

Usage: #$0 [options] packagename.ClassName

AsClass will automatically determine which template file to use based on the class name entered.
1) Names beginning with 'I' or ending with 'able' are assumed to be interfaces and use 'Interface.as'
2) Names ending with 'Test' are assumed to be test cases and use the 'TestCase.as' template
3) If the --mxml flag is set, the 'Component.mxml' template is used
4) If the --component flas is set, the 'Component.as' template is used
5) If none of the previous criteria are met, the 'Class.as' template is used

Classes will be placed in the ProjectPath/src directory.
Test cases and test suites will be placed in the ProjectPath/test directory.

Using -t requires a single template selection. The template is a folder name inside of the asclass folder.

Templates will be used when found in the first folder of the following list:
1) ./{ProjectName}/config/templates/asclass
2) #{@path_finder.user_asproject_home}/templates/asclass
3) #{@path_finder.gem_asproject_home}/templates/asclass

Examples:

1) Create a Class and TestCase

asclass utils.MathUtil

2) Create only a TestCase

asclass utils.MathUtilTest

3) Create an interface

asclass utils.IEnumerator
or
asclass utils.Enumerable

4) Rebuild Test Suites

asclass -s
or
asclass -s utils.MathUtil


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('-s', '--build-test-suites', "Build TestSuites in my test directory") do
      self[:build_test_suites] = true
    end

    opts.on('-t', '--template [STRING]', "Define which project template folder to use.") do |str|
      self[:template] = str
    end
  
    opts.on_tail('-h', '--help', 'display this help and exit') do
      puts opts
      exit
    end
  end
  opts.parse!(args)

  if(args.size > 0)
    self[:name] = args.shift.to_s
  end
end

#templateObject



142
143
144
# File 'lib/asclass_arguments.rb', line 142

def template
  return self[:template]
end

#template=(template) ⇒ Object



138
139
140
# File 'lib/asclass_arguments.rb', line 138

def template=(template)
  self[:template] = template
end

#verboseObject



150
151
152
# File 'lib/asclass_arguments.rb', line 150

def verbose
  return self[:verbose]
end

#verify_template(template) ⇒ Object



125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/asclass_arguments.rb', line 125

def verify_template(template)
  if(!@class_templates.index template)
    msg = <<EOF

Template [#{template}] was not found! 

Please try again with one of the following available templates:
#{@class_templates.join(', ')}
EOF
    raise ProjectError.new(msg)
  end
end