module Cloaked::InstanceMethods
Public Instance Methods
cloak_field(field_name: nil, size: DEFAULT_SIZE, prefix: '', force: false, method: :url_safe)
click to toggle source
# File lib/cloaked.rb, line 51 def cloak_field(field_name: nil, size: DEFAULT_SIZE, prefix: '', force: false, method: :url_safe) return send(field_name) if send(field_name).present? && !force cloaked_value = prefix.to_s + value(method, size) return send("#{field_name}=", cloaked_value) unless self.class.exists?(field_name) end
cloak_fields(force: false)
click to toggle source
# File lib/cloaked.rb, line 41 def cloak_fields(force: false) self.class.cloaked_fields ||= [] self.class.cloaked_fields.each do |field| cloak_field(field.merge(force: force)) end self end
Private Instance Methods
value(method, size)
click to toggle source
# File lib/cloaked.rb, line 61 def value(method, size) case method when :uuid then SecureRandom.uuid when :hex then SecureRandom.hex(size) when :url_safe then SecureRandom.urlsafe_base64(size) else raise InvalidMethod end end