conversational 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +4 -4
- data/VERSION +1 -1
- data/conversational.gemspec +4 -4
- data/lib/conversational/conversation.rb +12 -7
- data/lib/conversational/conversation_definition.rb +16 -4
- metadata +6 -4
data/README.markdown
CHANGED
@@ -86,7 +86,7 @@ Conversational also allows you to have *stateful* conversations. A stateful conv
|
|
86
86
|
|
87
87
|
Let's build on the prevous example using stateful conversations.
|
88
88
|
|
89
|
-
Our application so far is *stateless*. Currently if we get a friend request we have no way of accepting or rejecting it. If we were to continue building a stateless application we would
|
89
|
+
Our application so far is *stateless*. Currently if we get a friend request we have no way of accepting or rejecting it. If we were to continue building a stateless application we would simply add a couple of new commands such as:
|
90
90
|
|
91
91
|
* "afr <friend>"
|
92
92
|
* "rfr <friend>"
|
@@ -146,7 +146,7 @@ Now take a look at our `FacebookAlert` class. The first thing is that we renamed
|
|
146
146
|
|
147
147
|
There is also a new method `move_along` which looks at the message to see if the user replied with "yes" or "no" and responds appropriately. Notice it also calls `finish`.
|
148
148
|
|
149
|
-
If we jump back and take a look at our main Conversation class we see that `finish` marks the conversation state as finished so it
|
149
|
+
If we jump back and take a look at our main Conversation class we see that `finish` marks the conversation state as finished so it won't be found by `find_or_create_with`. It is important that you remember to call `finish` on all conversations where you don't expect a response.
|
150
150
|
|
151
151
|
So how does this all tie together?
|
152
152
|
|
@@ -196,7 +196,7 @@ Now when we text in "hey jonnie", `details` will try and find a conversation def
|
|
196
196
|
|
197
197
|
The same thing happens for a blank conversation.
|
198
198
|
|
199
|
-
There is one more subtle issue with our application. What if we text in "facebook_alert"? The reply will be: "Invalid response. Reply with yes or no" when it should actually be "Sorry. Unknown Command". This is because if `find_or_create_with` cannot find an existing conversation it will try and create one with the topic "facebook_alert" if `FacebookAlertConversation` is defined in our application (which it is). To solve this
|
199
|
+
There is one more subtle issue with our application. What if we text in "facebook_alert"? The reply will be: "Invalid response. Reply with yes or no" when it should actually be "Sorry. Unknown Command". This is because if `find_or_create_with` cannot find an existing conversation it will try and create one with the topic "facebook_alert" if `FacebookAlertConversation` is defined in our application (which it is). To solve this problem we can use `exclude`.
|
200
200
|
|
201
201
|
class Conversation
|
202
202
|
exclude FacebookAlertConversation
|
@@ -231,7 +231,7 @@ Generates a migration file if you want to use Conversational with Rails
|
|
231
231
|
|
232
232
|
## More Examples
|
233
233
|
|
234
|
-
Here's an [example](http://github.com/dwilkie/drinking) *stateful* conversation app
|
234
|
+
Here's an [example](http://github.com/dwilkie/drinking) *stateful* conversation app about drinking
|
235
235
|
|
236
236
|
## Notes
|
237
237
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.2
|
data/conversational.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{conversational}
|
8
|
-
s.version = "0.3.
|
8
|
+
s.version = "0.3.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["David Wilkie"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-08-31}
|
13
13
|
s.email = %q{dwilkie@gmail.com}
|
14
14
|
s.extra_rdoc_files = [
|
15
15
|
"README.markdown"
|
@@ -55,7 +55,7 @@ Gem::Specification.new do |s|
|
|
55
55
|
s.homepage = %q{http://github.com/dwilkie/conversational}
|
56
56
|
s.rdoc_options = ["--charset=UTF-8"]
|
57
57
|
s.require_paths = ["lib"]
|
58
|
-
s.rubygems_version = %q{1.3.
|
58
|
+
s.rubygems_version = %q{1.3.7}
|
59
59
|
s.summary = %q{Have conversations with your users over SMS}
|
60
60
|
s.test_files = [
|
61
61
|
"spec/conversation_spec.rb",
|
@@ -69,7 +69,7 @@ Gem::Specification.new do |s|
|
|
69
69
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
70
70
|
s.specification_version = 3
|
71
71
|
|
72
|
-
if Gem::Version.new(Gem::
|
72
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
73
73
|
else
|
74
74
|
end
|
75
75
|
else
|
@@ -12,12 +12,12 @@ module Conversational
|
|
12
12
|
|
13
13
|
# Returns the specific sublass of conversation based from the topic
|
14
14
|
# Example:
|
15
|
-
#
|
15
|
+
#
|
16
16
|
# <tt>
|
17
17
|
# Class Conversation
|
18
18
|
# include Conversational::Conversation
|
19
19
|
# end
|
20
|
-
#
|
20
|
+
#
|
21
21
|
# Class HelloConversation < Conversation
|
22
22
|
# end
|
23
23
|
#
|
@@ -58,6 +58,10 @@ module Conversational
|
|
58
58
|
becomes(details_subclass) if details_subclass
|
59
59
|
end
|
60
60
|
|
61
|
+
def topic_defined?
|
62
|
+
details_subclass = ConversationDefinition.topic_defined?(topic)
|
63
|
+
end
|
64
|
+
|
61
65
|
protected
|
62
66
|
# Called from a subclass to deliver the message
|
63
67
|
def say(message)
|
@@ -66,7 +70,7 @@ module Conversational
|
|
66
70
|
|
67
71
|
module InstanceAttributes
|
68
72
|
attr_accessor :with, :topic
|
69
|
-
|
73
|
+
|
70
74
|
def initialize(options = {})
|
71
75
|
self.with = options[:with]
|
72
76
|
self.topic = options[:topic]
|
@@ -89,15 +93,15 @@ module Conversational
|
|
89
93
|
def unknown_topic_subclass=(klass)
|
90
94
|
ConversationDefinition.unknown_topic_subclass = klass
|
91
95
|
end
|
92
|
-
|
96
|
+
|
93
97
|
def unknown_topic_subclass
|
94
98
|
ConversationDefinition.unknown_topic_subclass
|
95
99
|
end
|
96
|
-
|
100
|
+
|
97
101
|
def blank_topic_subclass=(klass)
|
98
102
|
ConversationDefinition.blank_topic_subclass = klass
|
99
103
|
end
|
100
|
-
|
104
|
+
|
101
105
|
def blank_topic_subclass
|
102
106
|
ConversationDefinition.blank_topic_subclass
|
103
107
|
end
|
@@ -127,7 +131,7 @@ module Conversational
|
|
127
131
|
# <tt>
|
128
132
|
# class AbstractConversation < Conversation
|
129
133
|
# end
|
130
|
-
#
|
134
|
+
#
|
131
135
|
# class MonkeyConversation < AbstractConversation
|
132
136
|
# end
|
133
137
|
#
|
@@ -197,3 +201,4 @@ module Conversational
|
|
197
201
|
end
|
198
202
|
end
|
199
203
|
end
|
204
|
+
|
@@ -21,7 +21,9 @@ module Conversational
|
|
21
21
|
def self.find_subclass_by_topic(topic, options = {})
|
22
22
|
subclass = nil
|
23
23
|
if topic.nil? || topic.blank?
|
24
|
-
|
24
|
+
unless options[:exclude_blank_unknown]
|
25
|
+
subclass = blank_topic_subclass if blank_topic_subclass
|
26
|
+
end
|
25
27
|
else
|
26
28
|
project_class_name = self.topic_subclass_name(topic)
|
27
29
|
begin
|
@@ -35,16 +37,25 @@ module Conversational
|
|
35
37
|
(options[:include_all] || !self.exclude?(project_class))
|
36
38
|
subclass = project_class
|
37
39
|
else
|
38
|
-
|
40
|
+
unless options[:exclude_blank_unknown]
|
41
|
+
subclass = unknown_topic_subclass if unknown_topic_subclass
|
42
|
+
end
|
39
43
|
end
|
40
44
|
end
|
41
45
|
subclass
|
42
46
|
end
|
43
47
|
|
48
|
+
def self.topic_defined?(topic)
|
49
|
+
self.find_subclass_by_topic(
|
50
|
+
topic,
|
51
|
+
:exclude_blank_unknown => true
|
52
|
+
)
|
53
|
+
end
|
54
|
+
|
44
55
|
def self.topic_subclass_name(topic)
|
45
56
|
topic.classify + @@klass.to_s
|
46
57
|
end
|
47
|
-
|
58
|
+
|
48
59
|
private
|
49
60
|
def self.exclude?(subclass)
|
50
61
|
if defined?(@@excluded_classes)
|
@@ -57,7 +68,7 @@ module Conversational
|
|
57
68
|
end
|
58
69
|
end
|
59
70
|
end
|
60
|
-
|
71
|
+
|
61
72
|
def self.exclude_class?(subclass)
|
62
73
|
if @@excluded_classes.is_a?(Class)
|
63
74
|
@@excluded_classes == subclass
|
@@ -84,3 +95,4 @@ module Conversational
|
|
84
95
|
end
|
85
96
|
end
|
86
97
|
end
|
98
|
+
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 3
|
8
|
-
-
|
9
|
-
version: 0.3.
|
8
|
+
- 2
|
9
|
+
version: 0.3.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- David Wilkie
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-
|
17
|
+
date: 2010-08-31 00:00:00 +07:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|
@@ -73,6 +73,7 @@ rdoc_options:
|
|
73
73
|
require_paths:
|
74
74
|
- lib
|
75
75
|
required_ruby_version: !ruby/object:Gem::Requirement
|
76
|
+
none: false
|
76
77
|
requirements:
|
77
78
|
- - ">="
|
78
79
|
- !ruby/object:Gem::Version
|
@@ -80,6 +81,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
80
81
|
- 0
|
81
82
|
version: "0"
|
82
83
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
|
+
none: false
|
83
85
|
requirements:
|
84
86
|
- - ">="
|
85
87
|
- !ruby/object:Gem::Version
|
@@ -89,7 +91,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
89
91
|
requirements: []
|
90
92
|
|
91
93
|
rubyforge_project:
|
92
|
-
rubygems_version: 1.3.
|
94
|
+
rubygems_version: 1.3.7
|
93
95
|
signing_key:
|
94
96
|
specification_version: 3
|
95
97
|
summary: Have conversations with your users over SMS
|