ellen 0.1.1 → 0.1.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/CHANGELOG.md +3 -0
- data/README.md +15 -11
- data/lib/ellen/adapters/base.rb +0 -14
- data/lib/ellen/brains/base.rb +1 -3
- data/lib/ellen/brains/{null.rb → memory.rb} +1 -1
- data/lib/ellen/env/validatable.rb +7 -1
- data/lib/ellen/env/validation_error.rb +6 -0
- data/lib/ellen/handlers/base.rb +3 -11
- data/lib/ellen/robot.rb +5 -0
- data/lib/ellen/version.rb +1 -1
- data/lib/ellen.rb +2 -1
- data/spec/ellen/env/validatable_spec.rb +48 -0
- data/spec/ellen/handlers/base_spec.rb +28 -0
- data/spec/ellen/robot_spec.rb +22 -3
- metadata +8 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d335cc5735c8d5308fcdc4fc9cae63e922016d75
|
4
|
+
data.tar.gz: b6bd23aa38894718ec4c334187296bb4380ff1cf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d4f00ccc9dba2c6e54faab5dc56c36cb591cc1b020fa6184bb1fd8a2c44e4ec5421e3742650ae5d7de311d53acd5825f39e9d6df4c609722450af2fa20d55aa0
|
7
|
+
data.tar.gz: 9bc6fd8798da1a74ecda1d696db68a1f3a50354e25cd70e765e23a3ae488c29cedfcf81382ee689c53d5398d2c1bedfbdf0234fd016bcb7a8a29a48b9ac146cb
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -6,25 +6,33 @@ A chatterbot framework, inspired by Hubot.
|
|
6
6
|
* Ruby 1.9.3+
|
7
7
|
|
8
8
|
## Adapter
|
9
|
-
|
10
|
-
[Ellen::Adpaters::Base](https://github.com/r7kamura/ellen/blob/master/lib/ellen/adapters/base.rb)
|
11
|
-
class with #run method. Please see the following real examples for more details.
|
9
|
+
Adapter hooks up your robot to chat services.
|
12
10
|
|
13
11
|
* [Ellen::Adapters::Shell](https://github.com/r7kamura/ellen/blob/master/lib/ellen/adapters/shell.rb)
|
14
12
|
* [Ellen::Adapters::Slack](https://github.com/r7kamura/ellen-slack)
|
15
13
|
* [Ellen::Adapters::Hipchat](https://github.com/r7kamura/ellen-hipchat)
|
16
14
|
* [Ellen::Adapters::Twitter](https://github.com/r7kamura/ellen-twitter)
|
15
|
+
* [Ellen::Adapters::Idobata](https://github.com/hanachin/ellen-idobata)
|
16
|
+
|
17
|
+
## Brain
|
18
|
+
Brain persists your robot's memory.
|
19
|
+
|
20
|
+
* [Ellen::Brains::Memory](https://github.com/r7kamura/ellen/blob/master/lib/ellen/brains/memory.rb)
|
21
|
+
* [Ellen::Brains::Redis](https://github.com/r7kamura/ellen-redis)
|
17
22
|
|
18
23
|
## Handler
|
19
|
-
|
20
|
-
[Ellen::Handlers::Base](https://github.com/r7kamura/ellen/blob/master/lib/ellen/handlers/base.rb) DSL.
|
24
|
+
Handler provides various behaviors to your robot.
|
21
25
|
|
22
26
|
* [Ellen::Handlers::Help](https://github.com/r7kamura/ellen/blob/master/lib/ellen/handlers/help.rb)
|
23
27
|
* [Ellen::Handlers::Ping](https://github.com/r7kamura/ellen/blob/master/lib/ellen/handlers/ping.rb)
|
24
28
|
* [Ellen::Handlers::Cron](https://github.com/r7kamura/ellen-cron)
|
25
29
|
* [Ellen::Handlers::GoogleImage](https://github.com/r7kamura/ellen-google_image)
|
26
30
|
|
27
|
-
##
|
31
|
+
## Configuration
|
32
|
+
Store configuration value in envorinment variables.
|
33
|
+
They are easy to change between deploys without changing any code.
|
34
|
+
We recommend to put `.env` and run with `ellen --dotenv` option to manage them.
|
35
|
+
|
28
36
|
All you need to use your favorite plugins is to write their names into Gemfile.
|
29
37
|
Ellen will load them before running.
|
30
38
|
|
@@ -32,14 +40,10 @@ Ellen will load them before running.
|
|
32
40
|
# Gemfile
|
33
41
|
gem "ellen-cron"
|
34
42
|
gem "ellen-google_image"
|
43
|
+
gem "ellen-redis"
|
35
44
|
gem "ellen-slack"
|
36
45
|
```
|
37
46
|
|
38
|
-
## Config
|
39
|
-
Store config in envorinment variables.
|
40
|
-
They are easy to change between deploys without changing any code.
|
41
|
-
We recommend to put `.env` and run with `ellen --dotenv` option to manage them.
|
42
|
-
|
43
47
|
## Deploy
|
44
48
|
Here is the smallest example to deploy a simple chatterbot to Heroku.
|
45
49
|
|
data/lib/ellen/adapters/base.rb
CHANGED
@@ -1,14 +1,4 @@
|
|
1
1
|
# Abstract class to be inherited from adapter class.
|
2
|
-
#
|
3
|
-
# Example:
|
4
|
-
#
|
5
|
-
# # Used as `ellen --adapter=my_adapter`
|
6
|
-
# class MyAdapter < Ellen::Adapters::Base
|
7
|
-
# def run
|
8
|
-
# ... do your work ...
|
9
|
-
# end
|
10
|
-
# end
|
11
|
-
#
|
12
2
|
module Ellen
|
13
3
|
module Adapters
|
14
4
|
class Base
|
@@ -26,10 +16,6 @@ module Ellen
|
|
26
16
|
@robot = robot
|
27
17
|
validate
|
28
18
|
end
|
29
|
-
|
30
|
-
def say(body, options = {})
|
31
|
-
Ellen.logger.info("Not implemented #{self.class}##{__method__} was called")
|
32
|
-
end
|
33
19
|
end
|
34
20
|
end
|
35
21
|
end
|
data/lib/ellen/brains/base.rb
CHANGED
@@ -20,7 +20,13 @@ module Ellen
|
|
20
20
|
def validate
|
21
21
|
self.class.envs.each(&:validate)
|
22
22
|
rescue MissingRequiredKeyError => exception
|
23
|
-
|
23
|
+
raise ValidationError, "#{exception}\n#{self.class.usage}"
|
24
|
+
end
|
25
|
+
|
26
|
+
def validate!
|
27
|
+
validate
|
28
|
+
rescue ValidationError => exception
|
29
|
+
Ellen.die(exception)
|
24
30
|
end
|
25
31
|
end
|
26
32
|
end
|
data/lib/ellen/handlers/base.rb
CHANGED
@@ -1,14 +1,3 @@
|
|
1
|
-
# Abstract class to be inherited from handler class.
|
2
|
-
#
|
3
|
-
# Example:
|
4
|
-
#
|
5
|
-
# class MyHandler < Ellen::Handlers::Base
|
6
|
-
# on /kill\z/ do |message|
|
7
|
-
# say "Good bye, cruel world..."
|
8
|
-
# exit
|
9
|
-
# end
|
10
|
-
# end
|
11
|
-
#
|
12
1
|
module Ellen
|
13
2
|
module Handlers
|
14
3
|
class Base
|
@@ -29,10 +18,13 @@ module Ellen
|
|
29
18
|
memoize :actions
|
30
19
|
end
|
31
20
|
|
21
|
+
include Env::Validatable
|
22
|
+
|
32
23
|
attr_reader :robot
|
33
24
|
|
34
25
|
def initialize(robot)
|
35
26
|
@robot = robot
|
27
|
+
validate!
|
36
28
|
end
|
37
29
|
|
38
30
|
def call(message)
|
data/lib/ellen/robot.rb
CHANGED
data/lib/ellen/version.rb
CHANGED
data/lib/ellen.rb
CHANGED
@@ -35,10 +35,11 @@ require "ellen/adapter_builder"
|
|
35
35
|
require "ellen/env"
|
36
36
|
require "ellen/env/missing_required_key_error"
|
37
37
|
require "ellen/env/validatable"
|
38
|
+
require "ellen/env/validation_error"
|
38
39
|
require "ellen/adapters/base"
|
39
40
|
require "ellen/adapters/shell"
|
40
41
|
require "ellen/brains/base"
|
41
|
-
require "ellen/brains/
|
42
|
+
require "ellen/brains/memory"
|
42
43
|
require "ellen/command_builder"
|
43
44
|
require "ellen/commands/base"
|
44
45
|
require "ellen/commands/generate"
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Ellen::Env::Validatable do
|
4
|
+
let(:validatable_class) do
|
5
|
+
Class.new do
|
6
|
+
include Ellen::Env::Validatable
|
7
|
+
|
8
|
+
env :A, "description of A"
|
9
|
+
env :B, "description of B", optional: true
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
let(:instance) do
|
14
|
+
validatable_class.new
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "#validate" do
|
18
|
+
context "without required ENV" do
|
19
|
+
it "raises Ellen::Env::ValidationError" do
|
20
|
+
expect { instance.validate }.to raise_error(Ellen::Env::ValidationError)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context "without optional ENV" do
|
25
|
+
before do
|
26
|
+
ENV["A"] = "dummy"
|
27
|
+
end
|
28
|
+
|
29
|
+
after do
|
30
|
+
ENV["A"] = nil
|
31
|
+
end
|
32
|
+
|
33
|
+
it "does nothing" do
|
34
|
+
expect { instance.validate }.not_to raise_error
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "#validate!" do
|
40
|
+
context "without required ENV" do
|
41
|
+
it "dies with usage as erorr message" do
|
42
|
+
Ellen.logger.should_receive(:error).with(/description of A/)
|
43
|
+
Ellen.should_receive(:exit)
|
44
|
+
instance.validate!
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Ellen::Handlers::Base do
|
4
|
+
after do
|
5
|
+
Ellen.handlers.pop
|
6
|
+
end
|
7
|
+
|
8
|
+
let(:robot) do
|
9
|
+
Ellen::Robot.new
|
10
|
+
end
|
11
|
+
|
12
|
+
let!(:handler_class) do
|
13
|
+
Class.new(described_class) do
|
14
|
+
on(/(\d+) \+ (\d+)/, name: "addition", all: true)
|
15
|
+
|
16
|
+
def addition(message)
|
17
|
+
robot.say(message[1].to_i + message[2].to_i)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe ".on" do
|
23
|
+
it "registers an action to the handler" do
|
24
|
+
robot.should_receive(:say).with(2)
|
25
|
+
robot.receive(body: "1 + 1")
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/spec/ellen/robot_spec.rb
CHANGED
@@ -10,9 +10,28 @@ describe Ellen::Robot do
|
|
10
10
|
end
|
11
11
|
|
12
12
|
describe "#brain" do
|
13
|
-
context "without any
|
14
|
-
it "returns a Ellen::Brains::
|
15
|
-
instance.brain.should be_a Ellen::Brains::
|
13
|
+
context "without any Brain class" do
|
14
|
+
it "returns a Ellen::Brains::Memory" do
|
15
|
+
instance.brain.should be_a Ellen::Brains::Memory
|
16
|
+
end
|
17
|
+
|
18
|
+
it "can be used as a Hash object" do
|
19
|
+
instance.brain.data["a"] = 1
|
20
|
+
instance.brain.data["a"].should == 1
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context "with another Brain class" do
|
25
|
+
after do
|
26
|
+
Ellen::Brains::Base.brain_classes.pop
|
27
|
+
end
|
28
|
+
|
29
|
+
let!(:another_brain_class) do
|
30
|
+
Class.new(Ellen::Brains::Base)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "returns its instance as a Brain" do
|
34
|
+
instance.brain.should be_a another_brain_class
|
16
35
|
end
|
17
36
|
end
|
18
37
|
end
|
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.
|
4
|
+
version: 0.1.2
|
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-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -174,7 +174,7 @@ files:
|
|
174
174
|
- lib/ellen/adapters/base.rb
|
175
175
|
- lib/ellen/adapters/shell.rb
|
176
176
|
- lib/ellen/brains/base.rb
|
177
|
-
- lib/ellen/brains/
|
177
|
+
- lib/ellen/brains/memory.rb
|
178
178
|
- lib/ellen/command_builder.rb
|
179
179
|
- lib/ellen/commands/base.rb
|
180
180
|
- lib/ellen/commands/generate.rb
|
@@ -182,6 +182,7 @@ files:
|
|
182
182
|
- lib/ellen/env.rb
|
183
183
|
- lib/ellen/env/missing_required_key_error.rb
|
184
184
|
- lib/ellen/env/validatable.rb
|
185
|
+
- lib/ellen/env/validation_error.rb
|
185
186
|
- lib/ellen/handlers/base.rb
|
186
187
|
- lib/ellen/handlers/help.rb
|
187
188
|
- lib/ellen/handlers/ping.rb
|
@@ -193,6 +194,8 @@ files:
|
|
193
194
|
- spec/ellen/adapters/shell_spec.rb
|
194
195
|
- spec/ellen/commands/generate_spec.rb
|
195
196
|
- spec/ellen/commands/run_spec.rb
|
197
|
+
- spec/ellen/env/validatable_spec.rb
|
198
|
+
- spec/ellen/handlers/base_spec.rb
|
196
199
|
- spec/ellen/handlers/help_spec.rb
|
197
200
|
- spec/ellen/handlers/ping_spec.rb
|
198
201
|
- spec/ellen/robot_spec.rb
|
@@ -227,8 +230,9 @@ test_files:
|
|
227
230
|
- spec/ellen/adapters/shell_spec.rb
|
228
231
|
- spec/ellen/commands/generate_spec.rb
|
229
232
|
- spec/ellen/commands/run_spec.rb
|
233
|
+
- spec/ellen/env/validatable_spec.rb
|
234
|
+
- spec/ellen/handlers/base_spec.rb
|
230
235
|
- spec/ellen/handlers/help_spec.rb
|
231
236
|
- spec/ellen/handlers/ping_spec.rb
|
232
237
|
- spec/ellen/robot_spec.rb
|
233
238
|
- spec/spec_helper.rb
|
234
|
-
has_rdoc:
|