Class: ActiveEnquo::Type::Text

Inherits:
ActiveEnquo::Type show all
Defined in:
lib/active_enquo.rb

Instance Method Summary collapse

Instance Method Details

#decrypt(value, context, field) ⇒ Object



367
368
369
370
371
372
373
# File 'lib/active_enquo.rb', line 367

def decrypt(value, context, field)
  if value.nil?
    nil
  else
    field.decrypt_text(value, context)
  end
end

#encrypt(value, context, field, enable_reduced_security_operations: false, no_query: false, enable_ordering: false) ⇒ Object



338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
# File 'lib/active_enquo.rb', line 338

def encrypt(value, context, field, enable_reduced_security_operations: false, no_query: false, enable_ordering: false)
  if enable_ordering && !enable_reduced_security_operations
    raise ArgumentError, "Cannot enable ordering on an Enquo attribute unless Reduced Security Operations are enabled"
  end

  if value.nil? || value.is_a?(::ActiveRecord::StatementCache::Substitute)
    value
  else
    opts = {
      unsafe: enable_reduced_security_operations,
      no_query: no_query,
    }
    if enable_ordering
      opts[:order_prefix_length] = 8
    end

    field.encrypt_text(value.respond_to?(:encode) ? value.encode("UTF-8") : value, context, **opts)
  end
end

#encrypt_metadata_value(name, value, field) ⇒ Object



358
359
360
361
362
363
364
365
# File 'lib/active_enquo.rb', line 358

def (name, value, field)
  case name
  when :length
    field.encrypt_text_length_query(value)
  else
    raise ArgumentError, "Unknown metadata name for Text field: #{name.inspect}"
  end
end

#typeObject



334
335
336
# File 'lib/active_enquo.rb', line 334

def type
  :enquo_text
end