Sha256: 34d0a9c3054b805bbb63b0b4e9e27493ce311a60c6c6a1456da3333ed0652008

Contents?: true

Size: 682 Bytes

Versions: 1

Compression:

Stored size: 682 Bytes

Contents

class CommandInterfaceHandler
  def run_command(cld, command, args)

    cr = CloudThrift::CloudResponse.new
    cr.name = cld.name
    cr.command = command
    resp = begin
      the_cloud = clouds[cld.name]
      the_cloud ? the_cloud.send(command.to_sym, *args) : "Cloud not found: #{cld.name}"
    rescue Exception => e
      cr.response = "Error: #{e.inspect}"
    end
    
    cr.response = format_response(resp)

    return cr
  end
  
  private
  
  def format_response(resp)
    case resp
    when Array
      resp.join(",")
    when Hash
      resp.map {|k,v| "#{k}:#{format_response(v.empty? ? "null" : v)}" }
    else
      [resp]
    end.map {|ele| ele.to_s }
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
auser-poolparty-1.3.0 lib/proto/command_interface_handler.rb