hubotgf 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3081b3ac191abd7c00ec91e0d3f0f631ade1f3de
4
- data.tar.gz: 1e5f660fe4af80c44ca49dded3802c2d8ce3672e
3
+ metadata.gz: 36c084e387e5d2faf558ef7c501448b46762fdc9
4
+ data.tar.gz: 79b120d98354bb04b55a35e65265241905e570f9
5
5
  SHA512:
6
- metadata.gz: a503182580bf19c75a6a4e9a5119a556e43c7f7228367ef049ac626f7adf1b421a66273ba9a2cc58e2ee418f202e533984ef6f915a75af490ac1193a65a629d2
7
- data.tar.gz: 5b0fe56427428076505ea3f7ffceaec8a43a99bae25990c7d1fadaa13c61ef115d755d97709cc19bd6ecd328d6cab9ba170fee5c7cd94bceb751f0f075b07cd3
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 params[:command], { sender: params[:_sender], room: params[:_room] }
5
+ result = HubotGf::Worker.start(params[:command], params[:_sender], params[:_room])
6
6
  head (result ? :ok : :not_found)
7
7
  end
8
8
 
@@ -1,4 +1,3 @@
1
1
  HubotGf::Engine.routes.draw do
2
2
  resources :tasks, only: :create
3
- # post '/hubotgf/tasks', controller: 'hubot_gf/tasks', action: 'create'
4
3
  end
@@ -1,5 +1,7 @@
1
1
  require "hubotgf/engine"
2
2
  require "hubotgf/config"
3
+ require "hubotgf/command"
4
+ require "hubotgf/command_collection"
3
5
  require "hubotgf/worker"
4
6
  require "hubotgf/messenger"
5
7
 
@@ -0,0 +1,16 @@
1
+ module HubotGf
2
+ class Command
3
+
4
+ attr_accessor :regex, :_method, :text
5
+
6
+ def initialize(hash)
7
+ @regex = hash.keys.first
8
+ @_method = hash.values.first
9
+ end
10
+
11
+ def arguments
12
+ regex.match(text).captures
13
+ end
14
+
15
+ end
16
+ end
@@ -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
@@ -9,11 +9,7 @@ module HubotGf
9
9
  end
10
10
 
11
11
  def perform
12
- @perform || lambda do |worker, args, metadata = {}|
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
 
@@ -1,3 +1,3 @@
1
1
  module HubotGf
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -4,28 +4,47 @@ module HubotGf
4
4
  def self.included(base)
5
5
  @workers ||= []
6
6
  @workers << base
7
- base.extend ClassMethods
7
+ base.extend(ClassMethods)
8
8
  end
9
9
 
10
- def self.start(command, metadata = {})
11
- worker = @workers.find { |w| w.command =~ command }
10
+ def self.start(command, sender = nil, room = nil)
11
+ worker = @workers.find { |w| w.commands.include? command }
12
12
  if worker
13
- arguments = worker.command.match(command).captures
14
- HubotGf::Config.perform.call(worker, arguments, metadata)
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
- def gf
19
- HubotGf::Messenger.new
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 command=(command)
24
- @command = command
34
+ def self.extended(base)
35
+ attr_accessor :command
25
36
  end
26
37
 
27
- def command
28
- @command || ''
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.1
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-02 00:00:00.000000000 Z
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.6
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: