Class: Manifest

Inherits:
Tool
  • Object
show all
Defined in:
lib/shed/manifest.rb

Overview

Scans a specified source tree for ActionScript and MXML files and for each one found creates a manifest entry. When complete writes the resulting manfiest file to disk.

Constant Summary

Constants inherited from Tool

Tool::INVALID_OPTS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Tool

#add_sigint_handler, #generated_at, #log, #puts, #to_disk, #valid_opts

Constructor Details

#initialize(opt, out = STDOUT) ⇒ Manifest

Returns a new instance of Manifest.



12
13
14
15
16
17
18
19
# File 'lib/shed/manifest.rb', line 12

def initialize(opt,out=STDOUT)
  super(opt,out)

  @filetypes = /\.(as|mxml|fxg)$/
  @filter = opt[:filter] || ''

  build
end

Instance Attribute Details

#componentsObject (readonly)

Returns the value of attribute components.



9
10
11
# File 'lib/shed/manifest.rb', line 9

def components
  @components
end

#xmlObject (readonly)

Returns the value of attribute xml.



9
10
11
# File 'lib/shed/manifest.rb', line 9

def xml
  @xml
end

Instance Method Details

#add(path, id) ⇒ Object

Generates a hash containing id and xml vales. The xml can be to be inserted into the manifest for the specified class.



25
26
27
28
29
30
31
# File 'lib/shed/manifest.rb', line 25

def add(path, id)
  log("Adding '#{path}'")

  cp = ProjectTools.import(path)

  { :key => id, :xml => "<component id=\"#{id}\" class=\"#{cp}\" />" }
end

#buildObject

Build the manifest file and save it to disk.



67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/shed/manifest.rb', line 67

def build
  @components = scan(@src)

  if @components.empty?
    puts "No ActionScript, MXML or FXG files found."
  else
    create_xml(@components)

    #Open/Create the manifest file and write the output to it.
    to_disk(xml)
  end
end

#create_xml(comps) ⇒ Object

Constructs the flex complier config file when given a list of paths to asdoc files.



84
85
86
87
88
# File 'lib/shed/manifest.rb', line 84

def create_xml(comps)
  @xml = "<?xml version='1.0'?>\n<componentPackage>\n"
  comps.each { |component| @xml << "\t#{component[:xml]}\n" }
  @xml << "</componentPackage>"
end

#process(list) ⇒ Object

Proccesses the list to remove duplicates, sort alphabetically and reject any items that do not match the filter.



58
59
60
61
62
# File 'lib/shed/manifest.rb', line 58

def process(list)
  list.uniq!
  list.sort! { |before,after| before[:xml] <=> after[:xml] }
  list.select { |element| element[:xml].match(@filter) }
end

#scan(dir) ⇒ Object

Search the provided path for as and mxml documents and return those found as a list.



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/shed/manifest.rb', line 37

def scan(dir)
  puts "Scanning '#{dir}' for as and mxml files..."

  found = []

  Search.find_all(@filetypes,dir,@excludes) do |path|
    ext = File.extname(path)
    name = File.basename(path, ext)

    found << add(path, name)
  end

  found = process(found) unless found.empty?

  found
end