Module: Journal
- Defined in:
- lib/journal.rb,
lib/journal/handler.rb,
lib/journal/version.rb,
lib/journal/rack/reloader.rb
Defined Under Namespace
Modules: Rack
Constant Summary collapse
- VERSION =
'0.0.7'
- @@_ran_once =
false
- @@_redis_on =
false
Class Method Summary collapse
- .last(key, _count = 1) ⇒ Object
- .load_and_set_settings! ⇒ Object
- .log(key, data, score) ⇒ Object
- .purge(key, timestamp) ⇒ Object
- .redis ⇒ Object
- .setup {|_self| ... } ⇒ Object
Class Method Details
.last(key, _count = 1) ⇒ Object
6 7 8 9 10 11 12 |
# File 'lib/journal/handler.rb', line 6 def self.last(key, _count = 1) if redis.zcount(key, "-inf", "+inf") > 0 return JournalEntry.new(key, redis.zrange(key, -1, -1).first) unless _count > 1 return JournalEntry.from_array(key, redis.zrange(key, _count * -1, -1).reverse) end return Array.new end |
.load_and_set_settings! ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/journal.rb', line 22 def self.load_and_set_settings! Kernel.send(:remove_const, 'JOURNAL_HOST') if Kernel.const_defined?('JOURNAL_HOST') Kernel.const_set('JOURNAL_HOST', Journal.host) Kernel.send(:remove_const, 'JOURNAL_PORT') if Kernel.const_defined?('JOURNAL_PORT') Kernel.const_set('JOURNAL_PORT', Journal.port) Kernel.send(:remove_const, 'JOURNAL_EXPIRY') if Kernel.const_defined?('JOURNAL_EXPIRY') Kernel.const_set('JOURNAL_EXPIRY', Journal.expiry) Kernel.send(:remove_const, 'JOURNAL_PASSWORD') if Kernel.const_defined?('JOURNAL_PASSWORD') Kernel.const_set('JOURNAL_PASSWORD', Journal.password) end |
.log(key, data, score) ⇒ Object
2 3 4 |
# File 'lib/journal/handler.rb', line 2 def self.log(key, data, score) return redis.zadd(key, score, "#{data}@#{score}") end |
.purge(key, timestamp) ⇒ Object
14 15 16 |
# File 'lib/journal/handler.rb', line 14 def self.purge(key, ) return @@redis.zremrangebyscore(key, "-inf", "(#{}") end |
.redis ⇒ Object
33 34 35 36 |
# File 'lib/journal.rb', line 33 def self.redis return @@redis if @@_redis_on @@redis = Redis.new(:host => Journal.host, :port => Journal.port || 6379, :password => Journal.password) end |
.setup {|_self| ... } ⇒ Object
17 18 19 20 |
# File 'lib/journal.rb', line 17 def self.setup yield self if @@_ran_once == false @@_ran_once = true end |