secure_attribute 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/secure_attribute/version.rb +1 -1
- data/lib/secure_attribute.rb +18 -7
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 986f1290881c6eb91799bfcd9a524c83d0a9392d
|
4
|
+
data.tar.gz: ba98eb059ca03d7736a6a21211f1ae0ae71d5ed9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d947af61564b6858a41d5447ad7e556f07bfff45cb9b85b180798046a922c5f014be56d762499fe2c4bdc9ed97c3c1fd205be96021ff4db082f17a82d7ba6534
|
7
|
+
data.tar.gz: 907f9b44635f58383ca504dfa9a1818f841eae78adcf5944024ae19233b8ef7f6aea78391d659ded7ff3d083dcebc8c0070ba3e2678558288b9bb0f87e6c8c64
|
data/lib/secure_attribute.rb
CHANGED
@@ -45,23 +45,34 @@ module SecureAttribute
|
|
45
45
|
|
46
46
|
module ClassMethods
|
47
47
|
def attr_secure(name, options = {})
|
48
|
-
|
49
|
-
attr_writer(name) unless respond_to?("#{name}=")
|
50
|
-
attr_reader(name) unless respond_to?(name)
|
48
|
+
ensure_attribute_accessors_are_defined(name)
|
51
49
|
alias_method(attr_reader = "#{name}_without_secure_attribute", "#{name}")
|
52
50
|
alias_method(attr_writer = "#{name}_without_secure_attribute=", "#{name}=")
|
53
51
|
|
54
52
|
define_method("#{name}=") do |data|
|
55
|
-
|
53
|
+
if data && !data.empty?
|
54
|
+
send(attr_writer, SecureAttribute.encipher(options[:algorithm], data, options[:key]))
|
55
|
+
else
|
56
|
+
send(attr_writer, data)
|
57
|
+
end
|
56
58
|
end
|
57
59
|
|
58
60
|
define_method(name) do
|
59
|
-
|
61
|
+
if (data = send(attr_reader)) && !data.empty?
|
62
|
+
SecureAttribute.decipher(data, options[:key])
|
63
|
+
else
|
64
|
+
data
|
65
|
+
end
|
60
66
|
end
|
61
67
|
end
|
62
68
|
|
63
|
-
def
|
64
|
-
|
69
|
+
def ensure_attribute_accessors_are_defined(name)
|
70
|
+
if defined?(ActiveRecord::Base) && self < ActiveRecord::Base
|
71
|
+
define_attribute_methods
|
72
|
+
else
|
73
|
+
attr_writer(name) unless respond_to?("#{name}=")
|
74
|
+
attr_reader(name) unless respond_to?(name)
|
75
|
+
end
|
65
76
|
end
|
66
77
|
end
|
67
78
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: secure_attribute
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexis Bernard
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-01-
|
11
|
+
date: 2018-01-16 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Encrypt attributes of any Ruby object or ActiveRecord model.
|
14
14
|
email:
|