ruboty-toggle_switch 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/lib/ruboty/handlers/toggle_switch.rb +10 -3
- data/lib/ruboty/toggle_switch/storage.rb +12 -0
- data/lib/ruboty/toggle_switch/version.rb +1 -1
- 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: 580bf6e33db15308f664caee452443305ef7c62a
|
4
|
+
data.tar.gz: 45b97438c8fa479f90585533bf967e7906b242e4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 82aa4cd51bb856c6069176874809f718915018e7a629031d3b37335306ad40f0a49b1d7870af029ca0cdb8441c93062dfb81fec01122c9cc13e1ad3e1e33d803
|
7
|
+
data.tar.gz: 1bb763dfe7eff9d94f5b38c1784b2a85540d8feaa77f4236b7fde00c68a9a6249b943aef1c7c2f4bc96891ae9146066cbce4f6f96b4373c3d647e91f409f488c
|
data/.gitignore
CHANGED
@@ -5,18 +5,19 @@ module Ruboty
|
|
5
5
|
|
6
6
|
on(/toggle\s+(?<switch>.*)\s+(?<state>on|off)(?:\s+(?<note>.*))?\z/, name: 'toggle', description: 'Toggle switch')
|
7
7
|
on(/show\s+(?<switch>.*)\s+status\z/, name: 'show', description: 'Show switch status')
|
8
|
+
on(/list switches/, name: 'list', description: 'Show list of switches')
|
8
9
|
|
9
10
|
def toggle(message)
|
10
11
|
switch = message[:switch]
|
11
|
-
state
|
12
|
-
note
|
12
|
+
state = message[:state]
|
13
|
+
note = message[:note]
|
13
14
|
|
14
15
|
storage_state = storage[switch] && storage[switch].state
|
15
16
|
|
16
17
|
if storage_state == state
|
17
18
|
message.reply("#{switch} is already #{state}.")
|
18
19
|
else
|
19
|
-
storage[switch] = {state: state, from: message.from_name, note: note}
|
20
|
+
storage[switch] = { state: state, from: message.from_name, note: note }
|
20
21
|
message.reply("#{switch} is now #{state}.")
|
21
22
|
end
|
22
23
|
end
|
@@ -35,6 +36,12 @@ module Ruboty
|
|
35
36
|
end
|
36
37
|
end
|
37
38
|
|
39
|
+
def list(message)
|
40
|
+
storage.each do |key, record|
|
41
|
+
message.reply("- #{key} is #{record.state}.")
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
38
45
|
private
|
39
46
|
|
40
47
|
def storage
|
@@ -1,6 +1,8 @@
|
|
1
1
|
module Ruboty
|
2
2
|
module ToggleSwitch
|
3
3
|
class Storage
|
4
|
+
include Enumerable
|
5
|
+
|
4
6
|
Record = Struct.new(:state, :from, :at, :note)
|
5
7
|
|
6
8
|
NAMESPACE = 'ruboty-toggle_switch-storage'
|
@@ -25,6 +27,16 @@ module Ruboty
|
|
25
27
|
state_for(key) == 'off'
|
26
28
|
end
|
27
29
|
|
30
|
+
def each
|
31
|
+
records.each do |entry|
|
32
|
+
yield(*entry)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def size
|
37
|
+
records.size
|
38
|
+
end
|
39
|
+
|
28
40
|
private
|
29
41
|
|
30
42
|
def state_for(key)
|