Class: GrayLogger::Bucket

Inherits:
Hash
  • Object
show all
Defined in:
lib/gray_logger/bucket.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, args, &block) ⇒ Object (protected)



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/gray_logger/bucket.rb', line 17

def method_missing(method_name, args, &block)
  if method_name.to_s.end_with?("=")

    # def method_name=(value)
    #   self[:method_name] = value
    # end
    instance_eval <<-EOMEVAL
      def #{method_name}(value)
        self[:#{method_name.to_s.chop}] = value
      end
    EOMEVAL

    send(method_name, args)
  else
    super
  end
end

Instance Method Details

#append_to(field_name, value) ⇒ Object



11
12
13
14
# File 'lib/gray_logger/bucket.rb', line 11

def append_to(field_name, value)
  self[field_name.to_sym] ||= ""
  self[field_name.to_sym] << "#{value}\n"
end

#to_message(name = nil) ⇒ Object



6
7
8
9
# File 'lib/gray_logger/bucket.rb', line 6

def to_message(name=nil)
  self[:gray_logger_bucket] = name if name
  GrayLogger::Message.new(self)
end