Module: UrlEncrypt::InstanceMethods

Defined in:
lib/url_encrypt.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



45
46
47
# File 'lib/url_encrypt.rb', line 45

def self.included(base)
  base.extend ClassMethods
end

Instance Method Details

#_encrypted_attributeObject



49
50
51
# File 'lib/url_encrypt.rb', line 49

def _encrypted_attribute
  @_encrypted_attribute ||= self.encrypt(self.send(self.class.encryptable_attribute))
end

#_encrypted_attribute=(encrypted_attribute) ⇒ Object



53
54
55
# File 'lib/url_encrypt.rb', line 53

def _encrypted_attribute= (encrypted_attribute)
  @_encrypted_attribute = encrypted_attribute
end

#encrypt(attribute_val) ⇒ Object



61
62
63
64
65
# File 'lib/url_encrypt.rb', line 61

def encrypt(attribute_val)
  UrlEncrypt.cipher.encrypt
  UrlEncrypt.cipher.key, UrlEncrypt.cipher.iv = UrlEncrypt.key, UrlEncrypt.iv
  URI.encode((UrlEncrypt.cipher.update(attribute_val.to_s) + UrlEncrypt.cipher.final).unpack("H*").to_s)
end

#to_paramObject



57
58
59
# File 'lib/url_encrypt.rb', line 57

def to_param
  self.class.encryptable_attribute ? self._encrypted_attribute : id.to_s
end