ruboty 1.0.4 → 1.1.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3d2b266449d5fb2a46af0c7c699af4d76e27a561
4
- data.tar.gz: 1a745441ebde7e3ee19af32e22d038ae56116744
3
+ metadata.gz: 2d0316cbee1696f16412c5dec59ff9a9acf2889c
4
+ data.tar.gz: 5cbc28c375c29492d59c02a8a269c7e65358e4ae
5
5
  SHA512:
6
- metadata.gz: b5f6ff5a0937b47e67029609bac31b4071a20b9010bbf366f591bfa0970c598bf21dce883471225d4dbaf32db7cf78a2729f38213fee20377c3c3b9b2220925e
7
- data.tar.gz: 70aa55d5abc89697692ecb6ba97eca087223de45810c44cffe318751c6c140d22fa82c8aa11598c193fad5cc1f2c1dfdea99a3d3e1651ab996cbde0f90f54518
6
+ metadata.gz: 0d47aaf46c28343f8ed9a390c2112ffef02cbf10a1378998047d55eedbc7ebebc5807ae1952143e16f21ae8db6f59ee2de82ce9dc3857c727845eb6879f2b805
7
+ data.tar.gz: 82d6b8b70b6be452b4d9b8924e984440fbf51a024f37141c9dc504b78e31823825dc4df325e47949ec14d5db676ddc8a3fd7bf4b4413eae47e239199b6433aec
@@ -1,3 +1,6 @@
1
+ ## 1.1.0
2
+ * Add :missing option for handler to respond with messages that didn't match any handlers
3
+
1
4
  ## 1.0.4
2
5
  * Support RUBOTY_NAME and obsolete ROBOT_NAME
3
6
 
data/README.md CHANGED
@@ -68,20 +68,6 @@ end
68
68
  ```
69
69
 
70
70
  ## Deploy
71
- Here is the smallest example to deploy a simple chatterbot to Heroku.
71
+ See [r7kamura/ruboty-template](https://github.com/r7kamura/ruboty-template) for example.
72
72
 
73
- ```sh
74
- $ echo 'source "https://rubygems.org"' >> Gemfile
75
- $ echo 'gem "ruboty"' >> Gemfile
76
- $ echo 'bot: bundle exec ruboty' >> Procfile
77
- $ bundle install
78
- $ git init
79
- $ git add .
80
- $ git commit -m "Initial commit"
81
- $ heroku create
82
- $ git push heroku master
83
- $ heroku scale bot=1
84
- ```
85
-
86
- ## Screenshot
87
- ![](https://raw.githubusercontent.com/r7kamura/ruboty/master/images/screenshot.png)
73
+ [![Deploy](https://www.herokucdn.com/deploy/button.png)](https://heroku.com/deploy?template=https://github.com/r7kamura/ruboty-template)
@@ -11,8 +11,13 @@ module Ruboty
11
11
  @options = options
12
12
  end
13
13
 
14
- def call(handler, message)
15
- handler.send(name, message) if message.match pattern_with(handler.robot.name)
14
+ def call(handler, message, options = {})
15
+ if !!options[:missing] == missing? && message.match(pattern_with(handler.robot.name))
16
+ handler.send(name, message)
17
+ true
18
+ else
19
+ false
20
+ end
16
21
  end
17
22
 
18
23
  def all?
@@ -27,6 +32,11 @@ module Ruboty
27
32
  !!options[:hidden]
28
33
  end
29
34
 
35
+ # @note :missing action is called only when any handler doesn't match given message.
36
+ def missing?
37
+ !!options[:missing]
38
+ end
39
+
30
40
  def name
31
41
  options[:name]
32
42
  end
@@ -27,9 +27,9 @@ module Ruboty
27
27
  validate!
28
28
  end
29
29
 
30
- def call(message)
31
- self.class.actions.each do |action|
32
- action.call(self, message)
30
+ def call(message, options = {})
31
+ self.class.actions.inject(false) do |matched, action|
32
+ matched | action.call(self, message, options)
33
33
  end
34
34
  end
35
35
  end
@@ -24,8 +24,10 @@ module Ruboty
24
24
 
25
25
  def receive(attributes)
26
26
  message = Message.new(attributes.merge(robot: self))
27
- handlers.each do |handler|
28
- handler.call(message)
27
+ unless handlers.inject(false) { |matched, handler| matched | handler.call(message) }
28
+ handlers.each do |handler|
29
+ handler.call(message, missing: true)
30
+ end
29
31
  end
30
32
  end
31
33
 
@@ -1,3 +1,3 @@
1
1
  module Ruboty
2
- VERSION = "1.0.4"
2
+ VERSION = "1.1.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruboty
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.1.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-10-23 00:00:00.000000000 Z
11
+ date: 2014-12-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -166,7 +166,6 @@ files:
166
166
  - README.md
167
167
  - Rakefile
168
168
  - bin/ruboty
169
- - images/screenshot.png
170
169
  - lib/ruboty.rb
171
170
  - lib/ruboty/action.rb
172
171
  - lib/ruboty/actions/base.rb
Binary file