lita 4.4.2 → 4.4.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/lita/adapter.rb +1 -1
- data/lib/lita/robot.rb +37 -13
- data/lib/lita/version.rb +1 -1
- data/spec/lita/robot_spec.rb +52 -14
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 60f8a5c4baff97cb21c6bda0e37416b919747443
|
4
|
+
data.tar.gz: 2ecdd16eb4c246c566178a31f4cfc277e0794282
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1f9d6e452648e187da436d3b9fbb248ff90243abc47ac671340df664f42b4c12c7d7fb832f169583cb485dd4adb44b554a79f4751f6ba011b6be6ed22fdc35d0
|
7
|
+
data.tar.gz: 55d2096400b2dca088b16b40f07ae0888ed30ec98ad9dc6e873c5a2b7a23132b7b16c8649a3b61c49a1a0a6c9009c830bc0e7b5ce6f7c589aeef37c0b105eb57
|
data/lib/lita/adapter.rb
CHANGED
@@ -82,7 +82,7 @@ module Lita
|
|
82
82
|
# @!method roster(room)
|
83
83
|
# Get a list of users that are online in the given room.
|
84
84
|
# @param room [Lita::Room] The room to return a roster for.
|
85
|
-
# @return [Array<Lita::
|
85
|
+
# @return [Array<Lita::User>] An array of users.
|
86
86
|
# @abstract This should be implemented by the adapter.
|
87
87
|
# @since 4.4.0
|
88
88
|
|
data/lib/lita/robot.rb
CHANGED
@@ -80,21 +80,40 @@ module Lita
|
|
80
80
|
end
|
81
81
|
|
82
82
|
# Makes the robot join a room with the specified ID.
|
83
|
-
# @param
|
83
|
+
# @param room [Room, String] The room to join, as a {Lita::Room} object or a string identifier.
|
84
84
|
# @return [void]
|
85
85
|
# @since 3.0.0
|
86
|
-
def join(
|
87
|
-
|
88
|
-
|
86
|
+
def join(room)
|
87
|
+
room_object = find_room(room)
|
88
|
+
|
89
|
+
if room_object
|
90
|
+
Lita.redis.sadd("persisted_rooms", room_object.id)
|
91
|
+
adapter.join(room_object.id)
|
92
|
+
else
|
93
|
+
adapter.join(room)
|
94
|
+
end
|
89
95
|
end
|
90
96
|
|
91
97
|
# Makes the robot part from the room with the specified ID.
|
92
|
-
# @param
|
98
|
+
# @param room [Room, String] The room to leave, as a {Lita::Room} object or a string identifier.
|
93
99
|
# @return [void]
|
94
100
|
# @since 3.0.0
|
95
|
-
def part(
|
96
|
-
|
97
|
-
|
101
|
+
def part(room)
|
102
|
+
room_object = find_room(room)
|
103
|
+
|
104
|
+
if room_object
|
105
|
+
Lita.redis.srem("persisted_rooms", room_object.id)
|
106
|
+
adapter.part(room_object.id)
|
107
|
+
else
|
108
|
+
adapter.part(room)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
# A list of room IDs the robot should join on boot.
|
113
|
+
# @return [Array<String>] An array of room IDs.
|
114
|
+
# @since 4.4.2
|
115
|
+
def persisted_rooms
|
116
|
+
Lita.redis.smembers("persisted_rooms").sort
|
98
117
|
end
|
99
118
|
|
100
119
|
# Sends one or more messages to a user or room.
|
@@ -162,11 +181,6 @@ module Lita
|
|
162
181
|
end
|
163
182
|
end
|
164
183
|
|
165
|
-
# A list of room IDs the robot should join.
|
166
|
-
def persisted_rooms
|
167
|
-
Lita.redis.smembers("persisted_rooms").sort
|
168
|
-
end
|
169
|
-
|
170
184
|
private
|
171
185
|
|
172
186
|
# Loads and caches the adapter on first access.
|
@@ -174,6 +188,16 @@ module Lita
|
|
174
188
|
@adapter ||= load_adapter
|
175
189
|
end
|
176
190
|
|
191
|
+
# Ensure the argument is a Lita::Room.
|
192
|
+
def find_room(room_or_identifier)
|
193
|
+
case room_or_identifier
|
194
|
+
when Room
|
195
|
+
room_or_identifier
|
196
|
+
else
|
197
|
+
Room.fuzzy_find(room_or_identifier)
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
177
201
|
# Loads the selected adapter.
|
178
202
|
def load_adapter
|
179
203
|
adapter_name = config.robot.adapter
|
data/lib/lita/version.rb
CHANGED
data/spec/lita/robot_spec.rb
CHANGED
@@ -128,15 +128,34 @@ describe Lita::Robot, lita: true do
|
|
128
128
|
allow_any_instance_of(Lita::Adapters::Shell).to receive(:join)
|
129
129
|
end
|
130
130
|
|
131
|
-
|
132
|
-
|
133
|
-
|
131
|
+
context "when a Room object exists" do
|
132
|
+
let!(:room) { Lita::Room.create_or_update(1, name: "#lita.io") }
|
133
|
+
|
134
|
+
it "passes the room ID to the adapter when a string argument is provided" do
|
135
|
+
expect_any_instance_of(Lita::Adapters::Shell).to receive(:join).with("1")
|
136
|
+
|
137
|
+
subject.join("#lita.io")
|
138
|
+
end
|
139
|
+
|
140
|
+
it "passes the room ID to the adapter when a Room argument is provided" do
|
141
|
+
expect_any_instance_of(Lita::Adapters::Shell).to receive(:join).with("1")
|
142
|
+
|
143
|
+
subject.join(room)
|
144
|
+
end
|
145
|
+
|
146
|
+
it "adds the room ID to the persisted list" do
|
147
|
+
subject.join("#lita.io")
|
148
|
+
|
149
|
+
expect(subject.persisted_rooms).to include("1")
|
150
|
+
end
|
134
151
|
end
|
135
152
|
|
136
|
-
|
137
|
-
|
153
|
+
context "when no Room object exists" do
|
154
|
+
it "delegates to the adapter with the raw argument" do
|
155
|
+
expect_any_instance_of(Lita::Adapters::Shell).to receive(:join).with("#lita.io")
|
138
156
|
|
139
|
-
|
157
|
+
subject.join("#lita.io")
|
158
|
+
end
|
140
159
|
end
|
141
160
|
end
|
142
161
|
|
@@ -146,17 +165,36 @@ describe Lita::Robot, lita: true do
|
|
146
165
|
allow_any_instance_of(Lita::Adapters::Shell).to receive(:part)
|
147
166
|
end
|
148
167
|
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
168
|
+
context "when a Room object exists" do
|
169
|
+
let!(:room) { Lita::Room.create_or_update(1, name: "#lita.io") }
|
170
|
+
|
171
|
+
it "passes the room ID to the adapter when a string argument is provided" do
|
172
|
+
expect_any_instance_of(Lita::Adapters::Shell).to receive(:part).with("1")
|
173
|
+
|
174
|
+
subject.part("#lita.io")
|
175
|
+
end
|
176
|
+
|
177
|
+
it "passes the room ID to the adapter when a Room argument is provided" do
|
178
|
+
expect_any_instance_of(Lita::Adapters::Shell).to receive(:part).with("1")
|
179
|
+
|
180
|
+
subject.part(room)
|
181
|
+
end
|
182
|
+
|
183
|
+
it "removes the room ID from the persisted list" do
|
184
|
+
subject.join("#lita.io")
|
185
|
+
|
186
|
+
subject.part("#lita.io")
|
153
187
|
|
154
|
-
|
155
|
-
|
188
|
+
expect(subject.persisted_rooms).not_to include("1")
|
189
|
+
end
|
190
|
+
end
|
156
191
|
|
157
|
-
|
192
|
+
context "when no Room object exists" do
|
193
|
+
it "delegates to the adapter with the raw argument" do
|
194
|
+
expect_any_instance_of(Lita::Adapters::Shell).to receive(:part).with("#lita.io")
|
158
195
|
|
159
|
-
|
196
|
+
subject.part("#lita.io")
|
197
|
+
end
|
160
198
|
end
|
161
199
|
end
|
162
200
|
|