ellen 0.1.1 → 0.1.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: 96e3c30b37c53dec2a1f1b781a9bbb8d21dbcb4b
4
- data.tar.gz: ae06dedaad859870eb47f91bc121ce94bbf5e040
3
+ metadata.gz: d335cc5735c8d5308fcdc4fc9cae63e922016d75
4
+ data.tar.gz: b6bd23aa38894718ec4c334187296bb4380ff1cf
5
5
  SHA512:
6
- metadata.gz: d6daf3ce130b28062a9f998b5a930f1699210f913d0786f93116dcd8594d48462a7cfd0ea754647232de3b0dda202439c19037229e0b45bffa35b8c9667511fe
7
- data.tar.gz: cba65d6007a7d5fb66d970ce99914ecf93a9ebaea6254c8414a6e511ec2605dbdee15ea49c71083b0dcaa37e3e32909a7ecbbdbe445622de9a96de7a286f4adf
6
+ metadata.gz: d4f00ccc9dba2c6e54faab5dc56c36cb591cc1b020fa6184bb1fd8a2c44e4ec5421e3742650ae5d7de311d53acd5825f39e9d6df4c609722450af2fa20d55aa0
7
+ data.tar.gz: 9bc6fd8798da1a74ecda1d696db68a1f3a50354e25cd70e765e23a3ae488c29cedfcf81382ee689c53d5398d2c1bedfbdf0234fd016bcb7a8a29a48b9ac146cb
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## 0.1.2
2
+ * Make Handler validatable
3
+
1
4
  ## 0.1.1
2
5
  * Improve Brain interface
3
6
 
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
- You can create your own favorite adapter from
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
- You can create your own handlers to add new behaviors from
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
- ## Bundler
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
 
@@ -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
@@ -12,15 +12,13 @@ module Ellen
12
12
  brain_classes.last
13
13
  end
14
14
 
15
- private
16
-
17
15
  def brain_classes
18
16
  @brain_classes ||= []
19
17
  end
20
18
  end
21
19
 
22
20
  def initialize
23
- validate
21
+ validate!
24
22
  end
25
23
  end
26
24
  end
@@ -1,6 +1,6 @@
1
1
  module Ellen
2
2
  module Brains
3
- class Null < Base
3
+ class Memory < Base
4
4
  def data
5
5
  @data ||= {}
6
6
  end
@@ -20,7 +20,13 @@ module Ellen
20
20
  def validate
21
21
  self.class.envs.each(&:validate)
22
22
  rescue MissingRequiredKeyError => exception
23
- Ellen.die("#{exception}\n#{self.class.usage}")
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
@@ -0,0 +1,6 @@
1
+ module Ellen
2
+ class Env
3
+ class ValidationError < StandardError
4
+ end
5
+ end
6
+ end
@@ -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
@@ -17,6 +17,7 @@ module Ellen
17
17
  bundle
18
18
  setup
19
19
  remember
20
+ handle
20
21
  adapt
21
22
  end
22
23
 
@@ -67,5 +68,9 @@ module Ellen
67
68
  def remember
68
69
  brain
69
70
  end
71
+
72
+ def handle
73
+ handlers
74
+ end
70
75
  end
71
76
  end
data/lib/ellen/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Ellen
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
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/null"
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
@@ -10,9 +10,28 @@ describe Ellen::Robot do
10
10
  end
11
11
 
12
12
  describe "#brain" do
13
- context "without any brain extension gem" do
14
- it "returns a Ellen::Brains::Base" do
15
- instance.brain.should be_a Ellen::Brains::Base
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.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-22 00:00:00.000000000 Z
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/null.rb
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: