Class: Dyndoc::InteractiveClient

Inherits:
Object
  • Object
show all
Defined in:
lib/dyndoc/cli/interactive-client.rb

Constant Summary collapse

@@end_token =
"__[[END_TOKEN]]__"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cmd, tmpl_filename, addr = "127.0.0.1", reinit = [], port = 7777) ⇒ InteractiveClient

reinit is an array



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/dyndoc/cli/interactive-client.rb', line 12

def initialize(cmd,tmpl_filename,addr="127.0.0.1",reinit=[],port=7777)

	@addr,@port,@cmd,@tmpl_filename=addr,port,cmd,tmpl_filename
	##p [:tmpl_filename,@tmpl_filename,@cmd]
	## The layout needs to be reintailized for new dyndoc file but not for the layout (of course)!
	dyndoc_cmd="dyndoc"
	dyndoc_cmd += "_with_tag_tmpl" if reinit.include? :dyndoc_tag_tmpl
	dyndoc_cmd += "_with_libs_reinit" if reinit.include? :dyndoc_libs
	dyndoc_cmd += "_with_layout_reinit" if reinit.include? :dyndoc_layout

#p [:addr,@addr]
	Socket.tcp(@addr, @port) {|sock|
			msg='__send_cmd__[['+dyndoc_cmd+'|'+@tmpl_filename+']]__' + @cmd + @@end_token
			#p msg
				sock.print msg
			#sleep 1
				sock.close_write
				@result=sock.read
	}

	data=@result.split(@@end_token,-1)
	last=data.pop
	resCmd=decode_cmd(data.join(""))
	##p [:resCmd,resCmd]
	if resCmd and resCmd[:cmd] != "windows_platform"
		@content=resCmd[:content]
	end
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



7
8
9
# File 'lib/dyndoc/cli/interactive-client.rb', line 7

def content
  @content
end

Instance Method Details

#decode_cmd(res) ⇒ Object



41
42
43
44
45
# File 'lib/dyndoc/cli/interactive-client.rb', line 41

def decode_cmd(res)
  if res =~ /^__send_cmd__\[\[([a-zA-Z0-9_]*)\]\]__([\s\S]*)/m
  	return {cmd: $1, content: $2}
  end
end