Sha256: 4de55a0363f88c50d54a53f08bd5b1d23551e80d5a435fe75f1c69291061a7c7

Contents?: true

Size: 1.07 KB

Versions: 2

Compression:

Stored size: 1.07 KB

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]
      if the_cloud
        if command.include?(".")
          command.split(".").inject([]) do |sum, cmd|
            if cmd.match(/\((.*)\)/)
              args = $1
              new_cmd = cmd.gsub(args, '').gsub(/\(\)/, '')
              sum = arr.send(new_cmd.to_sym, *args)
            else
              sum = arr.send(cmd)
            end
          end
        else
          the_cloud.send(command.to_sym, *args)
        end
      else
        "Cloud not found: #{cld.name}"
      end
    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

2 entries across 2 versions & 2 rubygems

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