Sha256: b2aed200ae8e9cf54f7927ca26619248d8176e884d44ce7a488767818592a128

Contents?: true

Size: 692 Bytes

Versions: 3

Compression:

Stored size: 692 Bytes

Contents

module ActiveRecord
  class Base
    class << self
      def attr_redacted(*params)
        define_attribute_methods rescue nil

        if const_defined?(:RedactedAttributes, _search_ancestors = false)
          mod = const_get(:RedactedAttributes)
        else
          mod = const_set(:RedactedAttributes, Module.new)
          include mod
        end

        params.each do |attribute|
          mod.module_eval(<<-REDACTED, __FILE__, __LINE__ + 1)
            def #{attribute}=(value)
              if value
                self.redacted_#{attribute} = value[0..2]
              end
              super(value)
            end
          REDACTED
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
redacted_attributes-1.1.1 lib/redacted_attributes/extensions/active_record/base.rb
redacted_attributes-1.1.0 lib/redacted_attributes/extensions/active_record/base.rb
redacted_attributes-1.0.0 lib/redacted_attributes/extensions/active_record/base.rb