class Object

Constants

APP_ENV

stores local copy of the application environment (‘production’, ‘test’, etc) so that appropriate values in config/database.yml are used

Public Instance Methods

compile_application(params = {}) click to toggle source

Compile the given Flex/AIR application The following options are supported:

:executable => 'mxmlc'
:application => nil
:destination => 'public/bin'
:opts => nil
:flex_root => 'app/flex'
# File lib/restfulx/tasks.rb, line 18
def compile_application(params = {})
  project_name, flex_project_name, command_controller_name, base_package, base_folder, 
    flex_root = extract_names()
  
  executable = params[:executable] || 'mxmlc'
  application = params[:application] || get_main_application
  destination = params[:destination] || 'public/bin'
  opts = params[:opts] || ''
  flex_root = params[:flex_root] || flex_root
  
  compiler = get_executable(executable)
  
  application = get_main_application unless application
  project_path = File.join(APP_ROOT, flex_root, application)
  target_project_path = project_path.sub(/.mxml$/, '.swf')
  target_project_air_descriptor = project_path.sub(/.mxml$/, '-app.xml')
    
  libs = Dir.glob(File.join(APP_ROOT, 'lib', '*.swc')).map {|lib| lib.gsub(' ', '\ ')}
    
  additional_compiler_args = 
    get_app_properties().elements["actionScriptProperties"].elements["compiler"].attributes["additionalCompilerArguments"]
  additional_compiler_args.gsub!("../locale/", "#{APP_ROOT}/app/locale/")
  
  cmd = "#{executable} #{opts} -library-path+=#{libs.join(',')} " << additional_compiler_args << " #{project_path.gsub(' ', '\ ')}"
  puts "Compiling #{project_path}"
  if system(cmd)
    FileUtils.makedirs File.join(APP_ROOT, destination)
    puts "Moving #{target_project_path} to " + File.join(APP_ROOT, destination)
    FileUtils.mv target_project_path, File.join(APP_ROOT, destination), :force => true
    if File.exist?(target_project_air_descriptor)
      descriptor = File.read(target_project_air_descriptor)
      descriptor_name = target_project_air_descriptor.split("/").last
      app_swf = target_project_path.split("/").last
      descriptor.gsub!("[This value will be overwritten by Flex Builder in the output app.xml]", 
        app_swf)

      File.open("#{APP_ROOT}/#{destination}/#{descriptor_name}", "w") do |file|
        file.print descriptor
      end
      puts "Created #{APP_ROOT}/#{destination}/#{descriptor_name} descriptor."
    end
    puts 'Done!'
  else
    puts "The application was not compiled. Check console for errors. " <<
      "It is possible that '(a)mxmlc' executable was not found or there are compilation errors."
  end
end
get_app_properties() click to toggle source
# File lib/restfulx/tasks.rb, line 82
def get_app_properties
  REXML::Document.new(File.open(File.join(APP_ROOT, ".actionScriptProperties")))
end
get_executable(executable) click to toggle source

Get appropriate executable based on platform

# File lib/restfulx/tasks.rb, line 87
def get_executable(executable)
  if RUBY_PLATFORM =~ /mswin32/
    executable << '.exe'
  end
  executable
end
get_main_application() click to toggle source

Find what the main application is based on .actionScriptProperties file

# File lib/restfulx/tasks.rb, line 78
def get_main_application
  get_app_properties().root.attributes['mainApplicationPath'].split("/").last
end
run_air_application(params = {}) click to toggle source
# File lib/restfulx/tasks.rb, line 66
def run_air_application(params = {})
  application = params[:application] || get_main_application
  descriptor = params[:descriptor] || application.sub(/.mxml$/, '-app.xml')
  destination = params[:destination] || 'bin-debug'
  
  puts "Running AIR application with descriptor: #{descriptor}"
  if !system("#{get_executable('adl')} #{destination}/#{descriptor}")
    puts "Could not run the application with descriptor: #{destination}/#{descriptor}. Check console for errors."
  end
end
stage_database(db_names, admin_password, db_user_name, db_password) click to toggle source

Performs MySQL database set-up based on the username and password provided. Also updates Rails config/database.yml file with database username and password

# File lib/restfulx/active_record_tasks.rb, line 39
def stage_database(db_names, admin_password, db_user_name, db_password)
  sql_command = ""
  
  db_names.each do |name|
    db_name = ActiveRecord::Base.configurations[name]['database']
    sql_command += "drop database if exists #{db_name}; " << 
      "create database #{db_name}; grant all privileges on #{db_name}.* " << 
      "to #{db_user_name}@localhost identified by \'#{db_password}\';"
    ActiveRecord::Base.configurations[name]['username'] = db_user_name
    ActiveRecord::Base.configurations[name]['password'] = db_password
  end

  if (!File.exist?("#{APP_ROOT}/tmp/stage.sql"))
    File.open("#{APP_ROOT}/tmp/stage.sql", "w") do |file|
      file.print sql_command
    end
  end

  # back up the original database.yml file just in case
  File.copy("#{APP_ROOT}/config/database.yml", 
    "#{APP_ROOT}/config/database.yml.sample") if !File.exist?("#{APP_ROOT}/config/database.yml.sample")
  
  dbconfig = File.read("#{APP_ROOT}/config/database.yml")
  dbconfig.gsub!(/username:.*/, "username: #{db_user_name}")
  dbconfig.gsub!(/password:.*/, "password: #{db_password}")
  
  File.open("#{APP_ROOT}/config/database.yml", "w") do |file|
    file.print dbconfig
  end

  if system %Q(mysql -h localhost -u root --password=#{admin_password} < tmp/stage.sql)
    puts "Updated config/database.yml and staged the database based on your settings"
    File.delete("tmp/stage.sql") if File.file?("tmp/stage.sql")
  else
    puts "Staging was not performed. Check console for errors. It is possible that 'mysql' executable was not found."
  end
end