socrates 0.1.7 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/exe/socrates +4 -4
- data/lib/socrates/adapters/{console_adapter.rb → console.rb} +3 -1
- data/lib/socrates/adapters/{memory_adapter.rb → memory.rb} +3 -1
- data/lib/socrates/adapters/{slack_adapter.rb → slack.rb} +3 -1
- data/lib/socrates/bots/{cli_bot.rb → cli.rb} +5 -2
- data/lib/socrates/bots/{slack_bot.rb → slack.rb} +7 -4
- data/lib/socrates/configuration.rb +27 -0
- data/lib/socrates/core/dispatcher.rb +8 -5
- data/lib/socrates/core/state.rb +6 -1
- data/lib/socrates/core/state_data.rb +3 -4
- data/lib/socrates/sample_states.rb +1 -0
- data/lib/socrates/storage/memory.rb +25 -0
- data/lib/socrates/storage/redis.rb +27 -0
- data/lib/socrates/version.rb +1 -1
- data/lib/socrates.rb +8 -9
- data/socrates.gemspec +2 -2
- metadata +14 -13
- data/lib/socrates/config.rb +0 -21
- data/lib/socrates/storage/storage.rb +0 -50
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1f0032b63152e0394fa4fd937f32f4c5bdfdfacb
|
4
|
+
data.tar.gz: bbe5c6deb6223862b6d3dc2d31f9645837b25352
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d278b58e1e84f5f2c72ea64197db4bfe6058bd8714810bcc1a84b1ae613dea7cd267345098d716005b681c561ba697b96963a403513e343cb42510605fd2b16d
|
7
|
+
data.tar.gz: d9fc427ba56a46e1ba8acdea37b82db4598325bdb53a267ba3a263d7f558993faaee359a639c6714ee48b81034e6cf6bbb54f4d58943d1c6c4ef724fc7e07a2d
|
data/exe/socrates
CHANGED
@@ -38,9 +38,9 @@ def run_command(options)
|
|
38
38
|
storage =
|
39
39
|
case options[:storage]
|
40
40
|
when "redis"
|
41
|
-
Socrates::Storage::
|
41
|
+
Socrates::Storage::Redis.new(url: ENV.fetch("REDIS_URL", "redis://localhost"))
|
42
42
|
else
|
43
|
-
Socrates::Storage::
|
43
|
+
Socrates::Storage::Memory.new
|
44
44
|
end
|
45
45
|
|
46
46
|
Socrates.configure do |config|
|
@@ -54,9 +54,9 @@ def run_command(options)
|
|
54
54
|
|
55
55
|
case (adapter = options[:adapter])
|
56
56
|
when "console"
|
57
|
-
Socrates::Bots::
|
57
|
+
Socrates::Bots::CLI.new(state_factory: Socrates::SampleStates::StateFactory.new).start
|
58
58
|
when "slack"
|
59
|
-
Socrates::Bots::
|
59
|
+
Socrates::Bots::Slack.new(state_factory: Socrates::SampleStates::StateFactory.new).start
|
60
60
|
else
|
61
61
|
puts "Unknown adapter '#{adapter}'"
|
62
62
|
exit 1
|
@@ -1,8 +1,11 @@
|
|
1
|
+
require "socrates/adapters/console"
|
2
|
+
require "socrates/core/dispatcher"
|
3
|
+
|
1
4
|
module Socrates
|
2
5
|
module Bots
|
3
|
-
class
|
6
|
+
class CLI
|
4
7
|
def initialize(adapter: nil, state_factory:)
|
5
|
-
@adapter = adapter || Adapters::
|
8
|
+
@adapter = adapter || Adapters::Console.new
|
6
9
|
@dispatcher = Core::Dispatcher.new(adapter: @adapter, state_factory: state_factory)
|
7
10
|
end
|
8
11
|
|
@@ -1,10 +1,13 @@
|
|
1
1
|
require "slack-ruby-client"
|
2
2
|
|
3
|
+
require "socrates/adapters/slack"
|
4
|
+
require "socrates/core/dispatcher"
|
5
|
+
|
3
6
|
module Socrates
|
4
7
|
module Bots
|
5
|
-
class
|
8
|
+
class Slack
|
6
9
|
def initialize(state_factory:)
|
7
|
-
Slack.configure do |config|
|
10
|
+
::Slack.configure do |config|
|
8
11
|
config.token = ENV["SLACK_API_TOKEN"]
|
9
12
|
config.logger = Logger.new(STDOUT)
|
10
13
|
config.logger.level = Logger::INFO
|
@@ -12,8 +15,8 @@ module Socrates
|
|
12
15
|
raise "Missing ENV['SLACK_API_TOKEN']!" unless config.token
|
13
16
|
end
|
14
17
|
|
15
|
-
@slack_client = Slack::RealTime::Client.new
|
16
|
-
@adapter = Adapters::
|
18
|
+
@slack_client = ::Slack::RealTime::Client.new
|
19
|
+
@adapter = Adapters::Slack.new(@slack_client)
|
17
20
|
@dispatcher = Core::Dispatcher.new(adapter: @adapter, state_factory: state_factory)
|
18
21
|
end
|
19
22
|
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require "socrates/logger"
|
2
|
+
require "socrates/storage/memory"
|
3
|
+
|
4
|
+
module Socrates
|
5
|
+
def self.config
|
6
|
+
@config ||= Configuration.new
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.configure
|
10
|
+
yield(config)
|
11
|
+
end
|
12
|
+
|
13
|
+
class Configuration
|
14
|
+
attr_accessor :view_path
|
15
|
+
attr_accessor :storage
|
16
|
+
attr_accessor :error_message
|
17
|
+
attr_accessor :expired_timeout # seconds
|
18
|
+
attr_accessor :logger
|
19
|
+
|
20
|
+
def initialize
|
21
|
+
@storage = Storage::Memory.new
|
22
|
+
@error_message = "Sorry, something went wrong. We'll have to start over..."
|
23
|
+
@expired_timeout = 30.minutes
|
24
|
+
@logger = Socrates::Logger.default
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -1,8 +1,11 @@
|
|
1
1
|
require "hashie"
|
2
|
+
require "active_support/all"
|
2
3
|
|
4
|
+
require "socrates/configuration"
|
3
5
|
require "socrates/logger"
|
4
6
|
require "socrates/string_helpers"
|
5
|
-
require "socrates/storage/
|
7
|
+
require "socrates/storage/memory"
|
8
|
+
require "socrates/core/state"
|
6
9
|
require "socrates/core/state_data"
|
7
10
|
|
8
11
|
module Socrates
|
@@ -11,10 +14,10 @@ module Socrates
|
|
11
14
|
def initialize(adapter:, state_factory:, storage: nil)
|
12
15
|
@adapter = adapter
|
13
16
|
@state_factory = state_factory
|
14
|
-
@storage = storage || Socrates
|
17
|
+
@storage = storage || Socrates.config.storage
|
15
18
|
|
16
|
-
@logger = Socrates
|
17
|
-
@error_message = Socrates
|
19
|
+
@logger = Socrates.config.logger
|
20
|
+
@error_message = Socrates.config.error_message || DEFAULT_ERROR_MESSAGE
|
18
21
|
end
|
19
22
|
|
20
23
|
# rubocop:disable Metrics/AbcSize
|
@@ -105,7 +108,7 @@ module Socrates
|
|
105
108
|
def state_data_expired?(state_data)
|
106
109
|
return unless state_data.timestamp.present?
|
107
110
|
|
108
|
-
state_data.elapsed_time > (
|
111
|
+
state_data.elapsed_time > (Socrates.config.expired_timeout || 30.minutes)
|
109
112
|
end
|
110
113
|
|
111
114
|
def instantiate_state(state_data, context)
|
data/lib/socrates/core/state.rb
CHANGED
@@ -1,6 +1,11 @@
|
|
1
1
|
require "hashie"
|
2
2
|
require "erb"
|
3
3
|
|
4
|
+
require "socrates/configuration"
|
5
|
+
require "socrates/logger"
|
6
|
+
require "socrates/string_helpers"
|
7
|
+
require "socrates/core/state_data"
|
8
|
+
|
4
9
|
module Socrates
|
5
10
|
module Core
|
6
11
|
module State
|
@@ -12,7 +17,7 @@ module Socrates
|
|
12
17
|
@context = context
|
13
18
|
@next_state_id = nil
|
14
19
|
@next_state_action = nil
|
15
|
-
@logger = Socrates
|
20
|
+
@logger = Socrates.config.logger || Socrates::Logger.default
|
16
21
|
end
|
17
22
|
|
18
23
|
def next_state_id
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require "hashie"
|
2
2
|
require "json"
|
3
|
-
require "set"
|
4
3
|
require "yaml"
|
4
|
+
require "active_support/core_ext/time"
|
5
5
|
|
6
6
|
module Socrates
|
7
7
|
module Core
|
@@ -13,7 +13,7 @@ module Socrates
|
|
13
13
|
@state_action = state_action
|
14
14
|
@timestamp = Time.current
|
15
15
|
@data = data
|
16
|
-
@temporary_keys =
|
16
|
+
@temporary_keys = temporary_keys
|
17
17
|
end
|
18
18
|
|
19
19
|
def elapsed_time
|
@@ -33,8 +33,7 @@ module Socrates
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def has_temporary_key?(key)
|
36
|
-
|
37
|
-
@temporary_keys.include?(key) == true
|
36
|
+
@temporary_keys.include?(key)
|
38
37
|
end
|
39
38
|
|
40
39
|
def get(key, clear: false)
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Socrates
|
2
|
+
module Storage
|
3
|
+
class Memory
|
4
|
+
def initialize
|
5
|
+
@memory = {}
|
6
|
+
end
|
7
|
+
|
8
|
+
def has_key?(key)
|
9
|
+
@memory.has_key?(key)
|
10
|
+
end
|
11
|
+
|
12
|
+
def clear(key)
|
13
|
+
@memory.delete(key)
|
14
|
+
end
|
15
|
+
|
16
|
+
def get(key)
|
17
|
+
@memory[key]
|
18
|
+
end
|
19
|
+
|
20
|
+
def put(key, value)
|
21
|
+
@memory[key] = value
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require "redis"
|
2
|
+
|
3
|
+
module Socrates
|
4
|
+
module Storage
|
5
|
+
class Redis
|
6
|
+
def initialize(url: "redis://localhost")
|
7
|
+
@redis = Redis.new(url: url)
|
8
|
+
end
|
9
|
+
|
10
|
+
def has_key?(key)
|
11
|
+
@redis.exists(key)
|
12
|
+
end
|
13
|
+
|
14
|
+
def clear(key)
|
15
|
+
@redis.del(key)
|
16
|
+
end
|
17
|
+
|
18
|
+
def get(key)
|
19
|
+
@redis.get(key)
|
20
|
+
end
|
21
|
+
|
22
|
+
def put(key, value)
|
23
|
+
@redis.set(key, value)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/socrates/version.rb
CHANGED
data/lib/socrates.rb
CHANGED
@@ -1,20 +1,19 @@
|
|
1
1
|
# Socrates
|
2
2
|
require "socrates/version"
|
3
|
-
require "socrates/
|
3
|
+
require "socrates/configuration"
|
4
4
|
require "socrates/logger"
|
5
5
|
require "socrates/string_helpers"
|
6
|
-
require "socrates/adapters/
|
7
|
-
require "socrates/adapters/
|
8
|
-
require "socrates/adapters/
|
6
|
+
require "socrates/adapters/console"
|
7
|
+
require "socrates/adapters/memory"
|
8
|
+
require "socrates/adapters/slack"
|
9
9
|
require "socrates/adapters/stubs"
|
10
|
-
require "socrates/storage/
|
10
|
+
require "socrates/storage/memory"
|
11
|
+
require "socrates/storage/redis"
|
11
12
|
require "socrates/core/state_data"
|
12
13
|
require "socrates/core/state"
|
13
14
|
require "socrates/core/dispatcher"
|
14
|
-
|
15
|
-
|
16
|
-
require "socrates/bots/cli_bot"
|
17
|
-
require "socrates/bots/slack_bot"
|
15
|
+
require "socrates/bots/cli"
|
16
|
+
require "socrates/bots/slack"
|
18
17
|
|
19
18
|
module Socrates
|
20
19
|
end
|
data/socrates.gemspec
CHANGED
@@ -26,7 +26,7 @@ Gem::Specification.new do |spec|
|
|
26
26
|
spec.required_ruby_version = ">= 2.3.0"
|
27
27
|
|
28
28
|
spec.add_development_dependency "bundler", "~> 1.14"
|
29
|
-
spec.add_development_dependency "rake", "~> 10.
|
29
|
+
spec.add_development_dependency "rake", "~> 10.5"
|
30
30
|
spec.add_development_dependency "rspec", "~> 3.5"
|
31
31
|
spec.add_development_dependency "rubocop", "~> 0.48.1"
|
32
32
|
spec.add_development_dependency "timecop", "~> 0.8.1"
|
@@ -35,5 +35,5 @@ Gem::Specification.new do |spec|
|
|
35
35
|
spec.add_dependency "celluloid-io", ">= 0.17.3"
|
36
36
|
spec.add_dependency "hashie", ">= 3.5.5"
|
37
37
|
spec.add_dependency "redis", ">= 3.3.3"
|
38
|
-
spec.add_dependency "slack-ruby-client", ">= 0.8.
|
38
|
+
spec.add_dependency "slack-ruby-client", ">= 0.8.1"
|
39
39
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: socrates
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christian Nelson
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-05-
|
11
|
+
date: 2017-05-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '10.
|
33
|
+
version: '10.5'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '10.
|
40
|
+
version: '10.5'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -142,14 +142,14 @@ dependencies:
|
|
142
142
|
requirements:
|
143
143
|
- - ">="
|
144
144
|
- !ruby/object:Gem::Version
|
145
|
-
version: 0.8.
|
145
|
+
version: 0.8.1
|
146
146
|
type: :runtime
|
147
147
|
prerelease: false
|
148
148
|
version_requirements: !ruby/object:Gem::Requirement
|
149
149
|
requirements:
|
150
150
|
- - ">="
|
151
151
|
- !ruby/object:Gem::Version
|
152
|
-
version: 0.8.
|
152
|
+
version: 0.8.1
|
153
153
|
description:
|
154
154
|
email:
|
155
155
|
- christian@carbonfive.com
|
@@ -170,19 +170,20 @@ files:
|
|
170
170
|
- circle.yml
|
171
171
|
- exe/socrates
|
172
172
|
- lib/socrates.rb
|
173
|
-
- lib/socrates/adapters/
|
174
|
-
- lib/socrates/adapters/
|
175
|
-
- lib/socrates/adapters/
|
173
|
+
- lib/socrates/adapters/console.rb
|
174
|
+
- lib/socrates/adapters/memory.rb
|
175
|
+
- lib/socrates/adapters/slack.rb
|
176
176
|
- lib/socrates/adapters/stubs.rb
|
177
|
-
- lib/socrates/bots/
|
178
|
-
- lib/socrates/bots/
|
179
|
-
- lib/socrates/
|
177
|
+
- lib/socrates/bots/cli.rb
|
178
|
+
- lib/socrates/bots/slack.rb
|
179
|
+
- lib/socrates/configuration.rb
|
180
180
|
- lib/socrates/core/dispatcher.rb
|
181
181
|
- lib/socrates/core/state.rb
|
182
182
|
- lib/socrates/core/state_data.rb
|
183
183
|
- lib/socrates/logger.rb
|
184
184
|
- lib/socrates/sample_states.rb
|
185
|
-
- lib/socrates/storage/
|
185
|
+
- lib/socrates/storage/memory.rb
|
186
|
+
- lib/socrates/storage/redis.rb
|
186
187
|
- lib/socrates/string_helpers.rb
|
187
188
|
- lib/socrates/version.rb
|
188
189
|
- sample-conversation-console.gif
|
data/lib/socrates/config.rb
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
module Socrates
|
2
|
-
module Config
|
3
|
-
extend self
|
4
|
-
|
5
|
-
attr_accessor :view_path
|
6
|
-
attr_accessor :storage
|
7
|
-
attr_accessor :error_message
|
8
|
-
attr_accessor :expired_timeout # seconds
|
9
|
-
attr_accessor :logger
|
10
|
-
end
|
11
|
-
|
12
|
-
class << self
|
13
|
-
def configure
|
14
|
-
block_given? ? yield(Config) : Config
|
15
|
-
end
|
16
|
-
|
17
|
-
def config
|
18
|
-
Config
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
@@ -1,50 +0,0 @@
|
|
1
|
-
require "redis"
|
2
|
-
require "json"
|
3
|
-
|
4
|
-
module Socrates
|
5
|
-
module Storage
|
6
|
-
class MemoryStorage
|
7
|
-
def initialize
|
8
|
-
@storage = {}
|
9
|
-
end
|
10
|
-
|
11
|
-
def has_key?(key)
|
12
|
-
@storage.has_key? key
|
13
|
-
end
|
14
|
-
|
15
|
-
def clear(key)
|
16
|
-
@storage.delete key
|
17
|
-
end
|
18
|
-
|
19
|
-
def get(key)
|
20
|
-
@storage[key]
|
21
|
-
end
|
22
|
-
|
23
|
-
def put(key, value)
|
24
|
-
@storage[key] = value
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
class RedisStorage
|
29
|
-
def initialize(url: "redis://localhost")
|
30
|
-
@redis = Redis.new(url: url)
|
31
|
-
end
|
32
|
-
|
33
|
-
def has_key?(key)
|
34
|
-
@redis.exists(key)
|
35
|
-
end
|
36
|
-
|
37
|
-
def clear(key)
|
38
|
-
@redis.del key
|
39
|
-
end
|
40
|
-
|
41
|
-
def get(key)
|
42
|
-
@redis.get(key)
|
43
|
-
end
|
44
|
-
|
45
|
-
def put(key, value)
|
46
|
-
@redis.set(key, value)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|