Class: GrayLogger::MessageStore
- Inherits:
-
Object
- Object
- GrayLogger::MessageStore
- Defined in:
- lib/gray_logger/message_store.rb
Instance Attribute Summary collapse
-
#store ⇒ Object
readonly
Returns the value of attribute store.
Instance Method Summary collapse
-
#add(field_set) ⇒ Object
(also: #<<)
gets a hash with fields.
-
#initialize(store = {}) ⇒ MessageStore
constructor
A new instance of MessageStore.
- #to_message ⇒ Object
Constructor Details
#initialize(store = {}) ⇒ MessageStore
Returns a new instance of MessageStore.
6 7 8 |
# File 'lib/gray_logger/message_store.rb', line 6 def initialize(store={}) @store = store end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, args, &block) ⇒ Object (protected)
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/gray_logger/message_store.rb', line 24 def method_missing(method_name, args, &block) if method_name.to_s.end_with?("=") # def method_name=(value) # @store[:method_name] = value # end instance_eval <<-EOMEVAL def #{method_name}(value) @store[:#{method_name.to_s.chop}] = value end EOMEVAL send(method_name, args) end end |
Instance Attribute Details
#store ⇒ Object (readonly)
Returns the value of attribute store.
4 5 6 |
# File 'lib/gray_logger/message_store.rb', line 4 def store @store end |
Instance Method Details
#add(field_set) ⇒ Object Also known as: <<
gets a hash with fields
11 12 13 14 15 16 |
# File 'lib/gray_logger/message_store.rb', line 11 def add(field_set) field_set.each_pair do |field, value| @store[field.to_sym] = value end @store end |
#to_message ⇒ Object
19 20 21 |
# File 'lib/gray_logger/message_store.rb', line 19 def GrayLogger::Message.new(@store) end |