Sha256: b5799aa00c4a67609f220ab1d49d5ef14094a8030da88c531ab6f355de0170cd

Contents?: true

Size: 656 Bytes

Versions: 2

Compression:

Stored size: 656 Bytes

Contents

require "charwidth"

module Charwidth
  module ActiveRecord
    module InstanceMethods
      def write_attribute_with_normalize_charwidth(attr_name, value)
        value = value.is_a?(String) ? Charwidth.normalize(value) : value
        write_attribute_without_normalize_charwidth(attr_name, value)
      end
    end

    def self.included(base)
      base.class_eval do
        include InstanceMethods
        alias_method :write_attribute_without_normalize_charwidth, :write_attribute
        alias_method :write_attribute, :write_attribute_with_normalize_charwidth
      end
    end
  end
end

ActiveRecord::Base.send(:include, Charwidth::ActiveRecord)

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
charwidth-0.1.4 lib/charwidth/active_record.rb
charwidth-0.1.3 lib/charwidth/active_record.rb