Class: XRefreshServer::Client
- Inherits:
-
Object
- Object
- XRefreshServer::Client
- Defined in:
- lib/xrefresh-server/client.rb
Overview
client representation on server side
Instance Attribute Summary collapse
-
#agent ⇒ Object
Returns the value of attribute agent.
-
#dead ⇒ Object
Returns the value of attribute dead.
-
#id ⇒ Object
Returns the value of attribute id.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(id, socket) ⇒ Client
constructor
A new instance of Client.
- #name ⇒ Object
- #send(data) ⇒ Object
- #send_about(version, agent) ⇒ Object
- #send_do_refresh(root, name, type, date, time, files) ⇒ Object
Constructor Details
#initialize(id, socket) ⇒ Client
Returns a new instance of Client.
9 10 11 12 13 14 15 |
# File 'lib/xrefresh-server/client.rb', line 9 def initialize(id, socket) @id = id @socket = socket @dead = false @type = '?' @agent = '?' end |
Instance Attribute Details
#agent ⇒ Object
Returns the value of attribute agent.
7 8 9 |
# File 'lib/xrefresh-server/client.rb', line 7 def agent @agent end |
#dead ⇒ Object
Returns the value of attribute dead.
7 8 9 |
# File 'lib/xrefresh-server/client.rb', line 7 def dead @dead end |
#id ⇒ Object
Returns the value of attribute id.
7 8 9 |
# File 'lib/xrefresh-server/client.rb', line 7 def id @id end |
#type ⇒ Object
Returns the value of attribute type.
7 8 9 |
# File 'lib/xrefresh-server/client.rb', line 7 def type @type end |
Instance Method Details
#name ⇒ Object
17 18 19 |
# File 'lib/xrefresh-server/client.rb', line 17 def name green("#{@type}(#{@id})") end |
#send(data) ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/xrefresh-server/client.rb', line 21 def send(data) return if @dead begin @socket << data.to_json + XREFRESH_MESSAGE_SEPARATOR rescue OUT.puts "Client #{name} #{red("is dead")}" @dead = true end end |
#send_about(version, agent) ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/xrefresh-server/client.rb', line 31 def send_about(version, agent) send({ "command" => "AboutMe", "version" => version, "agent" => agent }) end |
#send_do_refresh(root, name, type, date, time, files) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/xrefresh-server/client.rb', line 39 def send_do_refresh(root, name, type, date, time, files) # read all CSS files and add them into response contents = {} files.each do |item| next unless item["path1"] =~ /\.css$/ path = File.join(root, item["path1"]) content = File.open(path).read contents[item["path1"]] = content end send({ "command" => "DoRefresh", "root" => root, "name" => name, "date" => date, "time" => time, "type" => type, "files" => files, "contents" => contents }) end |