module ActiveModel::LoggerAttributes::ClassMethods
Public Instance Methods
define_logger_attr_accessor(attribute)
click to toggle source
# File lib/active_model/logger_attributes.rb, line 40 def define_logger_attr_accessor(attribute) options = @logger_attributes[attribute] define_method(options[:logger_name]) do instance_variable_get(:"@#{options[:logger_name]}") || send(:"initialize_#{options[:logger_name]}") end end
define_logger_attr_initializer(attribute)
click to toggle source
# File lib/active_model/logger_attributes.rb, line 31 def define_logger_attr_initializer(attribute) options = @logger_attributes[attribute] define_method(:"initialize_#{options[:logger_name]}") do define_attr_logger_attribute(attribute) logger = logger_for_logger_attribute(attribute, options[:logger_class], &options[:logger_init]) instance_variable_set :"@#{options[:logger_name]}", logger end end
logger_attr(attribute, options = {})
click to toggle source
# File lib/active_model/logger_attributes.rb, line 25 def logger_attr(attribute, options = {}) attribute = attribute.to_sym setup_logger_attr(attribute, options) attr_accessor(attribute) end
logger_attr_default_options()
click to toggle source
# File lib/active_model/logger_attributes.rb, line 13 def logger_attr_default_options { logger_class: ::Logger, logger_name: nil, logger_init: ->(l) {} } end
setup_logger_attr(attribute, options)
click to toggle source
# File lib/active_model/logger_attributes.rb, line 17 def setup_logger_attr(attribute, options) @logger_attributes ||= {} @logger_attributes[attribute] = logger_attr_default_options.merge(options) @logger_attributes[attribute][:logger_name] ||= "#{attribute}_logger" define_logger_attr_initializer(attribute) define_logger_attr_accessor(attribute) end