Module: ActiveModel::LoggerAttributes::ClassMethods
- Defined in:
- lib/active_model/logger_attributes.rb
Instance Method Summary collapse
- #define_logger_attr_accessor(attribute) ⇒ Object
- #define_logger_attr_initializer(attribute) ⇒ Object
- #logger_attr(attribute, options = {}) ⇒ Object
- #logger_attr_default_options ⇒ Object
- #setup_logger_attr(attribute, options) ⇒ Object
Instance Method Details
#define_logger_attr_accessor(attribute) ⇒ Object
40 41 42 43 44 45 |
# File 'lib/active_model/logger_attributes.rb', line 40 def define_logger_attr_accessor(attribute) = @logger_attributes[attribute] define_method([:logger_name]) do instance_variable_get(:"@#{[:logger_name]}") || send(:"initialize_#{[:logger_name]}") end end |
#define_logger_attr_initializer(attribute) ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/active_model/logger_attributes.rb', line 31 def define_logger_attr_initializer(attribute) = @logger_attributes[attribute] define_method(:"initialize_#{[:logger_name]}") do define_attr_logger_attribute(attribute) logger = logger_for_logger_attribute(attribute, [:logger_class], &[:logger_init]) instance_variable_set :"@#{[:logger_name]}", logger end end |
#logger_attr(attribute, options = {}) ⇒ Object
25 26 27 28 29 |
# File 'lib/active_model/logger_attributes.rb', line 25 def logger_attr(attribute, = {}) attribute = attribute.to_sym setup_logger_attr(attribute, ) attr_accessor(attribute) end |
#logger_attr_default_options ⇒ Object
13 14 15 |
# File 'lib/active_model/logger_attributes.rb', line 13 def { logger_class: ::Logger, logger_name: nil, logger_init: ->(l) {} } end |
#setup_logger_attr(attribute, options) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/active_model/logger_attributes.rb', line 17 def setup_logger_attr(attribute, ) @logger_attributes ||= {} @logger_attributes[attribute] = .merge() @logger_attributes[attribute][:logger_name] ||= "#{attribute}_logger" define_logger_attr_initializer(attribute) define_logger_attr_accessor(attribute) end |