conversational 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/.travis.yml +4 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +6 -6
- data/{MIT-LICENSE → LICENSE} +1 -1
- data/{README.markdown → README.md} +2 -2
- data/conversational.gemspec +2 -3
- data/lib/conversational.rb +3 -2
- data/lib/conversational/conversation.rb +11 -14
- data/lib/conversational/version.rb +1 -1
- data/spec/conversation_spec.rb +29 -2
- data/spec/spec_helper.rb +0 -2
- metadata +12 -22
data/.gitignore
CHANGED
data/.travis.yml
ADDED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,16 +1,19 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
conversational (0.
|
4
|
+
conversational (0.4.0)
|
5
5
|
activesupport
|
6
6
|
i18n
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: http://rubygems.org/
|
10
10
|
specs:
|
11
|
-
activesupport (3.0
|
11
|
+
activesupport (3.1.0)
|
12
|
+
multi_json (~> 1.0)
|
12
13
|
diff-lcs (1.1.2)
|
13
14
|
i18n (0.5.0)
|
15
|
+
multi_json (1.0.3)
|
16
|
+
rake (0.9.2)
|
14
17
|
rspec (2.5.0)
|
15
18
|
rspec-core (~> 2.5.0)
|
16
19
|
rspec-expectations (~> 2.5.0)
|
@@ -19,14 +22,11 @@ GEM
|
|
19
22
|
rspec-expectations (2.5.0)
|
20
23
|
diff-lcs (~> 1.1.2)
|
21
24
|
rspec-mocks (2.5.0)
|
22
|
-
simplecov (0.4.1)
|
23
|
-
simplecov-html (~> 0.4.3)
|
24
|
-
simplecov-html (0.4.3)
|
25
25
|
|
26
26
|
PLATFORMS
|
27
27
|
ruby
|
28
28
|
|
29
29
|
DEPENDENCIES
|
30
30
|
conversational!
|
31
|
+
rake
|
31
32
|
rspec
|
32
|
-
simplecov
|
data/{MIT-LICENSE → LICENSE}
RENAMED
@@ -1,5 +1,7 @@
|
|
1
1
|
# Conversational
|
2
2
|
|
3
|
+
[![Build Status](https://secure.travis-ci.org/dwilkie/conversational.png)](http://travis-ci.org/dwilkie/conversational)
|
4
|
+
|
3
5
|
Conversational makes it easier to accept incoming text messages (SMS), emails and IM and respond to them in your application.
|
4
6
|
|
5
7
|
NOTE: Conversational no longer supports ActiveRecord additions or "stateful" conversations. If you still need this feature use version 0.3.2
|
@@ -82,5 +84,3 @@ You can configure Conversation to deal with unknown or blank topics as follows:
|
|
82
84
|
|
83
85
|
Now if the user texts something like "hey jonnie", they'll receive: "Sorry. Unknown Command." Similarly, if they text nothing, they'll receive "Hey. What do you want?"
|
84
86
|
|
85
|
-
Copyright (c) 2011 David Wilkie, released under the MIT license
|
86
|
-
|
data/conversational.gemspec
CHANGED
@@ -19,10 +19,9 @@ Gem::Specification.new do |s|
|
|
19
19
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
20
|
s.require_paths = ["lib"]
|
21
21
|
|
22
|
-
s.
|
23
|
-
s.
|
22
|
+
s.add_dependency("activesupport")
|
23
|
+
s.add_dependency("i18n")
|
24
24
|
|
25
25
|
s.add_development_dependency("rspec")
|
26
|
-
s.add_development_dependency("simplecov")
|
27
26
|
end
|
28
27
|
|
data/lib/conversational.rb
CHANGED
@@ -2,23 +2,19 @@ module Conversational
|
|
2
2
|
module Conversation
|
3
3
|
|
4
4
|
mattr_accessor :unknown_topic_subclass,
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
:blank_topic_subclass,
|
6
|
+
:parent,
|
7
|
+
:class_suffix
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
base.extend ClassMethods
|
14
|
-
end
|
9
|
+
extend ActiveSupport::Concern
|
10
|
+
|
11
|
+
included do
|
12
|
+
Conversational::Conversation.parent = self
|
15
13
|
|
16
|
-
module InstanceAttributes
|
17
14
|
attr_accessor :topic
|
18
15
|
|
19
16
|
def initialize(options = {})
|
20
17
|
self.topic = options[:topic]
|
21
|
-
super
|
22
18
|
end
|
23
19
|
end
|
24
20
|
|
@@ -83,6 +79,7 @@ module Conversational
|
|
83
79
|
end
|
84
80
|
|
85
81
|
module ClassMethods
|
82
|
+
|
86
83
|
def unknown_topic_subclass(value)
|
87
84
|
Conversational::Conversation.unknown_topic_subclass = Conversational::Conversation.stringify(value)
|
88
85
|
end
|
@@ -185,7 +182,7 @@ module Conversational
|
|
185
182
|
|
186
183
|
def self.find_subclass_by_topic(topic, options = {})
|
187
184
|
subclass = nil
|
188
|
-
if topic.nil? || topic.
|
185
|
+
if topic.nil? || topic.empty?
|
189
186
|
unless options[:exclude_blank_unknown]
|
190
187
|
subclass = blank_topic_subclass.constantize if blank_topic_subclass
|
191
188
|
end
|
@@ -224,7 +221,7 @@ module Conversational
|
|
224
221
|
end
|
225
222
|
|
226
223
|
def self.topic_subclass_name(topic)
|
227
|
-
topic.
|
224
|
+
topic.camelize + (class_suffix || parent).to_s
|
228
225
|
end
|
229
226
|
|
230
227
|
private
|
@@ -258,7 +255,7 @@ module Conversational
|
|
258
255
|
else
|
259
256
|
excluded_class = @@excluded_classes.to_s
|
260
257
|
begin
|
261
|
-
excluded_class.
|
258
|
+
excluded_class.camelize.constantize == subclass
|
262
259
|
rescue
|
263
260
|
false
|
264
261
|
end
|
data/spec/conversation_spec.rb
CHANGED
@@ -13,6 +13,9 @@ describe Conversational::Conversation do
|
|
13
13
|
class SmokingConversation < Conversation
|
14
14
|
end
|
15
15
|
|
16
|
+
class BusinessConversation < Conversation
|
17
|
+
end
|
18
|
+
|
16
19
|
class DrivingBlahBlah < Conversation
|
17
20
|
end
|
18
21
|
|
@@ -31,7 +34,7 @@ describe Conversational::Conversation do
|
|
31
34
|
Conversation.should respond_to(:class_suffix)
|
32
35
|
end
|
33
36
|
|
34
|
-
let
|
37
|
+
let(:conversation) { Conversation.new }
|
35
38
|
|
36
39
|
before do
|
37
40
|
Conversation.exclude(nil)
|
@@ -46,31 +49,37 @@ describe Conversational::Conversation do
|
|
46
49
|
Conversation.exclude "something"
|
47
50
|
}.should_not raise_error
|
48
51
|
end
|
52
|
+
|
49
53
|
it "should accept a symbol" do
|
50
54
|
lambda {
|
51
55
|
Conversation.exclude :defined_conversation
|
52
56
|
}.should_not raise_error
|
53
57
|
end
|
58
|
+
|
54
59
|
it "should accept a regex" do
|
55
60
|
lambda {
|
56
61
|
Conversation.exclude /something/i
|
57
62
|
}.should_not raise_error
|
58
63
|
end
|
64
|
+
|
59
65
|
it "should accept a Class" do
|
60
66
|
lambda {
|
61
67
|
Conversation.exclude(DrinkingConversation)
|
62
68
|
}.should_not raise_error
|
63
69
|
end
|
70
|
+
|
64
71
|
it "should accept an Array where the elements are a Class, String, Symbol or Regexp" do
|
65
72
|
lambda {
|
66
73
|
Conversation.exclude ["Something", DrinkingConversation, /something/i, :something]
|
67
74
|
}.should_not raise_error
|
68
75
|
end
|
76
|
+
|
69
77
|
it "should accept nil" do
|
70
78
|
lambda {
|
71
79
|
Conversation.exclude nil
|
72
80
|
}.should_not raise_error
|
73
81
|
end
|
82
|
+
|
74
83
|
it "should not accept anything else" do
|
75
84
|
lambda {
|
76
85
|
Conversation.exclude({})
|
@@ -85,6 +94,16 @@ describe Conversational::Conversation do
|
|
85
94
|
end
|
86
95
|
end
|
87
96
|
|
97
|
+
describe "#initialize" do
|
98
|
+
context ":topic => 'blah'" do
|
99
|
+
let(:subject) { Conversation.new(:topic => 'blah') }
|
100
|
+
|
101
|
+
it "should set the topic to 'blah'" do
|
102
|
+
subject.topic.should == 'blah'
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
88
107
|
describe "#topic_defined?" do
|
89
108
|
shared_examples_for "#topic_defined? for an excluded class" do
|
90
109
|
it "should return nil" do
|
@@ -93,8 +112,8 @@ describe Conversational::Conversation do
|
|
93
112
|
end
|
94
113
|
|
95
114
|
context "a class with this topic is defined" do
|
96
|
-
before { conversation.topic = "drinking" }
|
97
115
|
it "should be true" do
|
116
|
+
conversation.topic = "drinking"
|
98
117
|
conversation.topic_defined?.should be_true
|
99
118
|
end
|
100
119
|
|
@@ -145,6 +164,7 @@ describe Conversational::Conversation do
|
|
145
164
|
it "should return nil" do
|
146
165
|
conversation.details.should be_nil
|
147
166
|
end
|
167
|
+
|
148
168
|
context "when '.unknown_topic_subclass' is set" do
|
149
169
|
before {Conversation.unknown_topic_subclass(SmokingConversation)}
|
150
170
|
it "should return an instance of the unknown_topic_subclass" do
|
@@ -153,6 +173,13 @@ describe Conversational::Conversation do
|
|
153
173
|
end
|
154
174
|
end
|
155
175
|
|
176
|
+
context "a conversation for this topic ending with 's' has been defined" do
|
177
|
+
before { conversation.topic = "business" }
|
178
|
+
it "should return the instance as a subclass" do
|
179
|
+
conversation.details.should be_a(BusinessConversation)
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
156
183
|
context "a conversation for this topic has been defined" do
|
157
184
|
before { conversation.topic = "drinking" }
|
158
185
|
it "should return the instance as a subclass" do
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: conversational
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-09-
|
12
|
+
date: 2011-09-30 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
16
|
-
requirement: &
|
16
|
+
requirement: &82126960 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *82126960
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: i18n
|
27
|
-
requirement: &
|
27
|
+
requirement: &82126750 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *82126750
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rspec
|
38
|
-
requirement: &
|
38
|
+
requirement: &82126510 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,18 +43,7 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
47
|
-
- !ruby/object:Gem::Dependency
|
48
|
-
name: simplecov
|
49
|
-
requirement: &78476370 !ruby/object:Gem::Requirement
|
50
|
-
none: false
|
51
|
-
requirements:
|
52
|
-
- - ! '>='
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
55
|
-
type: :development
|
56
|
-
prerelease: false
|
57
|
-
version_requirements: *78476370
|
46
|
+
version_requirements: *82126510
|
58
47
|
description: Allows you to instansiate conversations based on keywords
|
59
48
|
email:
|
60
49
|
- dwilkie@gmail.com
|
@@ -63,10 +52,11 @@ extensions: []
|
|
63
52
|
extra_rdoc_files: []
|
64
53
|
files:
|
65
54
|
- .gitignore
|
55
|
+
- .travis.yml
|
66
56
|
- Gemfile
|
67
57
|
- Gemfile.lock
|
68
|
-
-
|
69
|
-
- README.
|
58
|
+
- LICENSE
|
59
|
+
- README.md
|
70
60
|
- Rakefile
|
71
61
|
- conversational.gemspec
|
72
62
|
- lib/conversational.rb
|
@@ -94,7 +84,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
94
84
|
version: '0'
|
95
85
|
requirements: []
|
96
86
|
rubyforge_project: conversational
|
97
|
-
rubygems_version: 1.8.
|
87
|
+
rubygems_version: 1.8.10
|
98
88
|
signing_key:
|
99
89
|
specification_version: 3
|
100
90
|
summary: Have topic based conversations
|