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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 00aad36c6f88f0f259b0fa6cd9a24c6e1a0cdd13
4
- data.tar.gz: 38e66b51e6389d497260ca257f6145ee25f22c4b
3
+ metadata.gz: a7632e618c8546962cbe7c6dc8bb6c8f1622a75e
4
+ data.tar.gz: e0892a3d514bd92263803f65391c72b38a3cb6a0
5
5
  SHA512:
6
- metadata.gz: 63bb23ab82f4d1781b6c9474fb8694113020eec94f497151d6f7e12ff1c5a44fd047a726f965ee1e16283be05cad46140fcee1ed5e47df4fc52c903ac8aaf4df
7
- data.tar.gz: a14ac2143cde8550c000027ae6fdb4525b2bff22da17b5442cf3cb6e558f553f949543300a4d806458ce3e29ca281c68cb8ec33316179fbb60a615fd5001bd08
6
+ metadata.gz: 3b1a73b5c3d1ea5faf6596b2cc24562982d86fbb82980cdbac95524f43af3efb1bdc996476d30c86d557e44f3ddb4ec57a42aba68345238747edefd566a2b92b
7
+ data.tar.gz: 432256a6c72779709dd78553ad2991af954c152abafb064b9cdb108ded299104d1b8b3c21d4eecd76b3e4b5ea31b1fca4bf034b343ab0c0f575608a07837c37c
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## 0.2.0
2
+ * Change adapter & message interface
3
+
1
4
  ## 0.1.3
2
5
  * Change Ellen::Message interface
3
6
 
@@ -0,0 +1,11 @@
1
+ module Ellen
2
+ module Actions
3
+ class Base
4
+ attr_reader :message
5
+
6
+ def initialize(message)
7
+ @message = message
8
+ end
9
+ end
10
+ end
11
+ end
@@ -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
@@ -0,0 +1,19 @@
1
+ module Ellen
2
+ module Actions
3
+ class Ping < Base
4
+ def call
5
+ message.reply(pong)
6
+ end
7
+
8
+ private
9
+
10
+ def ping
11
+ message.body[-4..-1]
12
+ end
13
+
14
+ def pong
15
+ ping.gsub(/i/i, "i" => "o", "I" => "O")
16
+ end
17
+ end
18
+ end
19
+ end
@@ -16,8 +16,8 @@ module Ellen
16
16
  listen
17
17
  end
18
18
 
19
- def say(body, options = {})
20
- Ellen.logger.info(body)
19
+ def say(message)
20
+ Ellen.logger.info(message[:body])
21
21
  end
22
22
 
23
23
  private
@@ -1,12 +1,10 @@
1
1
  module Ellen
2
2
  module Handlers
3
3
  class Help < Base
4
- on /help\z/i, name: "help", description: "Show this help message"
4
+ on /help( me)?\z/i, name: "help", description: "Show this help message"
5
5
 
6
6
  def help(message)
7
- robot.say Ellen.actions.map {|action|
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
@@ -4,7 +4,7 @@ module Ellen
4
4
  on /ping\z/i, name: "ping", description: "Return PONG to PING"
5
5
 
6
6
  def ping(message)
7
- robot.say message.body[-4..-1].gsub(/i/i, "i" => "o", "I" => "O")
7
+ Ellen::Actions::Ping.new(message).call
8
8
  end
9
9
  end
10
10
  end
data/lib/ellen/message.rb CHANGED
@@ -1,10 +1,17 @@
1
1
  module Ellen
2
2
  class Message
3
- attr_reader :body, :match_data, :from, :to
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
@@ -22,7 +22,7 @@ module Ellen
22
22
  end
23
23
 
24
24
  def receive(attributes)
25
- message = Message.new(attributes)
25
+ message = Message.new(attributes.merge(robot: self))
26
26
  handlers.each do |handler|
27
27
  handler.call(message)
28
28
  end
data/lib/ellen/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Ellen
2
- VERSION = "0.1.3"
2
+ VERSION = "0.2.0"
3
3
  end
data/lib/ellen.rb CHANGED
@@ -31,6 +31,9 @@ module Ellen
31
31
  end
32
32
 
33
33
  require "ellen/action"
34
+ require "ellen/actions/base"
35
+ require "ellen/actions/help"
36
+ require "ellen/actions/ping"
34
37
  require "ellen/adapter_builder"
35
38
  require "ellen/env"
36
39
  require "ellen/env/missing_required_key_error"
@@ -50,7 +50,7 @@ describe Ellen::Adapters::Shell do
50
50
  describe "#say" do
51
51
  it "shows given message body on stdout" do
52
52
  Ellen.logger.should_receive(:info).with("a")
53
- adapter.say("a")
53
+ adapter.say(body: "a")
54
54
  end
55
55
  end
56
56
  end
@@ -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(%r<ellen /help\\z/i +- Show this help message>)
11
- robot.receive(body: "@ellen help")
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
- "@ellen ping" => "pong",
11
- "@ellen Ping" => "Pong",
12
- "@ellen PING" => "PONG",
13
- }.each do |input, output|
14
- it "responds to `#{input}` and says `#{output}`" do
15
- robot.should_receive(:say).with(output)
16
- robot.receive(body: input)
17
- end
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
@@ -6,6 +6,7 @@ if ENV["CI"]
6
6
  CodeClimate::TestReporter.start
7
7
  end
8
8
 
9
+ require "active_support/core_ext/string/strip"
9
10
  require "ellen"
10
11
 
11
12
  RSpec.configure do |config|
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.1.3
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-25 00:00:00.000000000 Z
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