Class: ProjectTools
- Inherits:
-
Object
- Object
- ProjectTools
- Defined in:
- lib/shed/project_tools.rb
Overview
A collection of utility methods to help working with ActionScript source.
Class Method Summary collapse
-
.common_src_dirs ⇒ Object
Returns an array of directory names that are commonly used as the root directory for source files.
-
.flex_file_regx ⇒ Object
Regular expression to match files we expect to find in a ActionScript/Flex project.
-
.import(path) ⇒ Object
Takes a file path and converts it to a import path using conventionally named source folders as the root marker.
-
.package(path) ⇒ Object
Takes a file path and converts it to a package path using conventionally named source folders as the root marker.
-
.remove_relative_prefix(path) ⇒ Object
Removes any relative prefixes found in the provided path.
-
.truncate_to_src(path) ⇒ Object
Takes a file path and truncates it to the last matching conventionally named source directory.
Class Method Details
.common_src_dirs ⇒ Object
Returns an array of directory names that are commonly used as the root directory for source files.
12 13 14 |
# File 'lib/shed/project_tools.rb', line 12 def self.common_src_dirs ['src','source','test','lib'] end |
.flex_file_regx ⇒ Object
Regular expression to match files we expect to find in a ActionScript/Flex project.
56 57 58 |
# File 'lib/shed/project_tools.rb', line 56 def self.flex_file_regx /\.(as|mxml|asdoc)$/ end |
.import(path) ⇒ Object
Takes a file path and converts it to a import path using conventionally named source folders as the root marker.
48 49 50 |
# File 'lib/shed/project_tools.rb', line 48 def self.import(path) truncate_to_src(path).gsub('/','.').sub(flex_file_regx,'') end |
.package(path) ⇒ Object
Takes a file path and converts it to a package path using conventionally named source folders as the root marker.
38 39 40 41 42 |
# File 'lib/shed/project_tools.rb', line 38 def self.package(path) path = remove_relative_prefix(path) path = File.dirname(path) if path =~ flex_file_regx truncate_to_src(path).gsub('/','.') end |
.remove_relative_prefix(path) ⇒ Object
Removes any relative prefixes found in the provided path.
30 31 32 |
# File 'lib/shed/project_tools.rb', line 30 def self.remove_relative_prefix(path) path.sub(/^\W+\b/, '') end |
.truncate_to_src(path) ⇒ Object
Takes a file path and truncates it to the last matching conventionally named source directory.
20 21 22 23 24 25 |
# File 'lib/shed/project_tools.rb', line 20 def self.truncate_to_src(path) common_src_dirs.each do |remove| path = path.gsub(/^.*\b#{remove}\b(\/|$)/, ''); end path end |