mobb 0.3.0 → 0.3.1
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/examples/plugin.rb +33 -0
- data/lib/mobb/base.rb +42 -18
- data/lib/mobb/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 749131cf75ad400bf376e82f587cf2c51812255091fe617d015a3310e2c73758
|
4
|
+
data.tar.gz: a4f1869ab602a310a36dea7a501211fe598e85b42c264989ae2b20e19b411e70
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d253c8903cb253552a9e8821cc565a39647d51e0d229f21bc83c3ef117a9916b6eef3c2dcaed658556661a8908c852be8e09d6452b620cd8e3b2ab46526d1e0c
|
7
|
+
data.tar.gz: 164d570551220f9779646f01e19f88ae991c13a175d2f9ffcba91a4cb5a8460e8912436992ae71cf84ff639b0d0b182efc87a7981ac96c1e35a3bbde6fb67755
|
data/examples/plugin.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'mobb'
|
2
|
+
|
3
|
+
module ExampleHelpers
|
4
|
+
def greet(name)
|
5
|
+
"Hi #{name}, I'm #{settings.name}"
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
module ExampleExtensions
|
10
|
+
def to_yo(flag)
|
11
|
+
dest_condition(:to_yo) do |res|
|
12
|
+
res.last[:dest_channel] = 'bot_test'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class Application < Mobb::Base
|
18
|
+
helpers ExampleHelpers
|
19
|
+
register ExampleExtensions
|
20
|
+
|
21
|
+
set :name, 'deep'
|
22
|
+
set :service, 'slack'
|
23
|
+
|
24
|
+
on /Yo (.+)/ do |name|
|
25
|
+
greet(name)
|
26
|
+
end
|
27
|
+
|
28
|
+
every :minute, to_yo: true do
|
29
|
+
'Yo'
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
Application.run!
|
data/lib/mobb/base.rb
CHANGED
@@ -95,11 +95,11 @@ module Mobb
|
|
95
95
|
|
96
96
|
def handle_event(base = settings, passed_block = nil)
|
97
97
|
if responds = base.events[@env.event_type]
|
98
|
-
responds.each do |pattern, block,
|
99
|
-
process_event(pattern,
|
98
|
+
responds.each do |pattern, block, source_conditions, dest_conditions|
|
99
|
+
process_event(pattern, source_conditions) do |*args|
|
100
100
|
event_eval do
|
101
101
|
res = block[*args]
|
102
|
-
|
102
|
+
dest_conditions.inject(res) { |acc, c| c.bind(self).call(acc) }
|
103
103
|
end
|
104
104
|
end
|
105
105
|
end
|
@@ -146,8 +146,17 @@ module Mobb
|
|
146
146
|
|
147
147
|
def reset!
|
148
148
|
@events = {}
|
149
|
-
@
|
150
|
-
@
|
149
|
+
@source_conditions = []
|
150
|
+
@dest_conditions = []
|
151
|
+
@extensions = []
|
152
|
+
end
|
153
|
+
|
154
|
+
def extensions
|
155
|
+
if superclass.respond_to?(:extensions)
|
156
|
+
(@extensions + superclass.extensions).uniq
|
157
|
+
else
|
158
|
+
@extensions
|
159
|
+
end
|
151
160
|
end
|
152
161
|
|
153
162
|
def settings
|
@@ -157,12 +166,18 @@ module Mobb
|
|
157
166
|
def receive(pattern, options = {}, &block) event(:message, pattern, options, &block); end
|
158
167
|
alias :on :receive
|
159
168
|
|
160
|
-
def every(pattern, options = {}, &block) event(:ticker, pattern, options, &block); end
|
161
|
-
|
162
169
|
def cron(pattern, options = {}, &block) event(:ticker, pattern, options, &block); end
|
170
|
+
alias :every :cron
|
163
171
|
|
164
172
|
def event(type, pattern, options, &block)
|
165
|
-
|
173
|
+
signature = compile!(type, pattern, options, &block)
|
174
|
+
(@events[type] ||= []) << signature
|
175
|
+
invoke_hook(:event_added, type, pattern, block)
|
176
|
+
signature
|
177
|
+
end
|
178
|
+
|
179
|
+
def invoke_hook(name, *args)
|
180
|
+
extensions.each { |e| e.send(name, *args) if e.respond_to?(name) }
|
166
181
|
end
|
167
182
|
|
168
183
|
def compile!(type, pattern, options, &block)
|
@@ -176,13 +191,13 @@ module Mobb
|
|
176
191
|
compile_cron(pattern, at)
|
177
192
|
end
|
178
193
|
unbound_method = generate_method("#{type}", &block)
|
179
|
-
|
180
|
-
|
194
|
+
source_conditions, @source_conditions = @source_conditions, []
|
195
|
+
dest_conditions, @dest_conditions = @dest_conditions, []
|
181
196
|
wrapper = block.arity != 0 ?
|
182
197
|
proc { |instance, args| unbound_method.bind(instance).call(*args) } :
|
183
198
|
proc { |instance, args| unbound_method.bind(instance).call }
|
184
199
|
|
185
|
-
[ matcher, wrapper,
|
200
|
+
[ matcher, wrapper, source_conditions, dest_conditions ]
|
186
201
|
end
|
187
202
|
|
188
203
|
def compile(pattern, options) Matcher.new(pattern, options); end
|
@@ -207,6 +222,15 @@ module Mobb
|
|
207
222
|
include(*extensions) if extensions.any?
|
208
223
|
end
|
209
224
|
|
225
|
+
def register(*extensions, &block)
|
226
|
+
extensions << Module.new(&block) if block_given?
|
227
|
+
@extensions += extensions
|
228
|
+
extensions.each do |extension|
|
229
|
+
extend extension
|
230
|
+
extension.registered(self) if extension.respond_to?(:registered)
|
231
|
+
end
|
232
|
+
end
|
233
|
+
|
210
234
|
def development?; environment == :development; end
|
211
235
|
def production?; environment == :production; end
|
212
236
|
def test?; environment == :test; end
|
@@ -248,12 +272,12 @@ module Mobb
|
|
248
272
|
end
|
249
273
|
|
250
274
|
def condition(name = "#{caller.first[/`.*'/]} condition", &block)
|
251
|
-
@
|
275
|
+
@source_conditions << generate_method(name, &block)
|
252
276
|
end
|
253
|
-
alias :
|
277
|
+
alias :source_condition :condition
|
254
278
|
|
255
|
-
def
|
256
|
-
@
|
279
|
+
def dest_condition(name = "#{caller.first[/`.*'/]} condition", &block)
|
280
|
+
@dest_conditions << generate_method(name) do |res|
|
257
281
|
if String === res
|
258
282
|
res = [res, {}]
|
259
283
|
end
|
@@ -275,7 +299,7 @@ module Mobb
|
|
275
299
|
end
|
276
300
|
|
277
301
|
def dest_to(channel)
|
278
|
-
|
302
|
+
dest_condition do |res|
|
279
303
|
res.last[:dest_channel] = channel
|
280
304
|
end
|
281
305
|
end
|
@@ -402,7 +426,7 @@ module Mobb
|
|
402
426
|
end
|
403
427
|
end
|
404
428
|
|
405
|
-
module Delegator
|
429
|
+
module Delegator
|
406
430
|
def self.delegate(*methods)
|
407
431
|
methods.each do |method_name|
|
408
432
|
define_method(method_name) do |*args, &block|
|
@@ -415,7 +439,7 @@ module Mobb
|
|
415
439
|
|
416
440
|
delegate :receive, :on, :every, :cron,
|
417
441
|
:set, :enable, :disable, :clear,
|
418
|
-
:helpers
|
442
|
+
:helpers, :register
|
419
443
|
|
420
444
|
class << self
|
421
445
|
attr_accessor :target
|
data/lib/mobb/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mobb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kinoppyd
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-09-
|
11
|
+
date: 2018-09-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: repp
|
@@ -106,6 +106,7 @@ files:
|
|
106
106
|
- LICENSE.txt
|
107
107
|
- README.md
|
108
108
|
- Rakefile
|
109
|
+
- examples/plugin.rb
|
109
110
|
- examples/slack_bot.rb
|
110
111
|
- lib/mobb.rb
|
111
112
|
- lib/mobb/base.rb
|