Module: Voltron::Encrypt::ActiveRecord::CollectionAssociation

Defined in:
lib/voltron/encrypt/active_record/collection_association.rb

Instance Method Summary collapse

Instance Method Details

#ids_readerObject



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/voltron/encrypt/active_record/collection_association.rb', line 16

def ids_reader
  if klass.has_encrypted_id?
    if loaded?
      load_target.map(&:to_param)
    else
      scope.map(&:to_param)
    end
  else
    super
  end
end

#ids_writer(ids) ⇒ Object



6
7
8
9
10
11
12
13
14
# File 'lib/voltron/encrypt/active_record/collection_association.rb', line 6

def ids_writer(ids)
  if klass.has_encrypted_id?
    ids.reject!(&:blank?)
    records = klass.find(ids)
    replace(Array.wrap(records))
  else
    super ids
  end
end