lackie 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/lackie/javascript/surrender.js +41 -30
- data/lib/lackie/remote_control.rb +1 -1
- data/lib/lackie.rb +1 -1
- data/spec/lackie/remote_control_spec.rb +12 -1
- metadata +5 -5
@@ -1,65 +1,76 @@
|
|
1
1
|
Lackie = {
|
2
2
|
wip: false,
|
3
3
|
enabled: true,
|
4
|
-
|
5
|
-
|
4
|
+
baseUrl: "/lackie",
|
5
|
+
|
6
6
|
createXMLHttpRequest: function() {
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
try {
|
8
|
+
return new XMLHttpRequest();
|
9
|
+
} catch(e) {}
|
10
|
+
try {
|
11
|
+
return new ActiveXObject("Msxml2.XMLHTTP");
|
12
|
+
} catch(e) {}
|
13
|
+
throw new Error("XMLHttpRequest not supported");
|
10
14
|
},
|
11
|
-
|
15
|
+
|
12
16
|
yield: function() {
|
13
17
|
if (Lackie.wip || !Lackie.enabled) {
|
14
18
|
return;
|
15
19
|
}
|
16
20
|
var xhReq = Lackie.createXMLHttpRequest();
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
21
|
+
function readyStateChange() {
|
22
|
+
if (xhReq.readyState != 4 || xhReq.status == 404) {
|
23
|
+
return;
|
24
|
+
}
|
25
|
+
Lackie.wip = true;
|
26
|
+
try {
|
27
|
+
Lackie.execute(xhReq.responseText);
|
28
|
+
}
|
29
|
+
finally {
|
30
|
+
try {
|
31
|
+
xhReq.destroy();
|
32
|
+
xhReq = null;
|
33
|
+
} catch(e) {}
|
34
|
+
}
|
35
|
+
}
|
36
|
+
xhReq.open("GET", Lackie.url("/yield"), true);
|
37
|
+
xhReq.onreadystatechange = readyStateChange;
|
38
|
+
xhReq.send(null);
|
33
39
|
},
|
34
|
-
|
40
|
+
|
35
41
|
result: function(value) {
|
36
42
|
var xhReq = Lackie.createXMLHttpRequest();
|
37
43
|
var params = JSON.stringify(value);
|
38
|
-
|
39
|
-
|
44
|
+
xhReq.open("POST", Lackie.url("/result"), true);
|
45
|
+
xhReq.setRequestHeader("Content-type", "application/json");
|
40
46
|
xhReq.setRequestHeader("Content-length", params.length);
|
41
47
|
xhReq.setRequestHeader("Connection", "close");
|
42
|
-
|
43
|
-
|
48
|
+
xhReq.send(params);
|
49
|
+
Lackie.wip = false;
|
44
50
|
},
|
45
|
-
|
51
|
+
|
46
52
|
execute: function(command) {
|
47
53
|
var result;
|
48
54
|
try {
|
49
55
|
result = { 'value': eval(command) };
|
50
56
|
}
|
51
|
-
catch
|
57
|
+
catch(e) {
|
52
58
|
result = { 'error': e.toString() };
|
53
59
|
}
|
54
60
|
Lackie.result(result);
|
55
61
|
},
|
56
|
-
|
62
|
+
|
57
63
|
log: function(message) {
|
58
64
|
var logElement = document.getElementById("LackieLog");
|
59
65
|
if (logElement) {
|
60
66
|
logElement.innerHTML += '<div class="message">' + message + '</div>';
|
61
67
|
}
|
62
68
|
return message;
|
69
|
+
},
|
70
|
+
|
71
|
+
url: function(path) {
|
72
|
+
var now = new Date();
|
73
|
+
return Lackie.baseUrl + path + '?' + now.getTime().toString();
|
63
74
|
}
|
64
75
|
}
|
65
76
|
|
data/lib/lackie.rb
CHANGED
@@ -4,6 +4,7 @@ require 'lackie/javascript'
|
|
4
4
|
module Lackie
|
5
5
|
describe RemoteControl do
|
6
6
|
before(:each) do
|
7
|
+
Time.stub!(:now).and_return(mock("now", :to_i => "cachebust"))
|
7
8
|
@poller = Poller.new(:sleeper => mock("sleeper", :sleep => true))
|
8
9
|
Poller.stub!(:new).and_return(@poller)
|
9
10
|
@rc = RemoteControl.new("host", 555, @poller)
|
@@ -26,13 +27,23 @@ module Lackie
|
|
26
27
|
lambda { raise RestClient::ResourceNotFound },
|
27
28
|
lambda { mock("poll_response", :body => '{"value":"bar"}') }
|
28
29
|
]
|
29
|
-
RestClient.stub!(:get).with("http://host:555/lackie/result").and_return {
|
30
|
+
RestClient.stub!(:get).with("http://host:555/lackie/result?cachebust").and_return {
|
30
31
|
responses.shift.call
|
31
32
|
}
|
32
33
|
@rc.exec("foo").should == "bar"
|
33
34
|
responses.should be_empty
|
34
35
|
end
|
35
36
|
|
37
|
+
it "cache-busts calls to GET /lackie/result" do
|
38
|
+
now = mock("now")
|
39
|
+
Time.should_receive(:now).and_return(now)
|
40
|
+
now.should_receive(:to_i).and_return("letmego")
|
41
|
+
RestClient.should_receive(:get).with("http://host:555/lackie/result?letmego").and_return(
|
42
|
+
mock("response", :body => '{"value":"123"}')
|
43
|
+
)
|
44
|
+
@rc.exec("foo")
|
45
|
+
end
|
46
|
+
|
36
47
|
it "waits for a default number of seconds" do
|
37
48
|
@poller.should_receive(:await).with("result of command:\nfoo", {}).and_yield
|
38
49
|
@rc.exec("foo")
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lackie
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 29
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 3
|
10
|
+
version: 0.1.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Josh Chisholm
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-01-
|
18
|
+
date: 2011-01-12 00:00:00 +00:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -197,7 +197,7 @@ rubyforge_project:
|
|
197
197
|
rubygems_version: 1.4.1
|
198
198
|
signing_key:
|
199
199
|
specification_version: 3
|
200
|
-
summary: lackie-0.1.
|
200
|
+
summary: lackie-0.1.3
|
201
201
|
test_files:
|
202
202
|
- features/remote_control.feature
|
203
203
|
- features/step_definitions/lackie_steps.rb
|