Permalink
Browse files

remove huberry namespace

  • Loading branch information...
1 parent cdac616 commit ed068192c40a0a1bbfb1689df66c190d3cc8cc8e @shuber shuber committed Jan 28, 2010
View

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -0,0 +1,55 @@
+if defined?(ActiveRecord)
+ module AttrEncrypted
+ module Adapters
+ module ActiveRecord
+ def self.extended(base)
+ base.attr_encrypted_options[:encode] = true
+ base.eigenclass_eval { alias_method_chain :method_missing, :attr_encrypted }
+ end
+
+ protected
+
+ # Ensures the attribute methods for db fields have been defined before calling the original
+ # <tt>attr_encrypted</tt> method
+ def attr_encrypted(*attrs)
+ define_attribute_methods rescue nil
+ super
+ attrs.reject { |attr| attr.is_a?(Hash) }.each { |attr| alias_method "#{attr}_before_type_cast", attr }
+ end
+
+ # Allows you to use dynamic methods like <tt>find_by_email</tt> or <tt>scoped_by_email</tt> for
+ # encrypted attributes
+ #
+ # NOTE: This only works when the <tt>:key</tt> option is specified as a string (see the README)
+ #
+ # This is useful for encrypting fields like email addresses. Your user's email addresses
+ # are encrypted in the database, but you can still look up a user by email for logging in
+ #
+ # Example
+ #
+ # class User < ActiveRecord::Base
+ # attr_encrypted :email, :key => 'secret key'
+ # end
+ #
+ # User.find_by_email_and_password('test@example.com', 'testing')
+ # # results in a call to
+ # User.find_by_encrypted_email_and_password('the_encrypted_version_of_test@example.com', 'testing')
+ def method_missing_with_attr_encrypted(method, *args, &block)
+ if match = /^(find|scoped)_(all_by|by)_([_a-zA-Z]\w*)$/.match(method.to_s)
+ attribute_names = match.captures.last.split('_and_')
+ attribute_names.each_with_index do |attribute, index|
+ if attr_encrypted?(attribute)
+ args[index] = send("encrypt_#{attribute}", args[index])
+ attribute_names[index] = encrypted_attributes[attribute]
+ end
+ end
+ method = "#{match.captures[0]}_#{match.captures[1]}_#{attribute_names.join('_and_')}".to_sym
+ end
+ method_missing_without_attr_encrypted(method, *args, &block)
+ end
+ end
+ end
+ end
+
+ ActiveRecord::Base.extend AttrEncrypted::Adapters::ActiveRecord
+end
@@ -0,0 +1,21 @@
+if defined?(DataMapper)
+ module AttrEncrypted
+ module Adapters
+ module DataMapper
+ def self.extended(base)
+ base.eigenclass_eval do
+ alias_method :included_without_attr_encrypted, :included
+ alias_method :included, :included_with_attr_encrypted
+ end
+ end
+
+ def included_with_attr_encrypted(base)
+ included_without_attr_encrypted(base)
+ base.attr_encrypted_options[:encode] = true
+ end
+ end
+ end
+ end
+
+ DataMapper::Resource.extend AttrEncrypted::Adapters::DataMapper
+end
@@ -0,0 +1,13 @@
+if defined?(Sequel)
+ module AttrEncrypted
+ module Adapters
+ module Sequel
+ def self.extended(base)
+ base.attr_encrypted_options[:encode] = true
+ end
+ end
+ end
+ end
+
+ Sequel::Model.extend AttrEncrypted::Adapters::Sequel
+end
@@ -1,57 +0,0 @@
-if defined?(ActiveRecord)
- module Huberry
- module AttrEncrypted
- module Adapters
- module ActiveRecord
- def self.extended(base)
- base.attr_encrypted_options[:encode] = true
- base.eigenclass_eval { alias_method_chain :method_missing, :attr_encrypted }
- end
-
- protected
-
- # Ensures the attribute methods for db fields have been defined before calling the original
- # <tt>attr_encrypted</tt> method
- def attr_encrypted(*attrs)
- define_attribute_methods rescue nil
- super
- attrs.reject { |attr| attr.is_a?(Hash) }.each { |attr| alias_method "#{attr}_before_type_cast", attr }
- end
-
- # Allows you to use dynamic methods like <tt>find_by_email</tt> or <tt>scoped_by_email</tt> for
- # encrypted attributes
- #
- # NOTE: This only works when the <tt>:key</tt> option is specified as a string (see the README)
- #
- # This is useful for encrypting fields like email addresses. Your user's email addresses
- # are encrypted in the database, but you can still look up a user by email for logging in
- #
- # Example
- #
- # class User < ActiveRecord::Base
- # attr_encrypted :email, :key => 'secret key'
- # end
- #
- # User.find_by_email_and_password('test@example.com', 'testing')
- # # results in a call to
- # User.find_by_encrypted_email_and_password('the_encrypted_version_of_test@example.com', 'testing')
- def method_missing_with_attr_encrypted(method, *args, &block)
- if match = /^(find|scoped)_(all_by|by)_([_a-zA-Z]\w*)$/.match(method.to_s)
- attribute_names = match.captures.last.split('_and_')
- attribute_names.each_with_index do |attribute, index|
- if attr_encrypted?(attribute)
- args[index] = send("encrypt_#{attribute}", args[index])
- attribute_names[index] = encrypted_attributes[attribute]
- end
- end
- method = "#{match.captures[0]}_#{match.captures[1]}_#{attribute_names.join('_and_')}".to_sym
- end
- method_missing_without_attr_encrypted(method, *args, &block)
- end
- end
- end
- end
- end
-
- ActiveRecord::Base.extend Huberry::AttrEncrypted::Adapters::ActiveRecord
-end
@@ -1,23 +0,0 @@
-if defined?(DataMapper)
- module Huberry
- module AttrEncrypted
- module Adapters
- module DataMapper
- def self.extended(base)
- base.eigenclass_eval do
- alias_method :included_without_attr_encrypted, :included
- alias_method :included, :included_with_attr_encrypted
- end
- end
-
- def included_with_attr_encrypted(base)
- included_without_attr_encrypted(base)
- base.attr_encrypted_options[:encode] = true
- end
- end
- end
- end
- end
-
- DataMapper::Resource.extend Huberry::AttrEncrypted::Adapters::DataMapper
-end
@@ -1,15 +0,0 @@
-if defined?(Sequel)
- module Huberry
- module AttrEncrypted
- module Adapters
- module Sequel
- def self.extended(base)
- base.attr_encrypted_options[:encode] = true
- end
- end
- end
- end
- end
-
- Sequel::Model.extend Huberry::AttrEncrypted::Adapters::Sequel
-end
@@ -20,7 +20,7 @@ def create_people_table
class Person < ActiveRecord::Base
attr_encrypted :email, :key => 'a secret key'
- attr_encrypted :credentials, :key => Proc.new { |user| Huberry::Encryptor.encrypt(:value => user.salt, :key => 'some private key') }, :marshal => true
+ attr_encrypted :credentials, :key => Proc.new { |user| Encryptor.encrypt(:value => user.salt, :key => 'some private key') }, :marshal => true
def after_initialize
self.salt ||= Digest::SHA256.hexdigest((Time.now.to_i * rand(5)).to_s)
@@ -157,23 +157,23 @@ def test_should_evaluate_a_key_passed_as_a_symbol
assert_nil @user.ssn_encrypted
@user.ssn = 'testing'
assert_not_nil @user.ssn_encrypted
- assert_equal Huberry::Encryptor.encrypt(:value => 'testing', :key => @user.salt), @user.ssn_encrypted
+ assert_equal Encryptor.encrypt(:value => 'testing', :key => @user.salt), @user.ssn_encrypted
end
def test_should_evaluate_a_key_passed_as_a_proc
@user = User.new
assert_nil @user.crypted_password_test
@user.password = 'testing'
assert_not_nil @user.crypted_password_test
- assert_equal Huberry::Encryptor.encrypt(:value => 'testing', :key => 'User'), @user.crypted_password_test
+ assert_equal Encryptor.encrypt(:value => 'testing', :key => 'User'), @user.crypted_password_test
end
def test_should_use_options_found_in_the_attr_encrypted_options_attribute
@user = User.new
assert_nil @user.crypted_password_test
@user.password = 'testing'
assert_not_nil @user.crypted_password_test
- assert_equal Huberry::Encryptor.encrypt(:value => 'testing', :key => 'User'), @user.crypted_password_test
+ assert_equal Encryptor.encrypt(:value => 'testing', :key => 'User'), @user.crypted_password_test
end
def test_should_inherit_encrypted_attributes
@@ -215,7 +215,7 @@ def test_should_encrypt_with_true_if
assert_nil @user.encrypted_with_true_if
@user.with_true_if = 'testing'
assert_not_nil @user.encrypted_with_true_if
- assert_equal Huberry::Encryptor.encrypt(:value => 'testing', :key => 'secret key'), @user.encrypted_with_true_if
+ assert_equal Encryptor.encrypt(:value => 'testing', :key => 'secret key'), @user.encrypted_with_true_if
end
def test_should_not_encrypt_with_false_if
@@ -231,7 +231,7 @@ def test_should_encrypt_with_false_unless
assert_nil @user.encrypted_with_false_unless
@user.with_false_unless = 'testing'
assert_not_nil @user.encrypted_with_false_unless
- assert_equal Huberry::Encryptor.encrypt(:value => 'testing', :key => 'secret key'), @user.encrypted_with_false_unless
+ assert_equal Encryptor.encrypt(:value => 'testing', :key => 'secret key'), @user.encrypted_with_false_unless
end
def test_should_not_encrypt_with_true_unless
View
@@ -11,7 +11,7 @@ class Client
property :salt, String
attr_encrypted :email, :key => 'a secret key'
- attr_encrypted :credentials, :key => Proc.new { |client| Huberry::Encryptor.encrypt(:value => client.salt, :key => 'some private key') }, :marshal => true
+ attr_encrypted :credentials, :key => Proc.new { |client| Encryptor.encrypt(:value => client.salt, :key => 'some private key') }, :marshal => true
def initialize(attrs = {})
super attrs
View
@@ -12,7 +12,7 @@
class Human < Sequel::Model(:humans)
attr_encrypted :email, :key => 'a secret key'
- attr_encrypted :credentials, :key => Proc.new { |human| Huberry::Encryptor.encrypt(:value => human.salt, :key => 'some private key') }, :marshal => true
+ attr_encrypted :credentials, :key => Proc.new { |human| Encryptor.encrypt(:value => human.salt, :key => 'some private key') }, :marshal => true
def after_initialize(attrs = {})
self.salt ||= Digest::SHA1.hexdigest((Time.now.to_i * rand(5)).to_s)
View
@@ -3,12 +3,6 @@
require 'rubygems'
-gem 'activerecord'
-gem 'datamapper'
-gem 'sequel'
-
-require 'eigenclass'
-require 'encryptor'
require 'active_record'
require 'datamapper'
require 'sequel'

0 comments on commit ed06819

Please sign in to comment.