ellen 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e25de66dca77cd59a37365477996c7323c2cdd83
4
+ data.tar.gz: d6aae02262e034f3f603d4c23fa92666b718d357
5
+ SHA512:
6
+ metadata.gz: 9696111504ef24468dbc0dac2c8a606842133d88e42ab7e6818cc022b8fa9e31424d6e1d02f40849ef19b32fdd00e8843284808de94ea994e6c46c183ffbeac2
7
+ data.tar.gz: 518c304aa42d6f1d1eeacd5c4a4f0e01b61e6846b4dc835237f655cb904c2a3da88032fa33446459df2512fc4263740412366b880c7df4a3feba1234bf7d4d04
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ellen.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Ryo Nakamura
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,14 @@
1
+ # Ellen
2
+ A chatterbot framework, inspired by Hubot.
3
+
4
+ ## Dependencies
5
+ * Ruby 1.9.3+
6
+
7
+ ## Usage
8
+ ```sh
9
+ $ gem install ellen # Install `ellen` gem to your local machine
10
+ $ ellen --generate # Generate your new chatterbot with ./ellen/ directory
11
+ $ cd ellen # Changes to ./ellen/
12
+ $ vi Gemfile # Adds your favorite plugin gems
13
+ $ bundle exec ellen --adapter=shell # Run your chatterbot with specified adapter
14
+ ```
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+ task default: :spec
data/bin/ellen ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
4
+ require "ellen"
5
+
6
+ Ellen::CommandBuilder.new(ARGV).build.call
data/ellen.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "ellen/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "ellen"
7
+ spec.version = Ellen::VERSION
8
+ spec.authors = ["Ryo Nakamura"]
9
+ spec.email = ["r7kamura@gmail.com"]
10
+ spec.summary = "A chatterbot framework, inspired by Hubot"
11
+ spec.homepage = "https://github.com/r7kamura/ellen"
12
+ spec.license = "MIT"
13
+
14
+ spec.files = `git ls-files -z`.split("\x0")
15
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
16
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17
+ spec.require_paths = ["lib"]
18
+
19
+ spec.add_dependency "activesupport"
20
+ spec.add_dependency "bundler"
21
+ spec.add_dependency "mem"
22
+ spec.add_dependency "slop"
23
+ spec.add_development_dependency "pry"
24
+ spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "rspec", "2.14.1"
26
+ end
@@ -0,0 +1,32 @@
1
+ module Ellen
2
+ class AdapterBuilder
3
+ attr_reader :robot, :options
4
+
5
+ def initialize(robot, options)
6
+ @robot = robot
7
+ @options = options
8
+ end
9
+
10
+ def build
11
+ adapter_class.new(robot, options)
12
+ end
13
+
14
+ private
15
+
16
+ def adapter_class
17
+ Ellen.adapters[name] or die
18
+ end
19
+
20
+ def name
21
+ options[:adapter] || default_name
22
+ end
23
+
24
+ def default_name
25
+ "shell"
26
+ end
27
+
28
+ def die
29
+ Ellen.die("No adapter is defined for `#{name}`")
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,30 @@
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
+ module Ellen
13
+ module Adapters
14
+ class Base
15
+ class << self
16
+ def inherited(child)
17
+ super
18
+ Ellen.adapters[child.name.split("::").last.underscore] = child
19
+ end
20
+ end
21
+
22
+ attr_reader :robot, :options
23
+
24
+ def initialize(robot, options)
25
+ @robot = robot
26
+ @options = options
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,44 @@
1
+ require "readline"
2
+
3
+ module Ellen
4
+ module Adapters
5
+ class Shell < Base
6
+ def run
7
+ explain
8
+ listen
9
+ end
10
+
11
+ private
12
+
13
+ def explain
14
+ puts "Type `exit` or `quit` to end the session."
15
+ end
16
+
17
+ def prompt
18
+ @prompt ||= "> "
19
+ end
20
+
21
+ def prompt=(str)
22
+ @prompt = str
23
+ end
24
+
25
+ def read
26
+ Readline.readline(prompt, true)
27
+ end
28
+
29
+ def listen
30
+ loop { step }
31
+ end
32
+
33
+ def step
34
+ prompt
35
+ case message = read
36
+ when "exit", "quit"
37
+ exit
38
+ else
39
+ robot.receive(message)
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,29 @@
1
+ module Ellen
2
+ class CommandBuilder
3
+ include Mem
4
+
5
+ attr_reader :arguments
6
+
7
+ def initialize(arguments = ARGV)
8
+ @arguments = arguments
9
+ end
10
+
11
+ def build
12
+ command_class.new(options)
13
+ end
14
+
15
+ private
16
+
17
+ def command_class
18
+ options[:generate] ? Commands::Generate : Commands::Run
19
+ end
20
+
21
+ def options
22
+ Slop.parse!(arguments, help: true) do
23
+ on("g", "generate", "Generate a new chatterbot with ./ellen/ directory if specified.")
24
+ on("a", "adapter=", "Take adapter name.")
25
+ end.to_hash
26
+ end
27
+ memoize :options
28
+ end
29
+ end
@@ -0,0 +1,11 @@
1
+ module Ellen
2
+ module Commands
3
+ class Base
4
+ attr_reader :options
5
+
6
+ def initialize(options)
7
+ @options = options
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,33 @@
1
+ require "fileutils"
2
+
3
+ module Ellen
4
+ module Commands
5
+ class Generate < Base
6
+ def call
7
+ valid? ? copy : die
8
+ end
9
+
10
+ private
11
+
12
+ def copy
13
+ FileUtils.cp_r(templates_directory_path, destination_path)
14
+ end
15
+
16
+ def die
17
+ Ellen.die("#{destination_path} already exists.")
18
+ end
19
+
20
+ def templates_directory_path
21
+ File.expand_path("../../../../templates", __FILE__)
22
+ end
23
+
24
+ def destination_path
25
+ "./ellen/"
26
+ end
27
+
28
+ def valid?
29
+ !File.exists?(destination_path)
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,9 @@
1
+ module Ellen
2
+ module Commands
3
+ class Run < Base
4
+ def call
5
+ Robot.new(options).run
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,28 @@
1
+ # Abstract class to be inherited from handler class.
2
+ #
3
+ # Example:
4
+ #
5
+ # class MyHandler < Ellen::Handlers::Base
6
+ # def call(message)
7
+ # ... do your work ...
8
+ # end
9
+ # end
10
+ #
11
+ module Ellen
12
+ module Handlers
13
+ class Base
14
+ class << self
15
+ def inherited(child)
16
+ super
17
+ Ellen.handlers << child
18
+ end
19
+ end
20
+
21
+ attr_reader :robot
22
+
23
+ def initialize(robot)
24
+ @robot = robot
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,17 @@
1
+ module Ellen
2
+ module Handlers
3
+ class Help < Base
4
+ def call(message)
5
+ case message
6
+ when /help\z/
7
+ help
8
+ end
9
+ end
10
+
11
+ # TODO
12
+ def help
13
+ puts "Not yet implemented"
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,10 @@
1
+ require "logger"
2
+
3
+ module Ellen
4
+ class Logger < Logger
5
+ def initialize(*)
6
+ super
7
+ @formatter = ->(severity, time, name, message) { "#{message}\n" }
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,40 @@
1
+ module Ellen
2
+ class Robot
3
+ include Mem
4
+
5
+ attr_reader :options
6
+
7
+ def initialize(options)
8
+ @options = options
9
+ end
10
+
11
+ def run
12
+ bundle
13
+ adapt
14
+ end
15
+
16
+ def receive(message)
17
+ handlers.each {|handler| handler.call(message) }
18
+ end
19
+
20
+ private
21
+
22
+ def adapt
23
+ adapter.run
24
+ end
25
+
26
+ def adapter
27
+ AdapterBuilder.new(self, options).build
28
+ end
29
+ memoize :adapter
30
+
31
+ def bundle
32
+ Bundler.require
33
+ end
34
+
35
+ def handlers
36
+ Ellen.handlers.map {|handler_class| handler_class.new(self) }
37
+ end
38
+ memoize :handlers
39
+ end
40
+ end
@@ -0,0 +1,3 @@
1
+ module Ellen
2
+ VERSION = "0.0.1"
3
+ end
data/lib/ellen.rb ADDED
@@ -0,0 +1,42 @@
1
+ require "active_support/core_ext/string/inflections"
2
+ require "bundler"
3
+ require "mem"
4
+ require "slop"
5
+
6
+ module Ellen
7
+ class << self
8
+ include Mem
9
+
10
+ def logger
11
+ @logger ||= Ellen::Logger.new($stdout)
12
+ end
13
+
14
+ def die(message)
15
+ logger.error("Error: #{message}")
16
+ exit(1)
17
+ end
18
+
19
+ def adapters
20
+ {}
21
+ end
22
+ memoize :adapters
23
+
24
+ def handlers
25
+ []
26
+ end
27
+ memoize :handlers
28
+ end
29
+ end
30
+
31
+ require "ellen/adapter_builder"
32
+ require "ellen/adapters/base"
33
+ require "ellen/adapters/shell"
34
+ require "ellen/command_builder"
35
+ require "ellen/commands/base"
36
+ require "ellen/commands/generate"
37
+ require "ellen/commands/run"
38
+ require "ellen/handlers/base"
39
+ require "ellen/handlers/help"
40
+ require "ellen/logger"
41
+ require "ellen/robot"
42
+ require "ellen/version"
@@ -0,0 +1,39 @@
1
+ require "spec_helper"
2
+
3
+ describe Ellen::Commands::Generate do
4
+ describe "#call" do
5
+ after do
6
+ FileUtils.rmtree("./ellen/")
7
+ end
8
+
9
+ let(:command) do
10
+ Ellen::CommandBuilder.new(arguments).build
11
+ end
12
+
13
+ let(:call) do
14
+ command.call
15
+ end
16
+
17
+ let(:arguments) do
18
+ ["--generate"]
19
+ end
20
+
21
+ context "with normal condition" do
22
+ it "generates ./ellen/ directory from our templates" do
23
+ call
24
+ File.exists?("./ellen/").should == true
25
+ end
26
+ end
27
+
28
+ context "when ./ellen/ directory already exists" do
29
+ before do
30
+ FileUtils.mkdir("./ellen/")
31
+ end
32
+
33
+ it "exits process with dying message" do
34
+ Ellen.logger.should_receive(:error).with("Error: ./ellen/ already exists.")
35
+ expect { call }.to raise_error(SystemExit)
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,50 @@
1
+ require "spec_helper"
2
+
3
+ describe Ellen::Commands::Run do
4
+ describe "#call" do
5
+ let(:command) do
6
+ Ellen::CommandBuilder.new(arguments).build
7
+ end
8
+
9
+ let(:call) do
10
+ command.call
11
+ end
12
+
13
+ let(:arguments) do
14
+ ["--adapter", adapter_name]
15
+ end
16
+
17
+ let(:adapter_name) do
18
+ "shell"
19
+ end
20
+
21
+ context "with no adapter name" do
22
+ before do
23
+ arguments.clear
24
+ end
25
+
26
+ it "defaults to shell adapter" do
27
+ Ellen::Adapters::Shell.any_instance.should_receive(:run)
28
+ call
29
+ end
30
+ end
31
+
32
+ context "with registered name" do
33
+ it "runs the adapter" do
34
+ Ellen::Adapters::Shell.any_instance.should_receive(:run)
35
+ call
36
+ end
37
+ end
38
+
39
+ context "with unregistered adapter name" do
40
+ let(:adapter_name) do
41
+ "unregistered"
42
+ end
43
+
44
+ it "exits with dying message" do
45
+ Ellen.logger.should_receive(:error).with("Error: No adapter is defined for `unregistered`")
46
+ expect { call }.to raise_error(SystemExit)
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,7 @@
1
+ require "ellen"
2
+
3
+ RSpec.configure do |config|
4
+ config.treat_symbols_as_metadata_keys_with_true_values = true
5
+ config.run_all_when_everything_filtered = true
6
+ config.filter_run :focus
7
+ end
data/templates/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "ellen"
metadata ADDED
@@ -0,0 +1,170 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ellen
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Ryo Nakamura
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-04-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: mem
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: slop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '='
102
+ - !ruby/object:Gem::Version
103
+ version: 2.14.1
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '='
109
+ - !ruby/object:Gem::Version
110
+ version: 2.14.1
111
+ description:
112
+ email:
113
+ - r7kamura@gmail.com
114
+ executables:
115
+ - ellen
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - ".gitignore"
120
+ - Gemfile
121
+ - LICENSE.txt
122
+ - README.md
123
+ - Rakefile
124
+ - bin/ellen
125
+ - ellen.gemspec
126
+ - lib/ellen.rb
127
+ - lib/ellen/adapter_builder.rb
128
+ - lib/ellen/adapters/base.rb
129
+ - lib/ellen/adapters/shell.rb
130
+ - lib/ellen/command_builder.rb
131
+ - lib/ellen/commands/base.rb
132
+ - lib/ellen/commands/generate.rb
133
+ - lib/ellen/commands/run.rb
134
+ - lib/ellen/handlers/base.rb
135
+ - lib/ellen/handlers/help.rb
136
+ - lib/ellen/logger.rb
137
+ - lib/ellen/robot.rb
138
+ - lib/ellen/version.rb
139
+ - spec/ellen/commands/generate_spec.rb
140
+ - spec/ellen/commands/run_spec.rb
141
+ - spec/spec_helper.rb
142
+ - templates/Gemfile
143
+ homepage: https://github.com/r7kamura/ellen
144
+ licenses:
145
+ - MIT
146
+ metadata: {}
147
+ post_install_message:
148
+ rdoc_options: []
149
+ require_paths:
150
+ - lib
151
+ required_ruby_version: !ruby/object:Gem::Requirement
152
+ requirements:
153
+ - - ">="
154
+ - !ruby/object:Gem::Version
155
+ version: '0'
156
+ required_rubygems_version: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - ">="
159
+ - !ruby/object:Gem::Version
160
+ version: '0'
161
+ requirements: []
162
+ rubyforge_project:
163
+ rubygems_version: 2.2.2
164
+ signing_key:
165
+ specification_version: 4
166
+ summary: A chatterbot framework, inspired by Hubot
167
+ test_files:
168
+ - spec/ellen/commands/generate_spec.rb
169
+ - spec/ellen/commands/run_spec.rb
170
+ - spec/spec_helper.rb