obfuscated 0.2.0 → 0.2.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.
Files changed (2) hide show
  1. data/lib/obfuscated.rb +9 -12
  2. metadata +2 -1
@@ -11,10 +11,9 @@ module Obfuscated
11
11
  end
12
12
 
13
13
  def self.supported?
14
- db = ActiveRecord::Base.connection.class.to_s.downcase
15
- @@db_support ||= db.include?('mysql') || db.include?('postgresql') ? true : false
14
+ @@mysql_support ||= ActiveRecord::Base.connection.class.to_s.downcase.include?('mysql') ? true : false
16
15
  end
17
-
16
+
18
17
  module Finder
19
18
  def find( *primary_key )
20
19
  # Sale.find( '7e2d2c4da1b0' )
@@ -47,18 +46,14 @@ module Obfuscated
47
46
  return find_by_id(hash, options) unless Obfuscated::supported?
48
47
 
49
48
  # Update the conditions to use the hash calculation
50
- db = ActiveRecord::Base.connection.class.to_s.downcase
51
- if db.include?('postgresql')
52
- options.update(:conditions => ["substring(encode(digest(concat('---',id::text,'-WICKED-#{self.table_name}-#{Obfuscated::salt}'), 'sha1'), 'hex'), 1, 12) = ?", hash])
53
- elsif db.include?('mysql')
54
- options.update(:conditions => ["SUBSTRING(SHA1(CONCAT('---',#{self.table_name}.id,'-WICKED-#{self.table_name}-#{Obfuscated::salt}')),1,12) = ?", hash])
55
- end
49
+ options.update(:conditions => ["SUBSTRING(SHA1(CONCAT('---',#{self.table_name}.id,'-WICKED-#{self.table_name}-#{Obfuscated::salt}')),1,12) = ?", hash])
50
+
56
51
  # Find it!
57
52
  first(options) or raise ActiveRecord::RecordNotFound, "Couldn't find #{self.class.to_s} with Hashed ID=#{hash}"
58
53
  end
59
54
  end
60
55
  end
61
- # select substring(encode(digest(concat('---',to_char(id),'-WICKED-clouds-abc123'), 'sha1'), 'hex'), 1, 12) from clouds
56
+
62
57
  end
63
58
 
64
59
  module InstanceMethods
@@ -70,7 +65,9 @@ module Obfuscated
70
65
  return id unless Obfuscated::supported?
71
66
 
72
67
  # Use SHA1 to generate a consistent hash based on the id and the table name
73
- @hashed_id ||= Digest::SHA1.hexdigest("---#{id}-WICKED-#{self.class.table_name}-#{Obfuscated::salt}")[0..11]
68
+ @hashed_id ||= Digest::SHA1.hexdigest(
69
+ "---#{id}-WICKED-#{self.class.table_name}-#{Obfuscated::salt}"
70
+ )[0..11]
74
71
  end
75
72
 
76
73
  def to_param
@@ -79,4 +76,4 @@ module Obfuscated
79
76
  end
80
77
  end
81
78
 
82
- ActiveRecord::Base.class_eval { include Obfuscated }
79
+ ActiveRecord::Base.class_eval { include Obfuscated }
metadata CHANGED
@@ -1,11 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: obfuscated
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Jon Collier
9
+ - Forrest Grant
9
10
  autorequire:
10
11
  bindir: bin
11
12
  cert_chain: []