Module: FlashSDK::FlashHelper

Included in:
ClassGenerator
Defined in:
flashsdk/lib/flashsdk/generators/flash_helper.rb

Overview

The FlashHelper is a module that can be included into any Sprout::Generator in order to provide support for many common features.

Examples:

An example of how to use this helper:

require 'flashsdk'

class BigFatGenerator < Sprout::Generator::Base
  include FlashSDK::FlashHelper

  ...
end

Instance Method Summary (collapse)

Instance Method Details

- (String) actionscript_file_to_class_name(file) (protected)

Transform a file name in the source or test path into a fully-qualified class name.

Parameters:

  • (File) file

    The path to a file on disk that is in the src or test folder.

Returns:

  • (String)

    The fully-qualified class name.



102
103
104
105
106
107
108
109
110
# File 'flashsdk/lib/flashsdk/generators/flash_helper.rb', line 102

def actionscript_file_to_class_name file
  name = file.dup
  name.gsub!(/^#{path}\//, '') if respond_to? :path
  name.gsub!(/^#{test}\//, '') if respond_to? :test
  name.gsub!(/^#{src}\//, '') if respond_to? :src
  name.gsub!(/.as$/, '')
  name.gsub!(/#{File::SEPARATOR}/, '.')
  return name
end

- (String) class_directory (protected)

The directory that contains the input class.

Returns:

  • (String)

    The directory that contains the input class.



114
115
116
117
118
119
120
121
# File 'flashsdk/lib/flashsdk/generators/flash_helper.rb', line 114

def class_directory
  parts = input_in_parts
  if parts.size > 1
    parts.pop
    return File.join src, *parts
  end
  return src
end

- (String) class_name (protected)

The fully-qualified class name provided on the command line at --input.

Returns:

  • (String)

    The fully-qualified class name provided on the command line at --input.



142
143
144
145
146
147
148
149
# File 'flashsdk/lib/flashsdk/generators/flash_helper.rb', line 142

def class_name
  parts = input_in_parts
  name = parts.pop.camel_case
  if(name.match(/Test$/))
    return name.gsub(/Test$/, '')
  end
  name
end

- (String) debug_swf_name (protected)

The class_name with '-debug.swf' appended.

Returns:

  • (String)

    The class_name with '-debug.swf' appended.



217
218
219
# File 'flashsdk/lib/flashsdk/generators/flash_helper.rb', line 217

def debug_swf_name
  "#{class_name}-debug.swf"
end

- (String) default_package_name (protected)

The package that provided on the command line at --package

Returns:

  • (String)

    The package that provided on the command line at --package



125
126
127
# File 'flashsdk/lib/flashsdk/generators/flash_helper.rb', line 125

def default_package_name
  remove_slashes package
end

- (String) deploy_swf_name (protected)

The class_name with '.swf' appended.

Returns:

  • (String)

    The class_name with '.swf' appended.



211
212
213
# File 'flashsdk/lib/flashsdk/generators/flash_helper.rb', line 211

def deploy_swf_name
  "#{class_name}.swf"
end

- (String) fully_qualified_class_name (protected)

The fully qualified class name version of whatever was input.

Returns:

  • (String)

    The fully qualified class name version of whatever was input.



193
194
195
# File 'flashsdk/lib/flashsdk/generators/flash_helper.rb', line 193

def fully_qualified_class_name
  remove_slashes remove_file_extensions(input)
end

- (Array<String>) input_in_parts(value = nil) (protected)

An Array of the provided string split on slahes or dots with the file extension removed.

Parameters:

  • (String) value (defaults to: nil)

    If no value is provided, will use --input instead.

Returns:

  • (Array<String>)

    An Array of the provided string split on slahes or dots with the file extension removed.



183
184
185
186
187
188
189
# File 'flashsdk/lib/flashsdk/generators/flash_helper.rb', line 183

def input_in_parts(value=nil)
  provided_input = value || input.dup
  provided_input.gsub! /^#{src}\//, '' if respond_to? :src
  provided_input = provided_input.split('/').join('.')

  remove_file_extensions(provided_input).split('.')
end

- (String) instance_name (protected)

Currently returns hard-coded 'instance'.

Returns:

  • (String)

    Currently returns hard-coded 'instance'.



171
172
173
174
175
176
177
# File 'flashsdk/lib/flashsdk/generators/flash_helper.rb', line 171

def instance_name
  # TODO: should uncapitalize class_name
  # (not the same as lowercase)
  # If the name is > 12 character, just
  # use 'instance' instead.
  'instance'
end

- (String) package_directory (protected)

The directory of the package based on the input string.

Returns:

  • (String)

    The directory of the package based on the input string.



24
25
26
27
28
29
# File 'flashsdk/lib/flashsdk/generators/flash_helper.rb', line 24

def package_directory
  if package.include?('/')
    remove_slashes package
  end
    split_package package
end

- (String) package_name (protected)

The package that was provided on the command line at --input

Returns:

  • (String)

    The package that was provided on the command line at --input



131
132
133
134
135
136
137
138
# File 'flashsdk/lib/flashsdk/generators/flash_helper.rb', line 131

def package_name
  parts = input_in_parts
  if parts.size > 1
    parts.pop
    return "#{parts.join('.')} "
  end
  return ""
end

- (String) project_name (protected)

The project name provided as --input on the command line. This is probably only helpful for project generators.

Returns:

  • (String)

    The project name provided as --input on the command line. This is probably only helpful for project generators.



165
166
167
# File 'flashsdk/lib/flashsdk/generators/flash_helper.rb', line 165

def project_name
  input.camel_case
end

- (String) remove_file_extensions(value) (protected)

A new String with common file extensions (.as, .mxml, .xml) removed from the provided value.

Parameters:

  • (String) value

    A string that may have a file extension.

Returns:

  • (String)

    A new String with common file extensions (.as, .mxml, .xml) removed from the provided value.



201
202
203
204
205
206
207
# File 'flashsdk/lib/flashsdk/generators/flash_helper.rb', line 201

def remove_file_extensions value
  value = value.dup
  value.gsub!(/\.as$/, '')
  value.gsub!(/\.mxml$/, '')
  value.gsub!(/\.xml$/, '')
  return value
end

- (String) remove_slashes(value) (protected)

The provided value with slashes replaced by dots.

Parameters:

  • (String) A

    directory or path on disk with slashes like ('/')

Returns:

  • (String)

    The provided value with slashes replaced by dots.



34
35
36
37
38
39
# File 'flashsdk/lib/flashsdk/generators/flash_helper.rb', line 34

def remove_slashes(value)
  if value.include?('/')
    value = value.split('/').join('.')
  end
  return value
end

- (Array<String>) split_package(value) (protected)

The provided package or class name split on the period. split on dots.

Parameters:

  • (String) value

    A fully-qualified package or class name (com.example.project.SomeClass)

Returns:

  • (Array<String>)

    The provided package or class name split on the period. split on dots.



45
46
47
# File 'flashsdk/lib/flashsdk/generators/flash_helper.rb', line 45

def split_package(value) 
  value.split('.')
end

- (Array<String>) test_case_classes (protected)

list of fully qualified class names.

Returns:

  • (Array<String>)

    Get the list of test_cases (which are files) as a



89
90
91
92
93
94
# File 'flashsdk/lib/flashsdk/generators/flash_helper.rb', line 89

def test_case_classes
  classes = self.test_cases.dup
  classes.collect do |file|
    actionscript_file_to_class_name(file)
  end
end

- (Array<File>) test_cases (protected)

using the test_glob as provided.

Returns:

  • (Array<File>)

    Collection of all test case files either assigned or found



75
76
77
# File 'flashsdk/lib/flashsdk/generators/flash_helper.rb', line 75

def test_cases
  @test_cases ||= Dir.glob(test_glob)
end

- (Array<String>) test_cases=(collection) (protected)

Collection of all test case files that were assigned or found.

Parameters:

  • (Array<String>) Set

    the collection of test cases as Files on disk.

Returns:

  • (Array<String>)

    Collection of all test case files that were assigned or found.



82
83
84
# File 'flashsdk/lib/flashsdk/generators/flash_helper.rb', line 82

def test_cases= collection
  @test_cases = collection
end

- (String) test_class_directory (protected)

The directory for test cases that are related to the class provided by input

Returns:

  • (String)

    The directory for test cases that are related to the class provided by input



51
52
53
54
55
56
57
58
# File 'flashsdk/lib/flashsdk/generators/flash_helper.rb', line 51

def test_class_directory
  parts = input_in_parts
  if parts.size > 1
    parts.pop
    return File.join test, *parts
  end
  return test
end

- (String) test_class_name (protected)

The fully-qualified test class name based on the --input argument provided on the command line.

Returns:

  • (String)

    The fully-qualified test class name based on the --input argument provided on the command line.



154
155
156
157
158
159
160
# File 'flashsdk/lib/flashsdk/generators/flash_helper.rb', line 154

def test_class_name
  source = class_name
  if(!source.match(/Test$/))
    return "#{source}Test"
  end
  source
end

- (String) test_glob (protected)

Glob that is used to search for test cases and build up the test suites.

Returns:

  • (String)

    Glob that is used to search for test cases and build up the test suites.



63
64
65
# File 'flashsdk/lib/flashsdk/generators/flash_helper.rb', line 63

def test_glob
  return @test_glob ||= File.join(path, test, '**', '?*Test.as')
end

- (String) test_glob=(glob) (protected)

The provided or default glob.

Returns:

  • (String)

    The provided or default glob.



68
69
70
# File 'flashsdk/lib/flashsdk/generators/flash_helper.rb', line 68

def test_glob= glob
  @test_glob = glob
end

- (String) test_runner_name (protected)

The class_name with 'Runner.swf' appended.

Returns:

  • (String)

    The class_name with 'Runner.swf' appended.



229
230
231
# File 'flashsdk/lib/flashsdk/generators/flash_helper.rb', line 229

def test_runner_name
  "#{class_name}Runner"
end

- (String) test_swf_name (protected)

The class_name with '-test.swf' appendend.

Returns:

  • (String)

    The class_name with '-test.swf' appendend.



223
224
225
# File 'flashsdk/lib/flashsdk/generators/flash_helper.rb', line 223

def test_swf_name
  "#{class_name}-test.swf"
end