Sha256: 2c1d23075cd78f0de3a297818126552cac64098da31789108829cd567ddd3d81

Contents?: true

Size: 1.01 KB

Versions: 5

Compression:

Stored size: 1.01 KB

Contents

module Fingerprintable
  module Mixin
    module ClassMethods
      def inherited(subclass)
        subclass.fingerprint(*fingerprintable_attributes)
        super(subclass)
      end

      def fingerprint(*attrs, ignore: [])
        @fingerprintable_attributes = fingerprintable_attributes | attrs
        ignore = [ignore] if ignore.is_a?(String) || ignore.is_a?(Symbol)
        fingerprintable_config[:ignore] |= ignore
      end

      def fingerprintable_attributes
        @fingerprintable_attributes ||= []
      end

      def fingerprintable_config
        @fingerprintable_config ||= {
          ignore: []
        }
      end
    end

    def self.included(base)
      base.extend(ClassMethods)
    end

    def fingerprint(*args)
      fingerprinter.fingerprint(*args)
    end

    def fingerprinter(*attrs, cache: {})
      Fingerprinter.new(
        attributes: self.class.fingerprintable_attributes | attrs,
        cache: cache,
        object: self,
        **self.class.fingerprintable_config
      )
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
fingerprintable-1.2.1 lib/fingerprintable/mixin.rb
fingerprintable-1.2.0 lib/fingerprintable/mixin.rb
fingerprintable-1.1.1 lib/fingerprintable/mixin.rb
fingerprintable-1.1.0 lib/fingerprintable/mixin.rb
fingerprintable-1.0.0 lib/fingerprintable/mixin.rb