class Concrete

Takes an ActionScript 3 Interface file and generates a concrete implementation from it.

Public Class Methods

new(opt,out=STDOUT) click to toggle source
Calls superclass method Tool::new
# File lib/shed/concrete.rb, line 8
def initialize(opt,out=STDOUT)
  super(opt,out)

  @interface = opt[:interface]

  do_exit unless valid_opts

  create_mixer(opt[:type])
  generate(File.new(@interface).read)
end

Public Instance Methods

generate(file) click to toggle source

Parse the Interface and outputs the concrete document.

# File lib/shed/concrete.rb, line 29
def generate(file)
  @parser = Interface.new(file) rescue do_exit
  output
end
valid_opts() click to toggle source

Valid if an Interface has been supplied in the options.

# File lib/shed/concrete.rb, line 22
def valid_opts
  File.exist?(@interface) rescue false
end

Private Instance Methods

accessors() click to toggle source

Generate the accessor block.

# File lib/shed/concrete.rb, line 65
def accessors
  decs = ""
  @parser.properties.each_pair { |name,property|
    type = property[:type]

    decs << @mixer.get(name,type) if property[:gets]
    decs << @mixer.set(name,type) if property[:sets]
  }
  decs
end
create_mixer(type) click to toggle source

Create the mixing tool which determines the output format.

# File lib/shed/concrete.rb, line 46
def create_mixer(type)
  mixers = { 'imp' => JustImplement,
             'class' => ActionScriptClass,
             'mock4as' => Mock4AS }

  @mixer = mixers[type].new
  @mixer
end
do_exit() click to toggle source

Log an error message and raise exit.

Calls superclass method Tool#do_exit
# File lib/shed/concrete.rb, line 97
def do_exit
  super "The specified interface file does not exist, or is not an Interface."
end
foot() click to toggle source

Generate the file footer.

# File lib/shed/concrete.rb, line 90
def foot
  @mixer.foot
end
head() click to toggle source

Generate the file header.

# File lib/shed/concrete.rb, line 58
def head
  @mixer.head(@parser.class_name,@parser.name)
end
methods() click to toggle source

Generate the method block.

# File lib/shed/concrete.rb, line 79
def methods
  decs = ""
  @parser.methods.each_pair { |name,method|
    decs << @mixer.method(name, method[:arguments], method[:return])
  }
  decs
end
output() click to toggle source

Output the constructed document.

# File lib/shed/concrete.rb, line 39
def output
  puts head + accessors + methods + foot
end