Class: RSMP::Archive
- Inherits:
-
Object
- Object
- RSMP::Archive
- Includes:
- Inspect
- Defined in:
- lib/rsmp/log/archive.rb
Overview
Archive of log items, which can be messages or info items. All items are timestamped, and stored chronologically.
Class Attribute Summary collapse
-
.index ⇒ Object
Returns the value of attribute index.
Instance Attribute Summary collapse
-
#items ⇒ Object
readonly
Returns the value of attribute items.
Class Method Summary collapse
Instance Method Summary collapse
- #add(item) ⇒ Object
- #by_level(levels) ⇒ Object
-
#initialize(max = 100) ⇒ Archive
constructor
A new instance of Archive.
- #inspect ⇒ Object
- #strings ⇒ Object
Methods included from Inspect
Constructor Details
#initialize(max = 100) ⇒ Archive
Returns a new instance of Archive.
15 16 17 18 |
# File 'lib/rsmp/log/archive.rb', line 15 def initialize(max = 100) @items = [] @max = max end |
Class Attribute Details
.index ⇒ Object
Returns the value of attribute index.
12 13 14 |
# File 'lib/rsmp/log/archive.rb', line 12 def index @index end |
Instance Attribute Details
#items ⇒ Object (readonly)
Returns the value of attribute items.
7 8 9 |
# File 'lib/rsmp/log/archive.rb', line 7 def items @items end |
Class Method Details
.current_index ⇒ Object
41 42 43 |
# File 'lib/rsmp/log/archive.rb', line 41 def self.current_index index end |
.increase_index ⇒ Object
37 38 39 |
# File 'lib/rsmp/log/archive.rb', line 37 def self.increase_index self.index += 1 end |
.prepare_item(item) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/rsmp/log/archive.rb', line 24 def self.prepare_item(item) raise ArgumentError unless item.is_a? Hash cleaned = item.slice(:author, :level, :ip, :port, :site_id, :component, :text, :message, :exception) cleaned[:timestamp] = Clock.now if item[:message] cleaned[:direction] = item[:message].direction cleaned[:component] = item[:message].attributes['cId'] end cleaned end |
Instance Method Details
#add(item) ⇒ Object
53 54 55 56 57 58 59 |
# File 'lib/rsmp/log/archive.rb', line 53 def add(item) item[:index] = RSMP::Archive.increase_index @items << item return unless @items.size > @max @items.shift end |
#by_level(levels) ⇒ Object
45 46 47 |
# File 'lib/rsmp/log/archive.rb', line 45 def by_level(levels) items.select { |item| levels.include? item[:level] } end |
#inspect ⇒ Object
20 21 22 |
# File 'lib/rsmp/log/archive.rb', line 20 def inspect "#<#{self.class.name}:#{object_id}, #{inspector(:@items)}>" end |
#strings ⇒ Object
49 50 51 |
# File 'lib/rsmp/log/archive.rb', line 49 def strings items.map { |item| item[:str] } end |