Skip to content
This repository
tag: v3.0.3
Fetching contributors…

Cannot retrieve contributors at this time

file 30 lines (26 sloc) 0.85 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
module ActiveRecord
  module AttributeMethods
    module BeforeTypeCast
      extend ActiveSupport::Concern

      included do
        attribute_method_suffix "_before_type_cast"
      end

      def read_attribute_before_type_cast(attr_name)
        @attributes[attr_name]
      end

      # Returns a hash of attributes before typecasting and deserialization.
      def attributes_before_type_cast
        Hash[attribute_names.map { |name| [name, read_attribute_before_type_cast(name)] }]
      end

      private
        # Handle *_before_type_cast for method_missing.
        def attribute_before_type_cast(attribute_name)
          if attribute_name == 'id'
            read_attribute_before_type_cast(self.class.primary_key)
          else
            read_attribute_before_type_cast(attribute_name)
          end
        end
    end
  end
end
Something went wrong with that request. Please try again.