Class: KM
- Inherits:
-
Object
show all
- Defined in:
- lib/km.rb,
lib/km/saas.rb,
lib/km/version.rb
Defined Under Namespace
Modules: SaaS
Classes: IdentError, InitError
Constant Summary
collapse
- VERSION =
"1.1.2"
Class Method Summary
collapse
Class Method Details
.alias(name, alias_to) ⇒ Object
67
68
69
70
71
72
73
74
|
# File 'lib/km.rb', line 67
def alias(name, alias_to)
begin
return unless is_initialized?
generate_query('a', { '_n' => alias_to, '_p' => name }, false)
rescue Exception => e
log_error(e)
end
end
|
.host ⇒ Object
112
113
114
|
# File 'lib/km.rb', line 112
def host
@host
end
|
.identify(id) ⇒ Object
50
51
52
|
# File 'lib/km.rb', line 50
def identify(id)
@id = id
end
|
.init(key, options = {}) ⇒ Object
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/km.rb', line 21
def init(key, options={})
default = {
:host => @host,
:log_dir => @log_dir,
:to_stderr => @to_stderr,
:use_cron => @use_cron,
:env => set_env,
}
options = default.merge(options)
begin
@key = key
@host = options[:host]
@log_dir = options[:log_dir]
@use_cron = options[:use_cron]
@to_stderr = options[:to_stderr]
@env = options[:env]
log_dir_writable?
rescue Exception => e
log_error(e)
end
end
|
.log_dir ⇒ Object
109
110
111
|
# File 'lib/km.rb', line 109
def log_dir
@log_dir
end
|
.record(action, props = {}) ⇒ Object
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/km.rb', line 54
def record(action,props={})
props = hash_keys_to_str(props)
begin
return unless is_initialized_and_identified?
return set(action) if action.class == Hash
props.update('_n' => action)
generate_query('e', props)
rescue Exception => e
log_error(e)
end
end
|
.send_logged_queries ⇒ Object
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
# File 'lib/km.rb', line 85
def send_logged_queries line = nil
begin
query_log = log_name(:query_old)
query_log = log_name(:query) unless File.exists?(query_log)
return unless File.exists?(query_log) FileUtils.move(query_log, log_name(:send))
File.open(log_name(:send)) do |fh|
while not fh.eof?
begin
line = fh.readline.chomp
send_query(line)
rescue Exception => e
log_query(line) if line
log_error(e)
end
end
end
FileUtils.rm(log_name(:send))
rescue Exception => e
log_error(e)
end
end
|
.set(data) ⇒ Object
76
77
78
79
80
81
82
83
|
# File 'lib/km.rb', line 76
def set(data)
begin
return unless is_initialized_and_identified?
generate_query('s', data)
rescue Exception => e
log_error(e)
end
end
|
.set_env ⇒ Object
44
45
46
47
48
|
# File 'lib/km.rb', line 44
def set_env
@env = Rails.env if defined? Rails
@env ||= ENV['RACK_ENV']
@env ||= 'production'
end
|