colloquy 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/README.md +160 -0
- data/TODO.md +256 -0
- data/bin/colloquy +14 -0
- data/examples/config/flows.yaml +22 -0
- data/examples/config/logger.yaml +2 -0
- data/examples/config/messages.yaml +3 -0
- data/examples/config/mysql.yaml +18 -0
- data/examples/config/redis.yaml +9 -0
- data/examples/config/scribe.yaml +2 -0
- data/examples/config/settings.yaml +2 -0
- data/examples/config/test.yaml +8 -0
- data/examples/config/urls.yaml +18 -0
- data/examples/flows/active_record_flow.rb +42 -0
- data/examples/flows/art_of_war_flow.rb +27 -0
- data/examples/flows/calculator_flow.rb +71 -0
- data/examples/flows/crossover_flow.rb +17 -0
- data/examples/flows/database_flow.rb +33 -0
- data/examples/flows/hangman_flow.rb +82 -0
- data/examples/flows/metadata_flow.rb +11 -0
- data/examples/flows/pagination_flow.rb +23 -0
- data/examples/flows/pass_flow.rb +29 -0
- data/examples/flows/prefix_menu_flow.rb +24 -0
- data/examples/flows/scribe_flow.rb +26 -0
- data/examples/flows/settings_flow.rb +23 -0
- data/examples/flows/special/special_redis_flow.rb +28 -0
- data/examples/flows/url_flow.rb +27 -0
- data/examples/log/renderer.log +198381 -0
- data/examples/log/urls.log +3269 -0
- data/examples/messages/active_record.yaml +2 -0
- data/examples/messages/art_of_war.yaml +1 -0
- data/examples/messages/calculator.yaml +2 -0
- data/examples/messages/database.yaml +1 -0
- data/examples/messages/hangman.yaml +0 -0
- data/examples/messages/prefix_menu.yaml +3 -0
- data/examples/models/activations.rb +5 -0
- data/lib/colloquy.rb +39 -0
- data/lib/colloquy/exceptions.rb +64 -0
- data/lib/colloquy/flow_parser.rb +315 -0
- data/lib/colloquy/flow_pool.rb +21 -0
- data/lib/colloquy/helpers.rb +15 -0
- data/lib/colloquy/helpers/mysql.rb +110 -0
- data/lib/colloquy/helpers/redis.rb +103 -0
- data/lib/colloquy/helpers/scribe.rb +103 -0
- data/lib/colloquy/helpers/settings.rb +111 -0
- data/lib/colloquy/helpers/url.rb +10 -0
- data/lib/colloquy/input.rb +14 -0
- data/lib/colloquy/logger.rb +11 -0
- data/lib/colloquy/menu.rb +128 -0
- data/lib/colloquy/message_builder.rb +54 -0
- data/lib/colloquy/node.rb +67 -0
- data/lib/colloquy/paginator.rb +59 -0
- data/lib/colloquy/paginator/menu.rb +79 -0
- data/lib/colloquy/paginator/prompt.rb +32 -0
- data/lib/colloquy/prompt.rb +35 -0
- data/lib/colloquy/renderer.rb +423 -0
- data/lib/colloquy/response.rb +4 -0
- data/lib/colloquy/runner.rb +93 -0
- data/lib/colloquy/server.rb +157 -0
- data/lib/colloquy/session_store.rb +46 -0
- data/lib/colloquy/session_store/memory.rb +14 -0
- data/lib/colloquy/session_store/redis.rb +24 -0
- data/lib/colloquy/simulator.rb +114 -0
- data/lib/colloquy/spec_helpers.rb +21 -0
- metadata +459 -0
@@ -0,0 +1,15 @@
|
|
1
|
+
|
2
|
+
module Colloquy::Helpers
|
3
|
+
require_relative 'helpers/url'
|
4
|
+
require_relative 'helpers/mysql'
|
5
|
+
require_relative 'helpers/redis'
|
6
|
+
require_relative 'helpers/scribe'
|
7
|
+
require_relative 'helpers/settings'
|
8
|
+
|
9
|
+
include Colloquy::Helpers::Url
|
10
|
+
include Colloquy::Helpers::MySQL
|
11
|
+
include Colloquy::Helpers::Redis
|
12
|
+
include Colloquy::Helpers::Scribe
|
13
|
+
include Colloquy::Helpers::Settings
|
14
|
+
end
|
15
|
+
|
@@ -0,0 +1,110 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
require 'yaml'
|
3
|
+
require 'active_support/core_ext/hash'
|
4
|
+
|
5
|
+
class Colloquy::MySQLConfigurationNotFoundException < Exception
|
6
|
+
end
|
7
|
+
|
8
|
+
class Colloquy::MySQLGemsNotFoundException < Exception
|
9
|
+
end
|
10
|
+
|
11
|
+
class Colloquy::MySQLConnectionNotFoundException < Exception
|
12
|
+
end
|
13
|
+
|
14
|
+
module Colloquy::Helpers::MySQL
|
15
|
+
def self.included(klass)
|
16
|
+
klass.class_eval do
|
17
|
+
include InstanceMethods
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
class MySQLProxy
|
22
|
+
DEFAULT_OPTIONS = { :host => "localhost", :port => 3306, :socket => "/tmp/mysql.sock", :username => "root", :password => "", :reconnect => true, :pool => 5}
|
23
|
+
|
24
|
+
include Singleton
|
25
|
+
|
26
|
+
def initialize
|
27
|
+
@configured = false
|
28
|
+
end
|
29
|
+
|
30
|
+
def configure
|
31
|
+
return if configured?
|
32
|
+
configure!
|
33
|
+
end
|
34
|
+
|
35
|
+
def configure!
|
36
|
+
unless mysql_configuration_file.exist?
|
37
|
+
raise Colloquy::MySQLConfigurationNotFoundException, "Cannot find #{mysql_configuration_file}"
|
38
|
+
end
|
39
|
+
|
40
|
+
begin
|
41
|
+
require_mysql_libraries
|
42
|
+
rescue LoadError
|
43
|
+
raise Colloquy::MySQLGemsNotFoundException, "Cannot load the mysql2 gem."
|
44
|
+
end
|
45
|
+
|
46
|
+
@mysql_db_connections ||= {}
|
47
|
+
mysql_configuration_load
|
48
|
+
|
49
|
+
@configured = true
|
50
|
+
end
|
51
|
+
|
52
|
+
def configured?
|
53
|
+
@configured
|
54
|
+
end
|
55
|
+
|
56
|
+
def require_mysql_libraries
|
57
|
+
require "em-synchrony/mysql2"
|
58
|
+
end
|
59
|
+
|
60
|
+
def [](identifier)
|
61
|
+
unless @mysql_db_connections[identifier.to_sym]
|
62
|
+
raise Colloquy::MySQLConnectionNotFoundException, "A connection for #{identifier} was not found, did you mis-spell or forget to configure it?"
|
63
|
+
end
|
64
|
+
|
65
|
+
@mysql_db_connections[identifier.to_sym]
|
66
|
+
end
|
67
|
+
|
68
|
+
def configuration
|
69
|
+
@mysql_configuration_entries
|
70
|
+
end
|
71
|
+
|
72
|
+
private
|
73
|
+
|
74
|
+
def mysql_configuration_file
|
75
|
+
Colloquy.root.join('config', 'mysql.yaml')
|
76
|
+
end
|
77
|
+
|
78
|
+
def mysql_configuration_load
|
79
|
+
return unless mysql_configuration_exists?
|
80
|
+
|
81
|
+
@mysql_configuration_entries = File.open(mysql_configuration_file, "r") { |f| YAML.load(f.read) }
|
82
|
+
@mysql_configuration_entries.to_options!
|
83
|
+
|
84
|
+
if @mysql_configuration_entries
|
85
|
+
@mysql_configuration_entries.each do |identifier, params|
|
86
|
+
params.to_options!.merge!(DEFAULT_OPTIONS) { |key, v1, v2| v1 }
|
87
|
+
@mysql_db_connections[identifier.to_sym] = mysql_connection(params)
|
88
|
+
end
|
89
|
+
else
|
90
|
+
raise Colloquy::MySQLConfigurationNotFoundException, "Cannot find configuration in #{mysql_configuration_file}. Is it empty?"
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def mysql_connection(params)
|
95
|
+
Mysql2::EM::Client.new(params)
|
96
|
+
end
|
97
|
+
|
98
|
+
def mysql_configuration_exists?
|
99
|
+
mysql_configuration_file.exist?
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
module InstanceMethods
|
104
|
+
def mysql
|
105
|
+
MySQLProxy.instance.configure
|
106
|
+
|
107
|
+
MySQLProxy.instance
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
class Colloquy::RedisConfigurationNotFoundException < Exception
|
5
|
+
end
|
6
|
+
|
7
|
+
class Colloquy::RedisGemsNotFoundException < Exception
|
8
|
+
end
|
9
|
+
|
10
|
+
class Colloquy::RedisConnectionNotFoundException < Exception
|
11
|
+
end
|
12
|
+
|
13
|
+
module Colloquy::Helpers::Redis
|
14
|
+
def self.included(klass)
|
15
|
+
klass.class_eval do
|
16
|
+
include InstanceMethods
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
class RedisProxy
|
21
|
+
include Singleton
|
22
|
+
|
23
|
+
def initialize
|
24
|
+
@configured = false
|
25
|
+
end
|
26
|
+
|
27
|
+
def configure
|
28
|
+
return if configured?
|
29
|
+
configure!
|
30
|
+
end
|
31
|
+
|
32
|
+
def configure!
|
33
|
+
unless redis_configuration_file.exist?
|
34
|
+
raise Colloquy::RedisConfigurationNotFoundException, "Cannot find #{redis_configuration_file}"
|
35
|
+
end
|
36
|
+
|
37
|
+
begin
|
38
|
+
require_redis_libraries
|
39
|
+
rescue LoadError
|
40
|
+
raise Colloquy::RedisGemsNotFoundException, "Cannot load the em-redis gem."
|
41
|
+
end
|
42
|
+
|
43
|
+
@redis_connections ||= {}
|
44
|
+
redis_configuration_load
|
45
|
+
|
46
|
+
@configured = true
|
47
|
+
end
|
48
|
+
|
49
|
+
def configured?
|
50
|
+
@configured
|
51
|
+
end
|
52
|
+
|
53
|
+
def require_redis_libraries
|
54
|
+
require "em-redis"
|
55
|
+
require "em-synchrony"
|
56
|
+
require "em-synchrony/em-redis"
|
57
|
+
end
|
58
|
+
|
59
|
+
def [](identifier)
|
60
|
+
unless @redis_connections[identifier.to_sym]
|
61
|
+
raise Colloquy::RedisConnectionNotFoundException, "A Redis connection for #{identifier} was not found, did you mis-spell or forget to configure it?"
|
62
|
+
end
|
63
|
+
|
64
|
+
@redis_connections[identifier.to_sym]
|
65
|
+
end
|
66
|
+
|
67
|
+
private
|
68
|
+
|
69
|
+
def redis_configuration_file
|
70
|
+
Colloquy.root.join('config', 'redis.yaml')
|
71
|
+
end
|
72
|
+
|
73
|
+
def redis_configuration_load
|
74
|
+
return unless redis_configuration_exists?
|
75
|
+
|
76
|
+
redis_configuration = File.open(redis_configuration_file, "r") { |f| YAML.load(f.read) }
|
77
|
+
|
78
|
+
if redis_configuration
|
79
|
+
redis_configuration.each do |identifier, params|
|
80
|
+
@redis_connections[identifier.to_sym] = redis_connection(params.to_options)
|
81
|
+
end
|
82
|
+
else
|
83
|
+
raise Colloquy::RedisConfigurationNotFoundException, "Cannot find configuration in #{redis_configuration_file}. Is it empty?"
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def redis_connection(params = {})
|
88
|
+
EM::Protocols::Redis.connect(params)
|
89
|
+
end
|
90
|
+
|
91
|
+
def redis_configuration_exists?
|
92
|
+
redis_configuration_file.exist?
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
module InstanceMethods
|
97
|
+
def redis
|
98
|
+
RedisProxy.instance.configure
|
99
|
+
|
100
|
+
RedisProxy.instance
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
class Colloquy::ScribeConfigurationNotFoundException < Exception
|
5
|
+
end
|
6
|
+
|
7
|
+
class Colloquy::ScribeGemsNotFoundException < Exception
|
8
|
+
end
|
9
|
+
|
10
|
+
class Colloquy::ScribeConnectionNotFoundException < Exception
|
11
|
+
end
|
12
|
+
|
13
|
+
module Colloquy::Helpers::Scribe
|
14
|
+
def self.included(klass)
|
15
|
+
klass.class_eval do
|
16
|
+
include InstanceMethods
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
class ScribeProxy
|
21
|
+
include Singleton
|
22
|
+
|
23
|
+
def initialize
|
24
|
+
@configured = false
|
25
|
+
end
|
26
|
+
|
27
|
+
def configure
|
28
|
+
return if configured?
|
29
|
+
configure!
|
30
|
+
end
|
31
|
+
|
32
|
+
def configure!
|
33
|
+
unless scribe_configuration_file.exist?
|
34
|
+
raise Colloquy::ScribeConfigurationNotFoundException, "Cannot find #{scribe_configuration_file}"
|
35
|
+
end
|
36
|
+
|
37
|
+
begin
|
38
|
+
require_scribe_libraries
|
39
|
+
rescue LoadError
|
40
|
+
raise Colloquy::ScribeGemsNotFoundException, "Cannot load the scribe gem."
|
41
|
+
end
|
42
|
+
|
43
|
+
@scribe_connections ||= {}
|
44
|
+
scribe_configuration_load
|
45
|
+
|
46
|
+
@configured = true
|
47
|
+
end
|
48
|
+
|
49
|
+
def configured?
|
50
|
+
@configured
|
51
|
+
end
|
52
|
+
|
53
|
+
def connections
|
54
|
+
@scribe_connections
|
55
|
+
end
|
56
|
+
|
57
|
+
def [](identifier)
|
58
|
+
unless @scribe_connections[identifier.to_sym]
|
59
|
+
raise Colloquy::ScribeConnectionNotFoundException, "A connection for #{identifier} was not found, did you mis-spell or forget to configure it?"
|
60
|
+
end
|
61
|
+
|
62
|
+
@scribe_connections[identifier.to_sym]
|
63
|
+
end
|
64
|
+
|
65
|
+
def require_scribe_libraries
|
66
|
+
require 'scribe-logger'
|
67
|
+
end
|
68
|
+
|
69
|
+
def scribe_configuration_file
|
70
|
+
Colloquy.root.join('config', 'scribe.yaml')
|
71
|
+
end
|
72
|
+
|
73
|
+
def scribe_configuration_load
|
74
|
+
return unless scribe_configuration_exists?
|
75
|
+
|
76
|
+
scribe_configuration = File.open(scribe_configuration_file, "r") { |f| YAML.load(f.read) }
|
77
|
+
|
78
|
+
if scribe_configuration
|
79
|
+
scribe_configuration.each do |identifier, params|
|
80
|
+
@scribe_connections[identifier.to_sym] = scribe_connection(params)
|
81
|
+
end
|
82
|
+
else
|
83
|
+
raise Colloquy::ScribeConfigurationNotFoundException, "Cannot find configuration in #{scribe_configuration_file}. Is it empty?"
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def scribe_connection(params)
|
88
|
+
Scribe.loggers(params)
|
89
|
+
end
|
90
|
+
|
91
|
+
def scribe_configuration_exists?
|
92
|
+
scribe_configuration_file.exist?
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
module InstanceMethods
|
97
|
+
def scribe
|
98
|
+
ScribeProxy.instance.configure
|
99
|
+
ScribeProxy.instance
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
@@ -0,0 +1,111 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
class Colloquy::SettingsConfigurationNotFoundException < Exception
|
5
|
+
end
|
6
|
+
|
7
|
+
class Colloquy::SettingsGemsNotFoundException < Exception
|
8
|
+
end
|
9
|
+
|
10
|
+
module Colloquy::Helpers::Settings
|
11
|
+
def self.included(klass)
|
12
|
+
klass.class_eval do
|
13
|
+
include InstanceMethods
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class SettingsProxy
|
18
|
+
include Singleton
|
19
|
+
|
20
|
+
def configure
|
21
|
+
return if configured?
|
22
|
+
configure!
|
23
|
+
end
|
24
|
+
|
25
|
+
def configured?
|
26
|
+
@configured
|
27
|
+
end
|
28
|
+
|
29
|
+
def configure!
|
30
|
+
unless settings_configuration_file.exist?
|
31
|
+
raise Colloquy::SettingsConfigurationNotFoundException, "Cannot find #{settings_configuration_file}"
|
32
|
+
end
|
33
|
+
|
34
|
+
begin
|
35
|
+
require_settings_libraries
|
36
|
+
rescue LoadError
|
37
|
+
raise Colloquy::SettingsGemsNotFoundException, "Cannot load the required settings gems."
|
38
|
+
end
|
39
|
+
|
40
|
+
@settings_configurations ||= {}
|
41
|
+
settings_configuration_load
|
42
|
+
|
43
|
+
@configured = true
|
44
|
+
end
|
45
|
+
|
46
|
+
def settings_configuration_file
|
47
|
+
Colloquy.root.join('config', 'settings.yaml')
|
48
|
+
end
|
49
|
+
|
50
|
+
def require_settings_libraries
|
51
|
+
require "yaml"
|
52
|
+
end
|
53
|
+
|
54
|
+
def settings_configuration_load
|
55
|
+
return unless settings_configuration_exists?
|
56
|
+
|
57
|
+
@settings_configuration_entries = File.open(settings_configuration_file, "r") { |f| YAML.load(f.read) }
|
58
|
+
|
59
|
+
if @settings_configuration_entries
|
60
|
+
@settings_configuration_entries.each do |identifier, params|
|
61
|
+
@settings_configurations[identifier.to_sym] = settings_configuration(params)
|
62
|
+
end
|
63
|
+
else
|
64
|
+
raise Colloquy::SettingsConfigurationNotFoundException, "Cannot find configuration in #{settings_configuration_file}. Is it empty?"
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def settings_configuration_exists?
|
69
|
+
settings_configuration_file.exist?
|
70
|
+
end
|
71
|
+
|
72
|
+
def [](identifier)
|
73
|
+
unless @settings_configurations[identifier.to_sym]
|
74
|
+
raise Colloquy::SettingsFileNotFoundException, "A settings file for #{identifier} was not found, did you mis-spell or forget to configure it?"
|
75
|
+
end
|
76
|
+
|
77
|
+
@settings_configurations[identifier.to_sym]
|
78
|
+
end
|
79
|
+
|
80
|
+
def settings_configuration(params)
|
81
|
+
begin
|
82
|
+
if params[0] == "/"
|
83
|
+
yaml = YAML::load(File.open(params))
|
84
|
+
else
|
85
|
+
yaml = YAML::load(File.open(Colloquy.root.join(params)))
|
86
|
+
end
|
87
|
+
rescue Errno::ENOENT => e
|
88
|
+
logger.error "File not found: #{params}"
|
89
|
+
return {}
|
90
|
+
rescue Psych::SyntaxError => e
|
91
|
+
logger.error "File #{params} is not valid YAML"
|
92
|
+
return {}
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
def logger
|
97
|
+
Colloquy.logger
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
101
|
+
|
102
|
+
|
103
|
+
module InstanceMethods
|
104
|
+
def settings
|
105
|
+
SettingsProxy.instance.configure
|
106
|
+
|
107
|
+
SettingsProxy.instance
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|