module CryptKeeper::Model
Public Instance Methods
ensure_valid_field!(field)
click to toggle source
Public: Ensures that each field exist and is of type text. This prevents encrypted data from being truncated.
# File lib/crypt_keeper/model.rb, line 10 def ensure_valid_field!(field) if self.class.columns_hash["#{field}"].nil? raise ArgumentError, "Column :#{field} does not exist" elsif !%i(text binary).include?(self.class.columns_hash["#{field}"].type) raise ArgumentError, "Column :#{field} must be of type 'text' or 'binary' \ to be used for encryption" end end
Private Instance Methods
enforce_column_types_callback()
click to toggle source
Private: Run each crypt_keeper_fields through ensure_valid_field!
# File lib/crypt_keeper/model.rb, line 22 def enforce_column_types_callback crypt_keeper_fields.each do |field| ensure_valid_field! field end end
force_encodings_on_fields()
click to toggle source
Private: Force string encodings if the option is set
# File lib/crypt_keeper/model.rb, line 29 def force_encodings_on_fields crypt_keeper_fields.each do |field| if attributes.has_key?(field.to_s) && send(field).respond_to?(:force_encoding) send(field).force_encoding(crypt_keeper_encoding) end end end