activerecord-obscuredid 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 58cb4a44828f83c6cd63d839571e3ffaa3156c374134ce603549249cec831fa9
4
- data.tar.gz: 0b6e070feb74a02a18ba57824135da6731661c69deaaef31d08a9013ada24fe7
3
+ metadata.gz: ba24a717b4184483875e367e36d6088fee5a4699a9305ff4487b8522b60b81c6
4
+ data.tar.gz: 0f04af937c13b4cffab241062b9972f9f761555b331f4016cdd5b660d44fca8e
5
5
  SHA512:
6
- metadata.gz: 8a6f7862c0bad759bd8eaaad59abb7ab49d9b5fce9fedd7bde820043f2f1cfd4003641ee0ee96d640fb9ea220060885fedd14c3711ca78cfc6ac91f648099651
7
- data.tar.gz: bcc53d8e8183357611b235df67c9819146e10ed0623ae1def5532ab7ef3f30b28cfbc8b5d6a242c744d16f8d8eeb4d3a92c02062d38d2e6459e7e6b1448923b2
6
+ metadata.gz: b53d9d4eedf6f3516c6a39c745d9936b9b9fcfe65ed7931707b8fb1485781f4f04b632282d6a533f0ea84efc292d132e23352572dfa6d70f19039cd0a9122952
7
+ data.tar.gz: 51908341f08140c0bc146fd5ecec3f1efe11b913fed822114e8547d6b51bedbf59f87548307e0680ab465e18e0b708628d700480ee45f10ead164a558f507e18
data/README.md CHANGED
@@ -6,13 +6,13 @@
6
6
  Install the gem and add to the application's Gemfile by executing:
7
7
 
8
8
  ```bash
9
- $ bundle add PLACEHOLDER_GEM_NAME
9
+ $ bundle add activerecord-obscuredid
10
10
  ```
11
11
 
12
12
  If bundler is not being used to manage dependencies, install the gem by executing:
13
13
 
14
14
  ```bash
15
- $ gem install PLACEHOLDER_GEM_NAME
15
+ $ gem install activerecord-obscuredid
16
16
  ```
17
17
 
18
18
  ## Configuration
@@ -23,6 +23,9 @@ By default, the gem uses example.com as the domain for generating obscured email
23
23
  # config/initializers/obscured_id.rb
24
24
  ActiveRecord::ObscuredId.configure do |config|
25
25
  config.domain = 'yourdomain.com'
26
+
27
+ # if you change your domain, and still need records to be findable by the old domain name
28
+ config.old_domains = ['yourolddomain.com']
26
29
  end
27
30
  ```
28
31
 
@@ -5,10 +5,11 @@ module ActiveRecord
5
5
  module ObscuredId
6
6
  # Holds configuration options for obscured id
7
7
  class Configuration
8
- attr_accessor :domain
8
+ attr_accessor :domain, :old_domains
9
9
 
10
10
  def initialize
11
11
  @domain = 'example.com'
12
+ @old_domains = []
12
13
  end
13
14
  end
14
15
 
@@ -15,9 +15,12 @@ module ActiveRecord
15
15
  class_methods do
16
16
  def from_obscured_email_address(obscured_email_address)
17
17
  domain = obscured_id_email_domain
18
+ old_domains = obscured_id_email_old_domains
18
19
  subdomain = obscured_id_email_subdomain
19
20
 
20
- return nil unless obscured_email_address.match?(/@#{subdomain}.#{domain}\z/)
21
+ matched = obscured_email_address.match?(/@#{subdomain}.#{domain}\z/)
22
+ matched ||= obscured_email_address.match?(/@#{subdomain}.(#{old_domains.join('|')})\z/) if old_domains.any?
23
+ return nil unless matched
21
24
 
22
25
  find_obscured(obscured_email_address.remove(/@.*\z/))
23
26
  end
@@ -25,6 +28,7 @@ module ActiveRecord
25
28
  private
26
29
 
27
30
  def obscured_id_email_domain = ActiveRecord::ObscuredId.config.domain
31
+ def obscured_id_email_old_domains = ActiveRecord::ObscuredId.config.old_domains
28
32
  def obscured_id_email_subdomain = name.pluralize.underscore.dasherize.downcase
29
33
  end
30
34
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module ActiveRecord
4
4
  module ObscuredId
5
- VERSION = '0.1.0'
5
+ VERSION = '0.2.0'
6
6
  end
7
7
  end
@@ -4,6 +4,7 @@ module ActiveRecord
4
4
 
5
5
  class Configuration
6
6
  attr_accessor domain: String
7
+ attr_accessor old_domains: [String]
7
8
 
8
9
  def initialize: () -> void
9
10
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-obscuredid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - darthrighteous
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-10-26 00:00:00.000000000 Z
11
+ date: 2024-11-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport