Sha256: b5f4859dd20228c2232b14d1328192b86a48c5d2f68ea42dfce3abf402320823

Contents?: true

Size: 872 Bytes

Versions: 3

Compression:

Stored size: 872 Bytes

Contents

require 'base64'
require 'encryptor'


class Setting < ActiveRecord::Base
	belongs_to :object, :polymorphic => true
	
	after_initialize	:decrypt_setting
	before_save			:do_encrypt_setting
	
	
	protected
	
	
	def decrypt_setting
		return unless self[:encrypt_setting]
		
		if self[:text_value].blank?
			self[:text_value] = ""
		else
			self[:text_value] = Encryptor.decrypt(Base64.decode64(self[:text_value]), {:key => Rails.application.config.automate.encrypt_key, :algorithm => 'aes-256-cbc'})
		end
	end
	
	def do_encrypt_setting
		return unless self[:encrypt_setting]
		
		if self[:text_value].blank?
			self[:text_value] = ""
		else
			self[:text_value] = Base64.encode64(Encryptor.encrypt(self[:text_value], {:key => Rails.application.config.automate.encrypt_key, :algorithm => 'aes-256-cbc'}))
		end
	end
	
	
	validates_presence_of :name, :object, :value_type
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
automate-em-0.0.4 app/models/setting.rb
automate-em-0.0.3 app/models/setting.rb
automate-em-0.0.2 app/models/setting.rb