Module: EventStore
- Defined in:
- lib/event_store.rb,
lib/event_store/client.rb,
lib/event_store/errors.rb,
lib/event_store/version.rb,
lib/event_store/aggregate.rb,
lib/event_store/time_hacker.rb,
lib/event_store/event_appender.rb
Defined Under Namespace
Classes: Aggregate, AttributeMissingError, Client, ConcurrencyError, Event, EventAppender, SerializedEvent, TimeHacker
Constant Summary
collapse
- SNAPSHOT_DELIMITER =
"__NexEvStDelim__"
- VERSION =
"0.2.9"
Class Method Summary
collapse
Class Method Details
.clear! ⇒ Object
70
71
72
73
74
|
# File 'lib/event_store.rb', line 70
def self.clear!
return unless connected?
EventStore.db.from(fully_qualified_table).delete
EventStore.redis.flushdb
end
|
.connect(*args) ⇒ Object
42
43
44
|
# File 'lib/event_store.rb', line 42
def self.connect(*args)
@db ||= Sequel.connect(*args)
end
|
.connected? ⇒ Boolean
66
67
68
|
# File 'lib/event_store.rb', line 66
def self.connected?
!!EventStore.db
end
|
.create_db ⇒ Object
126
127
128
129
130
131
|
# File 'lib/event_store.rb', line 126
def self.create_db
self.connect(@db_config)
schema_exits = @db.table_exists?("#{schema}__schema_info".to_sym)
@db.run "CREATE SCHEMA #{EventStore.schema};" unless schema_exits
Sequel::Migrator.run(@db, File.expand_path(File.join('..','..','db', self.migrations_dir), __FILE__), :table=> "#{schema}__schema_info".to_sym)
end
|
.custom_config(database_config, redis_config, table_name = 'events', environment = 'production') ⇒ Object
109
110
111
112
113
114
115
116
117
118
119
120
|
# File 'lib/event_store.rb', line 109
def self.custom_config(database_config, redis_config, table_name = 'events', environment = 'production')
self.redis_connect(redis_config)
database_config = database_config.inject({}) {|memo, (k,v)| memo[k.to_s] = v; memo}
redis_config = redis_config.inject({}) {|memo, (k,v)| memo[k.to_s] = v; memo}
@adapter = database_config['adapter'].to_s
@environment = environment
@db_config = database_config
@table_name = table_name
@schema = database_config['schema'].to_s
create_db
end
|
.db ⇒ Object
34
35
36
|
# File 'lib/event_store.rb', line 34
def self.db
@db
end
|
.db_config ⇒ Object
20
21
22
|
# File 'lib/event_store.rb', line 20
def self.db_config
raw_db_config[@environment.to_s][@adapter.to_s]
end
|
.escape_bytea(binary_string) ⇒ Object
101
102
103
|
# File 'lib/event_store.rb', line 101
def self.escape_bytea(binary_string)
binary_string.unpack('H*').join
end
|
.fully_qualified_table ⇒ Object
62
63
64
|
# File 'lib/event_store.rb', line 62
def self.fully_qualified_table
@fully_qualified_table ||= Sequel.lit "#{schema}.#{table_name}"
end
|
.local_redis_config ⇒ Object
50
51
52
|
# File 'lib/event_store.rb', line 50
def self.local_redis_config
@redis_connection ||= raw_db_config['redis']
end
|
.migrations_dir ⇒ Object
122
123
124
|
# File 'lib/event_store.rb', line 122
def self.migrations_dir
@adapter == 'vertica' ? 'migrations' : 'pg_migrations'
end
|
.postgres(environment = 'test', table_name = 'events', schema = 'event_store_test') ⇒ Object
76
77
78
79
80
81
82
83
|
# File 'lib/event_store.rb', line 76
def self.postgres(environment = 'test', table_name = 'events', schema = 'event_store_test')
@schema = schema
@table_name = table_name
@environment = environment.to_s
@adapter = 'postgres'
@db_config ||= self.db_config
custom_config(@db_config, local_redis_config, @table_name, environment)
end
|
.raw_db_config ⇒ Object
24
25
26
27
28
29
30
31
32
|
# File 'lib/event_store.rb', line 24
def self.raw_db_config
if @raw_db_config.nil?
file_path = File.expand_path(__FILE__ + '/../../db/database.yml')
@config_file = File.open(file_path,'r')
@raw_db_config = YAML.load(@config_file)
@config_file.close
end
@raw_db_config
end
|
.redis ⇒ Object
38
39
40
|
# File 'lib/event_store.rb', line 38
def self.redis
@redis
end
|
.redis_connect(config_hash) ⇒ Object
46
47
48
|
# File 'lib/event_store.rb', line 46
def self.redis_connect(config_hash)
@redis ||= Redis.new(config_hash)
end
|
.schema ⇒ Object
54
55
56
|
# File 'lib/event_store.rb', line 54
def self.schema
@schema ||= raw_db_config[@environment][@adapter]['schema']
end
|
.table_name ⇒ Object
58
59
60
|
# File 'lib/event_store.rb', line 58
def self.table_name
@table_name ||= raw_db_config['table_name']
end
|
.unescape_bytea(binary_string) ⇒ Object
105
106
107
|
# File 'lib/event_store.rb', line 105
def self.unescape_bytea(binary_string)
[binary_string].pack("H*")
end
|
.vertica(environment = 'test', table_name = 'events', schema = 'event_store_test') ⇒ Object
To find the ip address of vertica on your local box (running in a vm)
-
open Settings -> Network and select Wi-Fi
-
open a terminal in the VM
-
do /sbin/ifconfig (ifconfig is not in $PATH)
-
the inet address for en0 is what you want
Hint: if it just hangs, you have have the wrong IP
91
92
93
94
95
96
97
98
99
|
# File 'lib/event_store.rb', line 91
def self.vertica(environment = 'test', table_name = 'events', schema = 'event_store_test')
@schema = schema
@table_name = table_name
@environment = environment.to_s
@adapter = 'vertica'
@db_config ||= self.db_config
@db_config['host'] ||= ENV['VERTICA_HOST'] || vertica_host
custom_config(@db_config, local_redis_config, @table_name, environment)
end
|
.vertica_host ⇒ Object
133
134
135
|
# File 'lib/event_store.rb', line 133
def self.vertica_host
File.read File.expand_path(File.join('..','..','db', 'vertica_host_address.txt'), __FILE__)
end
|