sevenwire-attr_encrypted 1.0.8 → 1.1.0

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.
@@ -294,7 +294,12 @@ NOTE: This only works if all records are encrypted with the same encryption key
294
294
  Just like the default options for ActiveRecord, the `:encode` option is set to true by default since you'll be storing everything in a database.
295
295
 
296
296
 
297
+ ### ActiveResource ###
298
+
299
+ Works just like ActiveRecord. Questions about this should be directed to [Sevenwire](http://github.com/sevenwire).
300
+
301
+
297
302
  Contact
298
303
  -------
299
304
 
300
- Problems, comments, and suggestions all welcome: [shuber@huberry.com](mailto:shuber@huberry.com)
305
+ Problems, comments, and suggestions all welcome: [shuber@huberry.com](mailto:shuber@huberry.com)
@@ -1,7 +1,4 @@
1
- gem 'shuber-eigenclass', '>= 1.0.1'
2
1
  require 'eigenclass'
3
-
4
- gem 'shuber-encryptor'
5
2
  require 'encryptor'
6
3
 
7
4
  module Huberry
@@ -15,6 +15,14 @@ if defined?(ActiveRecord)
15
15
  def attr_encrypted(*attrs)
16
16
  define_attribute_methods
17
17
  super
18
+ unless @attr_encrypted_before_save_callback_defined
19
+ before_save do |record|
20
+ encrypted_attributes.keys.each do |attribute|
21
+ record.send(:"#{attribute}=", record.send(attribute.to_sym))
22
+ end
23
+ end
24
+ @attr_encrypted_before_save_callback_defined = true
25
+ end
18
26
  end
19
27
 
20
28
  # Allows you to use dynamic methods like <tt>find_by_email</tt> or <tt>scoped_by_email</tt> for
@@ -3,8 +3,39 @@ if defined?(ActiveResource)
3
3
  module AttrEncrypted
4
4
  module Adapters
5
5
  module ActiveResource
6
+
7
+ module InstanceMethods
8
+ # Calls the assignment method of each attribute so they are
9
+ # encrypted. Objects modified in place would not get saved
10
+ # otherwise.
11
+ def save_with_encrypted_attributes
12
+ self.class.encrypted_attributes.keys.each do |attribute|
13
+ if respond_to?(attribute)
14
+ send(:"#{attribute}=", send(attribute.to_sym))
15
+ end
16
+ end
17
+ save_without_encrypted_attributes
18
+ end
19
+ end
20
+
6
21
  def self.extended(base)
7
22
  base.attr_encrypted_options[:encode] = true
23
+ unless base.included_modules.include?(Huberry::AttrEncrypted::Adapters::ActiveResource::InstanceMethods)
24
+ base.send :include, Huberry::AttrEncrypted::Adapters::ActiveResource::InstanceMethods
25
+ base.alias_method_chain :save, :encrypted_attributes
26
+ end
27
+ end
28
+
29
+
30
+ protected
31
+
32
+ def attr_encrypted(*attrs)
33
+ super
34
+
35
+ encrypted_attributes.values.each do |attribute|
36
+ remove_method(attribute.to_sym)
37
+ remove_method(:"#{attribute}=")
38
+ end
8
39
  end
9
40
  end
10
41
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sevenwire-attr_encrypted
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.8
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sean Huber
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-01-13 00:00:00 -08:00
12
+ date: 2009-03-02 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency