Module: ActiveRecord::AttributeDecorators::ClassMethods

Defined in:
lib/active_record/attribute_decorators.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#decorate_attribute_type(column_name, decorator_name, &block) ⇒ Object



11
12
13
14
15
# File 'lib/active_record/attribute_decorators.rb', line 11

def decorate_attribute_type(column_name, decorator_name, &block)
  matcher = ->(name, _) { name == column_name.to_s }
  key = "_#{column_name}_#{decorator_name}"
  decorate_matching_attribute_types(matcher, key, &block)
end

#decorate_matching_attribute_types(matcher, decorator_name, &block) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/active_record/attribute_decorators.rb', line 17

def decorate_matching_attribute_types(matcher, decorator_name, &block)
  clear_caches_calculated_from_columns
  decorator_name = decorator_name.to_s

  # Create new hashes so we don't modify parent classes
  self.attribute_type_decorations = attribute_type_decorations.merge(decorator_name => [matcher, block])
end