attr_encrypted 1.0.9 → 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.
- data/README.rdoc +308 -0
- data/Rakefile +1 -1
- data/lib/attr_encrypted.rb +192 -196
- data/lib/attr_encrypted/adapters/active_record.rb +55 -0
- data/lib/attr_encrypted/adapters/data_mapper.rb +21 -0
- data/lib/attr_encrypted/adapters/sequel.rb +13 -0
- data/test/active_record_test.rb +1 -1
- data/test/attr_encrypted_test.rb +12 -5
- data/test/data_mapper_test.rb +1 -1
- data/test/sequel_test.rb +1 -1
- data/test/test_helper.rb +0 -6
- metadata +14 -10
- data/CHANGELOG +0 -45
- data/README.markdown +0 -299
- data/lib/huberry/attr_encrypted/adapters/active_record.rb +0 -57
- data/lib/huberry/attr_encrypted/adapters/data_mapper.rb +0 -23
- data/lib/huberry/attr_encrypted/adapters/sequel.rb +0 -15
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
if defined?(ActiveRecord)
|
|
2
|
-
module Huberry
|
|
3
|
-
module AttrEncrypted
|
|
4
|
-
module Adapters
|
|
5
|
-
module ActiveRecord
|
|
6
|
-
def self.extended(base)
|
|
7
|
-
base.attr_encrypted_options[:encode] = true
|
|
8
|
-
base.eigenclass_eval { alias_method_chain :method_missing, :attr_encrypted }
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
protected
|
|
12
|
-
|
|
13
|
-
# Ensures the attribute methods for db fields have been defined before calling the original
|
|
14
|
-
# <tt>attr_encrypted</tt> method
|
|
15
|
-
def attr_encrypted(*attrs)
|
|
16
|
-
define_attribute_methods rescue nil
|
|
17
|
-
super
|
|
18
|
-
attrs.reject { |attr| attr.is_a?(Hash) }.each { |attr| alias_method "#{attr}_before_type_cast", attr }
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
# Allows you to use dynamic methods like <tt>find_by_email</tt> or <tt>scoped_by_email</tt> for
|
|
22
|
-
# encrypted attributes
|
|
23
|
-
#
|
|
24
|
-
# NOTE: This only works when the <tt>:key</tt> option is specified as a string (see the README)
|
|
25
|
-
#
|
|
26
|
-
# This is useful for encrypting fields like email addresses. Your user's email addresses
|
|
27
|
-
# are encrypted in the database, but you can still look up a user by email for logging in
|
|
28
|
-
#
|
|
29
|
-
# Example
|
|
30
|
-
#
|
|
31
|
-
# class User < ActiveRecord::Base
|
|
32
|
-
# attr_encrypted :email, :key => 'secret key'
|
|
33
|
-
# end
|
|
34
|
-
#
|
|
35
|
-
# User.find_by_email_and_password('test@example.com', 'testing')
|
|
36
|
-
# # results in a call to
|
|
37
|
-
# User.find_by_encrypted_email_and_password('the_encrypted_version_of_test@example.com', 'testing')
|
|
38
|
-
def method_missing_with_attr_encrypted(method, *args, &block)
|
|
39
|
-
if match = /^(find|scoped)_(all_by|by)_([_a-zA-Z]\w*)$/.match(method.to_s)
|
|
40
|
-
attribute_names = match.captures.last.split('_and_')
|
|
41
|
-
attribute_names.each_with_index do |attribute, index|
|
|
42
|
-
if attr_encrypted?(attribute)
|
|
43
|
-
args[index] = send("encrypt_#{attribute}", args[index])
|
|
44
|
-
attribute_names[index] = encrypted_attributes[attribute]
|
|
45
|
-
end
|
|
46
|
-
end
|
|
47
|
-
method = "#{match.captures[0]}_#{match.captures[1]}_#{attribute_names.join('_and_')}".to_sym
|
|
48
|
-
end
|
|
49
|
-
method_missing_without_attr_encrypted(method, *args, &block)
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
end
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
ActiveRecord::Base.extend Huberry::AttrEncrypted::Adapters::ActiveRecord
|
|
57
|
-
end
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
if defined?(DataMapper)
|
|
2
|
-
module Huberry
|
|
3
|
-
module AttrEncrypted
|
|
4
|
-
module Adapters
|
|
5
|
-
module DataMapper
|
|
6
|
-
def self.extended(base)
|
|
7
|
-
base.eigenclass_eval do
|
|
8
|
-
alias_method :included_without_attr_encrypted, :included
|
|
9
|
-
alias_method :included, :included_with_attr_encrypted
|
|
10
|
-
end
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def included_with_attr_encrypted(base)
|
|
14
|
-
included_without_attr_encrypted(base)
|
|
15
|
-
base.attr_encrypted_options[:encode] = true
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
DataMapper::Resource.extend Huberry::AttrEncrypted::Adapters::DataMapper
|
|
23
|
-
end
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
if defined?(Sequel)
|
|
2
|
-
module Huberry
|
|
3
|
-
module AttrEncrypted
|
|
4
|
-
module Adapters
|
|
5
|
-
module Sequel
|
|
6
|
-
def self.extended(base)
|
|
7
|
-
base.attr_encrypted_options[:encode] = true
|
|
8
|
-
end
|
|
9
|
-
end
|
|
10
|
-
end
|
|
11
|
-
end
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
Sequel::Model.extend Huberry::AttrEncrypted::Adapters::Sequel
|
|
15
|
-
end
|