Class: Anony::Strategies::OverwriteHex

Inherits:
Struct
  • Object
show all
Defined in:
lib/anony/field_level_strategies.rb

Overview

This class curries the max_length into itself so it exists as a parameterless block that can be called by Anony.

Examples:

Direct usage:

anonymise do
  overwrite do
    with_strategy(OverwriteHex.new(20), :field, :field)
  end
end

Helper method, assumes length = 36

anonymise do
  overwrite do
    hex :field
  end
end

Helper method with explicit length

anonymise do
  overwrite do
    hex :field, max_length: 20
  end
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#max_lengthObject

Returns the value of attribute max_length

Returns:

  • (Object)

    the current value of max_length



148
149
150
# File 'lib/anony/field_level_strategies.rb', line 148

def max_length
  @max_length
end

Instance Method Details

#call(_existing_value) ⇒ Object



149
150
151
152
# File 'lib/anony/field_level_strategies.rb', line 149

def call(_existing_value)
  hex_length = (max_length / 2) + 1
  SecureRandom.hex(hex_length)[0, max_length]
end