Class: PatternPark::FCSH

Inherits:
Object show all
Defined in:
lib/airake/fcsh.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ip = nil, port = nil) ⇒ FCSH

Returns a new instance of FCSH.



35
36
37
38
# File 'lib/airake/fcsh.rb', line 35

def initialize(ip = nil, port = nil)
  @ip = ip
  @port = port
end

Instance Attribute Details

#ipObject

Returns the value of attribute ip.



33
34
35
# File 'lib/airake/fcsh.rb', line 33

def ip
  @ip
end

#portObject

Returns the value of attribute port.



33
34
35
# File 'lib/airake/fcsh.rb', line 33

def port
  @port
end

Class Method Details

.new_from_rake(env, default_ip = "127.0.0.1", default_port = 20569) ⇒ Object



81
82
83
84
85
# File 'lib/airake/fcsh.rb', line 81

def self.new_from_rake(env, default_ip = "127.0.0.1", default_port = 20569)
  fcsh_ip = env["FCSH_IP"] || default_ip
  fcsh_port = (env["FCSH_PORT"] || default_port).to_i
  self.new(fcsh_ip, fcsh_port)
end

Instance Method Details

#execute(args) ⇒ Object

Raises:



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/airake/fcsh.rb', line 54

def execute(args)
  start_time = Time.now

  error_found = false
  warning_found = false
  begin
    @socket = TCPSocket.open(@ip, @port) do |s|
      puts ">> Opened connection to fcshd on #{@ip}:#{@port}"
      s.puts args
      s.close_write
      while line = s.gets
        break if line =~ /^\[PROMPT\]/
        error_found = true if line =~ /^\[FCSH ERROR\]/
        warning_found = true if line =~ /^\[FCSH WARNING\]/
        puts line             
      end
    end
  rescue StandardError => e
    raise FCSHConnectError.new("[FCSH] Unable to connect to FCSHD process")
  end

  raise FCSHCompileError.new("[ERROR] Compile error encountered") if error_found

  end_time = Time.now - start_time
  puts "[FCSH] Compilation complete in: #{end_time} seconds"
end

#stopObject



40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/airake/fcsh.rb', line 40

def stop
  begin
    @socket = TCPSocket.open(@ip, @port) do |s|
      s.puts 'SIGHUP'
      s.close_write
      while(line = s.gets)
        puts line
      end
    end
  rescue StandardError => e
    raise FCSHError.new("[FCSH ERROR] Was unable to connect to a running fcsh process for stopping")
  end
end