Module: ActiveModel::LoggerAttributes

Extended by:
ActiveSupport::Concern
Defined in:
lib/active_model/logger_attributes.rb,
lib/active_model/logger_attributes/device.rb,
lib/active_model/logger_attributes/version.rb

Defined Under Namespace

Modules: ClassMethods Classes: Device

Constant Summary collapse

InvalidAttributeValue =
Class.new(RuntimeError)
VERSION =
'0.1.2'.freeze

Instance Method Summary collapse

Instance Method Details

#define_attr_logger_attribute(attribute) ⇒ Object

ensure the attribute itself has been initialized…



57
58
59
60
61
# File 'lib/active_model/logger_attributes.rb', line 57

def define_attr_logger_attribute(attribute)
  instance_variable_set(:"@#{attribute}", []) unless instance_variable_get(:"@#{attribute}")
  return if instance_variable_get(:"@#{attribute}").respond_to?(:<<)
  raise InvalidAttributeValue, "invalid type for attribute #{attribute}: #{send(attribute).class}"
end

#logger_for_logger_attribute(attribute, logger_class, &block) ⇒ Object



48
49
50
51
52
53
54
# File 'lib/active_model/logger_attributes.rb', line 48

def logger_for_logger_attribute(attribute, logger_class, &block)
  device = ActiveModel::LoggerAttributes::Device.new(attribute, self)
  logger_class.new(device).tap do |l|
    l.progname = "#{self.class.name}.#{attribute}" if l.respond_to?(:progname)
    yield l if block_given?
  end
end