notepadqq_api 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.
- checksums.yaml +4 -4
- data/lib/notepadqq_api/stubs.rb +4 -2
- data/lib/notepadqq_api.rb +29 -0
- data/test/test_stubs.rb +52 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e092a63573088f2db1e41de45d9ec066bd1121c5
|
4
|
+
data.tar.gz: b3fb8067ef1b9c5a9dccd9bdba4bf4c91ddcbf7e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8fb3048fecd2eff830a0fff6bc7f842d2d0d098a22f7cfccb805646dd1fe5f7f10b07fa3a59b27837ec53f47bad655ab1a202cf21b7f153d395d234f085a7821
|
7
|
+
data.tar.gz: 1cd22f92840a3a695063f6ad74247722e419693eb380e1b3af2e560386918434a2c5733c413606d1e982f01f626e8c4c8af0fe709ac9db84d4b1c5328efbc569
|
data/lib/notepadqq_api/stubs.rb
CHANGED
@@ -17,12 +17,14 @@ class NotepadqqApi
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def ==(other)
|
20
|
-
other.class <= Stub &&
|
20
|
+
other.class <= Stub &&
|
21
|
+
id == other.id &&
|
22
|
+
messageInterpreter == other.messageInterpreter
|
21
23
|
end
|
22
24
|
|
23
25
|
protected
|
24
26
|
|
25
|
-
attr_reader :id
|
27
|
+
attr_reader :id, :messageInterpreter
|
26
28
|
|
27
29
|
end
|
28
30
|
|
data/lib/notepadqq_api.rb
CHANGED
@@ -29,6 +29,35 @@ class NotepadqqApi
|
|
29
29
|
|
30
30
|
end
|
31
31
|
|
32
|
+
# Execute a block for every new window.
|
33
|
+
# This is preferable to the "newWindow" event of Notepadqq, because it could
|
34
|
+
# happen that the extension isn't ready soon enough to receive the
|
35
|
+
# "newWindow" event for the first Window. This method, instead, ensures that
|
36
|
+
# the passed block will be called once and only once for each current or
|
37
|
+
# future window.
|
38
|
+
def onWindowCreated(&callback)
|
39
|
+
capturedWindows = []
|
40
|
+
|
41
|
+
# Invoke the callback for every currently open window
|
42
|
+
notepadqq.windows.each do |window|
|
43
|
+
unless capturedWindows.include? window
|
44
|
+
capturedWindows.push window
|
45
|
+
callback.call(window)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
# Each time a new window gets opened, invoke the callback.
|
50
|
+
# When Notepadqq is starting and initializing all the extensions,
|
51
|
+
# we might not be fast enough to receive this event: this is why
|
52
|
+
# we manually invoked the callback for every currently open window.
|
53
|
+
notepadqq.on(:newWindow) do |window|
|
54
|
+
unless capturedWindows.include? window
|
55
|
+
capturedWindows.push window
|
56
|
+
callback.call(window)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
32
61
|
# Returns an instance of Notepadqq
|
33
62
|
def notepadqq
|
34
63
|
@nqq ||= Stubs::Notepadqq.new(@messageInterpreter, NQQ_STUB_ID);
|
data/test/test_stubs.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'notepadqq_api/stubs'
|
3
|
+
|
4
|
+
class StubsTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def test_comparison
|
7
|
+
|
8
|
+
# Different class
|
9
|
+
|
10
|
+
assert_equal NotepadqqApi::Stubs::Notepadqq.new(nil, 7),
|
11
|
+
NotepadqqApi::Stubs::Stub.new(nil, 7)
|
12
|
+
|
13
|
+
assert_equal NotepadqqApi::Stubs::Stub.new(nil, 7),
|
14
|
+
NotepadqqApi::Stubs::Notepadqq.new(nil, 7)
|
15
|
+
|
16
|
+
assert_equal NotepadqqApi::Stubs::Stub.new(nil, 7),
|
17
|
+
NotepadqqApi::Stubs::Stub.new(nil, 7)
|
18
|
+
|
19
|
+
assert_equal NotepadqqApi::Stubs::Notepadqq.new(nil, 7),
|
20
|
+
NotepadqqApi::Stubs::Notepadqq.new(nil, 7)
|
21
|
+
|
22
|
+
# Different id
|
23
|
+
|
24
|
+
assert_not_equal NotepadqqApi::Stubs::Notepadqq.new(nil, 1),
|
25
|
+
NotepadqqApi::Stubs::Stub.new(nil, 2)
|
26
|
+
|
27
|
+
assert_not_equal NotepadqqApi::Stubs::Stub.new(nil, 1),
|
28
|
+
NotepadqqApi::Stubs::Notepadqq.new(nil, 2)
|
29
|
+
|
30
|
+
assert_not_equal NotepadqqApi::Stubs::Stub.new(nil, 1),
|
31
|
+
NotepadqqApi::Stubs::Stub.new(nil, 2)
|
32
|
+
|
33
|
+
assert_not_equal NotepadqqApi::Stubs::Notepadqq.new(nil, 1),
|
34
|
+
NotepadqqApi::Stubs::Notepadqq.new(nil, 2)
|
35
|
+
|
36
|
+
# Different channel
|
37
|
+
|
38
|
+
assert_not_equal NotepadqqApi::Stubs::Notepadqq.new("test", 7),
|
39
|
+
NotepadqqApi::Stubs::Stub.new(nil, 7)
|
40
|
+
|
41
|
+
assert_not_equal NotepadqqApi::Stubs::Stub.new("test", 7),
|
42
|
+
NotepadqqApi::Stubs::Notepadqq.new(nil, 7)
|
43
|
+
|
44
|
+
assert_not_equal NotepadqqApi::Stubs::Stub.new("test", 7),
|
45
|
+
NotepadqqApi::Stubs::Stub.new(nil, 7)
|
46
|
+
|
47
|
+
assert_not_equal NotepadqqApi::Stubs::Notepadqq.new("test", 7),
|
48
|
+
NotepadqqApi::Stubs::Notepadqq.new(nil, 7)
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: notepadqq_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniele Di Sarli
|
@@ -49,7 +49,8 @@ files:
|
|
49
49
|
- lib/notepadqq_api/message_interpreter.rb
|
50
50
|
- lib/notepadqq_api/stubs.rb
|
51
51
|
- test/test_message_interpreter.rb
|
52
|
-
|
52
|
+
- test/test_stubs.rb
|
53
|
+
homepage: https://rubygems.org/gems/notepadqq_api
|
53
54
|
licenses:
|
54
55
|
- MIT
|
55
56
|
metadata: {}
|