acts_as_secure 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/acts_as_secure.rb +39 -20
  2. metadata +3 -3
@@ -11,31 +11,13 @@ module ActiveRecord::Acts::ActsAsSecure
11
11
  end
12
12
 
13
13
  module ClassMethods
14
-
15
- @@secure_crypto_providers = {}
16
-
14
+
17
15
  def acts_as_secure(options = {})
18
16
  parse_options!(options)
19
17
  add_callbacks
18
+ extend(ActsAsSecureClassMethods)
20
19
  send(:include, InstanceMethods)
21
20
  end
22
-
23
- def with_crypto_provider(provider)
24
- begin
25
- @@secure_crypto_providers[Thread.current.object_id] = provider
26
- yield
27
- ensure
28
- @@secure_crypto_providers.delete(Thread.current.object_id)
29
- end
30
- end
31
-
32
- def secure_columns
33
- columns.reject { |col| (col.type != @secure_storage_type) || @secure_except.include?(col.name) }
34
- end
35
-
36
- def secure_crypto_provider
37
- @@secure_crypto_providers[Thread.current.object_id] || @secure_class_crypto_provider
38
- end
39
21
 
40
22
  private
41
23
 
@@ -43,6 +25,7 @@ module ActiveRecord::Acts::ActsAsSecure
43
25
  @secure_except = unsecure_columns(options.delete(:except))
44
26
  @secure_storage_type = options.delete(:storage_type) || :binary
45
27
  @secure_class_crypto_provider = options.delete(:crypto_provider)
28
+ @secure_crypto_providers = {}
46
29
  fail("Unknown option(s): #{ options.keys.join(', ') }") unless options.empty?
47
30
  end
48
31
 
@@ -56,6 +39,42 @@ module ActiveRecord::Acts::ActsAsSecure
56
39
  def unsecure_columns(*names)
57
40
  names.flatten.collect(&:to_s)
58
41
  end
42
+
43
+ module ActsAsSecureClassMethods
44
+
45
+ def inherited(sub)
46
+
47
+ [:secure_except, :secure_storage_type, :secure_class_crypto_provider, :secure_crypto_providers].each do |p|
48
+ sub.instance_variable_set("@#{ p }", instance_variable_get("@#{ p }"))
49
+ end
50
+
51
+ super
52
+
53
+ end
54
+
55
+ def with_crypto_provider(provider)
56
+ begin
57
+ @secure_crypto_providers[secure_storage_id] = provider
58
+ yield
59
+ ensure
60
+ @secure_crypto_providers.delete(secure_storage_id)
61
+ end
62
+ end
63
+
64
+ def secure_columns
65
+ columns.reject { |col| (col.type != @secure_storage_type) || @secure_except.include?(col.name) }
66
+ end
67
+
68
+ def secure_crypto_provider
69
+ @secure_crypto_providers[secure_storage_id] || @secure_class_crypto_provider
70
+ end
71
+
72
+ def secure_storage_id
73
+ Thread.current.object_id
74
+ end
75
+
76
+ end
77
+
59
78
 
60
79
  module InstanceMethods
61
80
 
metadata CHANGED
@@ -3,9 +3,9 @@ rubygems_version: 0.9.2
3
3
  specification_version: 1
4
4
  name: acts_as_secure
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.0.1
7
- date: 2007-06-07 00:00:00 -04:00
8
- summary: acts_as_secure adds attributes encryption to ActiveRecord models
6
+ version: 0.0.2
7
+ date: 2007-06-19 00:00:00 -04:00
8
+ summary: Adds attribute encryption to ActiveRecord models
9
9
  require_paths:
10
10
  - lib
11
11
  email: rails-trunk@revolution.com