ellen 0.1.3 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/lib/ellen/actions/base.rb +11 -0
- data/lib/ellen/actions/help.rb +27 -0
- data/lib/ellen/actions/ping.rb +19 -0
- data/lib/ellen/adapters/shell.rb +2 -2
- data/lib/ellen/handlers/help.rb +2 -4
- data/lib/ellen/handlers/ping.rb +1 -1
- data/lib/ellen/message.rb +13 -1
- data/lib/ellen/robot.rb +1 -1
- data/lib/ellen/version.rb +1 -1
- data/lib/ellen.rb +3 -0
- data/spec/ellen/adapters/shell_spec.rb +1 -1
- data/spec/ellen/handlers/help_spec.rb +21 -2
- data/spec/ellen/handlers/ping_spec.rb +11 -9
- data/spec/spec_helper.rb +1 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a7632e618c8546962cbe7c6dc8bb6c8f1622a75e
|
4
|
+
data.tar.gz: e0892a3d514bd92263803f65391c72b38a3cb6a0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3b1a73b5c3d1ea5faf6596b2cc24562982d86fbb82980cdbac95524f43af3efb1bdc996476d30c86d557e44f3ddb4ec57a42aba68345238747edefd566a2b92b
|
7
|
+
data.tar.gz: 432256a6c72779709dd78553ad2991af954c152abafb064b9cdb108ded299104d1b8b3c21d4eecd76b3e4b5ea31b1fca4bf034b343ab0c0f575608a07837c37c
|
data/CHANGELOG.md
CHANGED
@@ -0,0 +1,27 @@
|
|
1
|
+
module Ellen
|
2
|
+
module Actions
|
3
|
+
class Help < Base
|
4
|
+
def call
|
5
|
+
message.reply(body)
|
6
|
+
end
|
7
|
+
|
8
|
+
private
|
9
|
+
|
10
|
+
def body
|
11
|
+
action_descriptions.join("\n")
|
12
|
+
end
|
13
|
+
|
14
|
+
def action_descriptions
|
15
|
+
Ellen.actions.map do |action|
|
16
|
+
prefix = ""
|
17
|
+
prefix << message.robot.name << " " unless action.all?
|
18
|
+
"%-#{pattern_max_length + prefix.size}s - #{action.description}" % "#{prefix}#{action.pattern.inspect}"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def pattern_max_length
|
23
|
+
Ellen.actions.map {|action| action.pattern.inspect }.map(&:size).max
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/ellen/adapters/shell.rb
CHANGED
data/lib/ellen/handlers/help.rb
CHANGED
@@ -1,12 +1,10 @@
|
|
1
1
|
module Ellen
|
2
2
|
module Handlers
|
3
3
|
class Help < Base
|
4
|
-
on /help
|
4
|
+
on /help( me)?\z/i, name: "help", description: "Show this help message"
|
5
5
|
|
6
6
|
def help(message)
|
7
|
-
|
8
|
-
"%-30s - #{action.description}" % "#{robot.name unless action.all?} #{action.pattern.inspect}"
|
9
|
-
}.join("\n")
|
7
|
+
Ellen::Actions::Help.new(message).call
|
10
8
|
end
|
11
9
|
end
|
12
10
|
end
|
data/lib/ellen/handlers/ping.rb
CHANGED
data/lib/ellen/message.rb
CHANGED
@@ -1,10 +1,17 @@
|
|
1
1
|
module Ellen
|
2
2
|
class Message
|
3
|
-
attr_reader
|
3
|
+
attr_reader(
|
4
|
+
:body,
|
5
|
+
:from,
|
6
|
+
:match_data,
|
7
|
+
:robot,
|
8
|
+
:to,
|
9
|
+
)
|
4
10
|
|
5
11
|
def initialize(options)
|
6
12
|
@body = options[:body]
|
7
13
|
@from = options[:from]
|
14
|
+
@robot = options[:robot]
|
8
15
|
@to = options[:to]
|
9
16
|
end
|
10
17
|
|
@@ -15,5 +22,10 @@ module Ellen
|
|
15
22
|
def [](index)
|
16
23
|
match_data[index]
|
17
24
|
end
|
25
|
+
|
26
|
+
def reply(body, options = {})
|
27
|
+
attributes = { body: body, from: from, to: to }.merge(options)
|
28
|
+
robot.say(attributes)
|
29
|
+
end
|
18
30
|
end
|
19
31
|
end
|
data/lib/ellen/robot.rb
CHANGED
data/lib/ellen/version.rb
CHANGED
data/lib/ellen.rb
CHANGED
@@ -6,9 +6,28 @@ describe Ellen::Handlers::Help do
|
|
6
6
|
end
|
7
7
|
|
8
8
|
describe "#help" do
|
9
|
+
let(:from) do
|
10
|
+
"alice"
|
11
|
+
end
|
12
|
+
|
13
|
+
let(:to) do
|
14
|
+
"#general"
|
15
|
+
end
|
16
|
+
|
17
|
+
let(:body) do
|
18
|
+
<<-EOS.strip_heredoc.strip
|
19
|
+
ellen /help( me)?\\z/i - Show this help message
|
20
|
+
ellen /ping\\z/i - Return PONG to PING
|
21
|
+
EOS
|
22
|
+
end
|
23
|
+
|
9
24
|
it "responds to `@ellen help` and says each handler's usage" do
|
10
|
-
robot.should_receive(:say).with(
|
11
|
-
|
25
|
+
robot.should_receive(:say).with(
|
26
|
+
body: body,
|
27
|
+
from: from,
|
28
|
+
to: to,
|
29
|
+
)
|
30
|
+
robot.receive(body: "@ellen help", from: from, to: to)
|
12
31
|
end
|
13
32
|
end
|
14
33
|
end
|
@@ -6,15 +6,17 @@ describe Ellen::Handlers::Ping do
|
|
6
6
|
end
|
7
7
|
|
8
8
|
describe "#ping" do
|
9
|
-
|
10
|
-
"
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
9
|
+
let(:from) do
|
10
|
+
"alice"
|
11
|
+
end
|
12
|
+
|
13
|
+
let(:to) do
|
14
|
+
"#general"
|
15
|
+
end
|
16
|
+
|
17
|
+
it "returns PONG to PING" do
|
18
|
+
robot.should_receive(:say).with(body: "pong", from: from, to: to)
|
19
|
+
robot.receive(body: "@ellen ping", from: from, to: to)
|
18
20
|
end
|
19
21
|
end
|
20
22
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ellen
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryo Nakamura
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-04-
|
11
|
+
date: 2014-04-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -170,6 +170,9 @@ files:
|
|
170
170
|
- images/screenshot.png
|
171
171
|
- lib/ellen.rb
|
172
172
|
- lib/ellen/action.rb
|
173
|
+
- lib/ellen/actions/base.rb
|
174
|
+
- lib/ellen/actions/help.rb
|
175
|
+
- lib/ellen/actions/ping.rb
|
173
176
|
- lib/ellen/adapter_builder.rb
|
174
177
|
- lib/ellen/adapters/base.rb
|
175
178
|
- lib/ellen/adapters/shell.rb
|