hubotgf 0.0.1 → 0.0.2
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/app/controllers/hubotgf/tasks_controller.rb +1 -1
- data/config/routes.rb +0 -1
- data/lib/hubotgf.rb +2 -0
- data/lib/hubotgf/command.rb +16 -0
- data/lib/hubotgf/command_collection.rb +28 -0
- data/lib/hubotgf/config.rb +1 -6
- data/lib/hubotgf/version.rb +1 -1
- data/lib/hubotgf/worker.rb +30 -11
- metadata +5 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 36c084e387e5d2faf558ef7c501448b46762fdc9
|
4
|
+
data.tar.gz: 79b120d98354bb04b55a35e65265241905e570f9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6e3a6ee2b92a9a7008c42c06526ad09a0371d46ccf1584a949c240a3ca449bb5609b5502f9bdc39d4b2b1495534e4ccbc1421f9946320ce065b5291df7ff3949
|
7
|
+
data.tar.gz: d168f9858bfedb2e5e3b5f80d20a68b9fa6cf6cea940ceba34db9db4e4cab99c2fb56c3cb4cf039da6a9c974e39919a4d5525fa0df316195d9b4ce9d965955f9
|
@@ -2,7 +2,7 @@ module HubotGf
|
|
2
2
|
class TasksController < ActionController::Base
|
3
3
|
|
4
4
|
def create
|
5
|
-
result = HubotGf::Worker.start
|
5
|
+
result = HubotGf::Worker.start(params[:command], params[:_sender], params[:_room])
|
6
6
|
head (result ? :ok : :not_found)
|
7
7
|
end
|
8
8
|
|
data/config/routes.rb
CHANGED
data/lib/hubotgf.rb
CHANGED
@@ -0,0 +1,28 @@
|
|
1
|
+
module HubotGf
|
2
|
+
class CommandCollection
|
3
|
+
|
4
|
+
attr_accessor :regex, :method
|
5
|
+
|
6
|
+
def initialize(worker)
|
7
|
+
@commands = []
|
8
|
+
@worker = worker
|
9
|
+
end
|
10
|
+
|
11
|
+
def <<(hash)
|
12
|
+
@commands << Command.new(hash)
|
13
|
+
end
|
14
|
+
|
15
|
+
def include?(text)
|
16
|
+
!!match(text)
|
17
|
+
end
|
18
|
+
|
19
|
+
def match(text)
|
20
|
+
command = @commands.find { |cmd| cmd.regex =~ text }
|
21
|
+
if command
|
22
|
+
command.text = text
|
23
|
+
command
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
data/lib/hubotgf/config.rb
CHANGED
@@ -9,11 +9,7 @@ module HubotGf
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def perform
|
12
|
-
@perform
|
13
|
-
arity = worker.instance_method(:perform).arity
|
14
|
-
args << metadata[:sender] if arity > args.length
|
15
|
-
args << metadata[:room] if arity > args.length
|
16
|
-
|
12
|
+
@perform ||= lambda do |worker, args|
|
17
13
|
case performer
|
18
14
|
when :sidekiq
|
19
15
|
Sidekiq::Client.enqueue(worker, *args)
|
@@ -22,7 +18,6 @@ module HubotGf
|
|
22
18
|
else
|
23
19
|
worker.new.perform(*args)
|
24
20
|
end
|
25
|
-
|
26
21
|
end
|
27
22
|
end
|
28
23
|
|
data/lib/hubotgf/version.rb
CHANGED
data/lib/hubotgf/worker.rb
CHANGED
@@ -4,28 +4,47 @@ module HubotGf
|
|
4
4
|
def self.included(base)
|
5
5
|
@workers ||= []
|
6
6
|
@workers << base
|
7
|
-
base.extend
|
7
|
+
base.extend(ClassMethods)
|
8
8
|
end
|
9
9
|
|
10
|
-
def self.start(command,
|
11
|
-
worker = @workers.find { |w| w.
|
10
|
+
def self.start(command, sender = nil, room = nil)
|
11
|
+
worker = @workers.find { |w| w.commands.include? command }
|
12
12
|
if worker
|
13
|
-
|
14
|
-
|
13
|
+
command = worker.commands.match(command)
|
14
|
+
arguments = command.arguments.unshift(command._method, sender, room)
|
15
|
+
HubotGf::Config.perform.(worker, arguments)
|
15
16
|
end
|
16
17
|
end
|
17
18
|
|
18
|
-
|
19
|
-
|
19
|
+
# Sidekiq entry
|
20
|
+
def perform(method, sender, room, *args)
|
21
|
+
@sender, @room = sender, room
|
22
|
+
send method, *args
|
23
|
+
end
|
24
|
+
|
25
|
+
def reply(message)
|
26
|
+
HubotGf::Messenger.new.pm(@sender, message)
|
27
|
+
end
|
28
|
+
|
29
|
+
def rebroadcast(message)
|
30
|
+
HubotGf::Messenger.new.broadcast(@room, message)
|
20
31
|
end
|
21
32
|
|
22
33
|
module ClassMethods
|
23
|
-
def
|
24
|
-
|
34
|
+
def self.extended(base)
|
35
|
+
attr_accessor :command
|
25
36
|
end
|
26
37
|
|
27
|
-
def
|
28
|
-
@
|
38
|
+
def listen(hash = {})
|
39
|
+
@commands ||= CommandCollection.new(self)
|
40
|
+
@commands << hash
|
41
|
+
end
|
42
|
+
|
43
|
+
def commands; @commands; end
|
44
|
+
|
45
|
+
# Resque entry
|
46
|
+
def perform(*args)
|
47
|
+
new.perform(*args)
|
29
48
|
end
|
30
49
|
end
|
31
50
|
|
metadata
CHANGED
@@ -1,15 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hubotgf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Logan Serman
|
8
|
-
- Michael Eatherly
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2014-04-
|
11
|
+
date: 2014-04-07 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: rails
|
@@ -126,13 +125,14 @@ dependencies:
|
|
126
125
|
description: Rails sidekick for Hubot
|
127
126
|
email:
|
128
127
|
- loganserman@gmail.com
|
129
|
-
- meatherly@gmail.com
|
130
128
|
executables: []
|
131
129
|
extensions: []
|
132
130
|
extra_rdoc_files: []
|
133
131
|
files:
|
134
132
|
- app/controllers/hubotgf/tasks_controller.rb
|
135
133
|
- config/routes.rb
|
134
|
+
- lib/hubotgf/command.rb
|
135
|
+
- lib/hubotgf/command_collection.rb
|
136
136
|
- lib/hubotgf/config.rb
|
137
137
|
- lib/hubotgf/engine.rb
|
138
138
|
- lib/hubotgf/messenger.rb
|
@@ -160,9 +160,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
160
160
|
version: '0'
|
161
161
|
requirements: []
|
162
162
|
rubyforge_project:
|
163
|
-
rubygems_version: 2.0.
|
163
|
+
rubygems_version: 2.0.3
|
164
164
|
signing_key:
|
165
165
|
specification_version: 4
|
166
166
|
summary: Rails sidekick for Hubot
|
167
167
|
test_files: []
|
168
|
-
has_rdoc:
|