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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 773123854481b3622f58a393706848701bf1c039
4
- data.tar.gz: a71411f98c30243778348a2a5d9426eeab7015ec
3
+ metadata.gz: 986f1290881c6eb91799bfcd9a524c83d0a9392d
4
+ data.tar.gz: ba98eb059ca03d7736a6a21211f1ae0ae71d5ed9
5
5
  SHA512:
6
- metadata.gz: eca1061427d684176ea764c898ea740c1cd7ad231a1b4f7e1446567e80daa72e4098a2ee27efaac5042a7f3d56c99ddd9d860a22a9d2a2298ddcfd2bc86b9865
7
- data.tar.gz: 9111e5f0544e859c926ca48849a57feaa13d284914d84e7063fe0d5b1e8903e641749bf5a318bf604126fb84b23bede70b7d6d2c9c9226228d3bf2fbdd11aa40
6
+ metadata.gz: d947af61564b6858a41d5447ad7e556f07bfff45cb9b85b180798046a922c5f014be56d762499fe2c4bdc9ed97c3c1fd205be96021ff4db082f17a82d7ba6534
7
+ data.tar.gz: 907f9b44635f58383ca504dfa9a1818f841eae78adcf5944024ae19233b8ef7f6aea78391d659ded7ff3d083dcebc8c0070ba3e2678558288b9bb0f87e6c8c64
@@ -1,3 +1,3 @@
1
1
  module SecureAttribute
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -45,23 +45,34 @@ module SecureAttribute
45
45
 
46
46
  module ClassMethods
47
47
  def attr_secure(name, options = {})
48
- force_defining_active_record_attribute_accessors
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
- send(attr_writer, SecureAttribute.encipher(options[:algorithm], data, options[:key]))
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
- SecureAttribute.decipher(send(attr_reader), options[:key])
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 force_defining_active_record_attribute_accessors
64
- define_attribute_methods if defined?(ActiveRecord::Base) && self < ActiveRecord::Base
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.0
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-09 00:00:00.000000000 Z
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: