Class: Peastash
- Inherits:
-
Object
show all
- Defined in:
- lib/peastash.rb,
lib/peastash/version.rb,
lib/peastash/middleware.rb,
lib/peastash/outputs/io.rb,
lib/peastash/rails_ext/watch.rb,
lib/peastash/rails_ext/railtie.rb
Defined Under Namespace
Modules: Outputs, Watch
Classes: Middleware, Railtie
Constant Summary
collapse
- STORE_NAME =
'peastash'
- VERSION =
"0.0.9"
- @@instance_cache =
ThreadSafe::Cache.new
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(instance_name) ⇒ Peastash
Returns a new instance of Peastash.
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/peastash.rb', line 46
def initialize(instance_name)
@instance_name = instance_name
@configuration = {
:source => STORE_NAME,
:tags => [],
:output => Outputs::IO.new(Outputs::IO::default_io),
:store_name => STORE_NAME,
:dump_if_empty => true
}
configure!(@@instance_cache[:global].configuration || {}) if @@instance_cache[:global]
end
|
Instance Attribute Details
#configuration ⇒ Object
Returns the value of attribute configuration.
42
43
44
|
# File 'lib/peastash.rb', line 42
def configuration
@configuration
end
|
#instance_name ⇒ Object
Returns the value of attribute instance_name.
41
42
43
|
# File 'lib/peastash.rb', line 41
def instance_name
@instance_name
end
|
Class Method Details
12
13
14
|
# File 'lib/peastash.rb', line 12
def configure!(conf = {})
with_instance.configure!(conf)
end
|
.safe! ⇒ Object
31
32
33
|
# File 'lib/peastash.rb', line 31
def safe!
@unsafe = false
end
|
.safe? ⇒ Boolean
27
28
29
|
# File 'lib/peastash.rb', line 27
def safe?
!@unsafe
end
|
.safely ⇒ Object
20
21
22
23
24
25
|
# File 'lib/peastash.rb', line 20
def safely
yield
rescue StandardError => e
STDERR.puts e
raise e unless safe?
end
|
.unsafe! ⇒ Object
35
36
37
|
# File 'lib/peastash.rb', line 35
def unsafe!
@unsafe = true
end
|
.with_instance(instance_name = :global) ⇒ Object
16
17
18
|
# File 'lib/peastash.rb', line 16
def with_instance(instance_name = :global)
@@instance_cache[instance_name] ||= Peastash.new(instance_name)
end
|
Instance Method Details
65
66
67
68
69
70
71
72
73
|
# File 'lib/peastash.rb', line 65
def configure!(conf = {})
self.configuration.merge!(conf)
@source = configuration[:source]
@base_tags = configuration[:tags].flatten
@output = configuration[:output]
@store_name = configuration[:store_name]
@dump_if_empty = configuration[:dump_if_empty]
@configured = true
end
|
#enabled? ⇒ Boolean
99
100
101
|
# File 'lib/peastash.rb', line 99
def enabled?
!!configuration[:enabled]
end
|
#instance ⇒ Object
103
104
105
|
# File 'lib/peastash.rb', line 103
def instance
@@instance_cache[instance_name]
end
|
#log(additional_tags = []) {|instance| ... } ⇒ Object
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
# File 'lib/peastash.rb', line 75
def log(additional_tags = [])
Peastash.safely do
configure! unless configured?
tags.replace(additional_tags)
store.clear
end
yield(instance)
Peastash.safely do
if enabled? && (!store.empty? || dump_if_empty?)
event = build_event(@source, tags)
@output.dump(event)
end
end
end
|
#store ⇒ Object
60
61
62
63
|
# File 'lib/peastash.rb', line 60
def store
Thread.current[instance_name] ||= Hash.new
Thread.current[instance_name][@store_name] ||= Hash.new { |hash, key| hash[key] = {} }
end
|
92
93
94
95
96
97
|
# File 'lib/peastash.rb', line 92
def tags
Peastash.safely do
configure! unless configured?
Thread.current[@store_name + ":tags"] ||= []
end
end
|