Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ spec/dummy/log/*.log
spec/dummy/tmp/
spec/dummy/.sass-cache
*.swp
*.gem
270 changes: 142 additions & 128 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,76 +1,82 @@
PATH
remote: .
specs:
obfuscate_id (0.2.0)
rails (~> 4.2.0)
obfuscate_id (0.3.0)
rails (~> 5.1.2)
scatter_swap (~> 0.0.3)

GEM
remote: http://rubygems.org/
specs:
actionmailer (4.2.0)
actionpack (= 4.2.0)
actionview (= 4.2.0)
activejob (= 4.2.0)
actioncable (5.1.3)
actionpack (= 5.1.3)
nio4r (~> 2.0)
websocket-driver (~> 0.6.1)
actionmailer (5.1.3)
actionpack (= 5.1.3)
actionview (= 5.1.3)
activejob (= 5.1.3)
mail (~> 2.5, >= 2.5.4)
rails-dom-testing (~> 1.0, >= 1.0.5)
actionpack (4.2.0)
actionview (= 4.2.0)
activesupport (= 4.2.0)
rack (~> 1.6.0)
rack-test (~> 0.6.2)
rails-dom-testing (~> 1.0, >= 1.0.5)
rails-html-sanitizer (~> 1.0, >= 1.0.1)
actionview (4.2.0)
activesupport (= 4.2.0)
rails-dom-testing (~> 2.0)
actionpack (5.1.3)
actionview (= 5.1.3)
activesupport (= 5.1.3)
rack (~> 2.0)
rack-test (~> 0.6.3)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.2)
actionview (5.1.3)
activesupport (= 5.1.3)
builder (~> 3.1)
erubis (~> 2.7.0)
rails-dom-testing (~> 1.0, >= 1.0.5)
rails-html-sanitizer (~> 1.0, >= 1.0.1)
activejob (4.2.0)
activesupport (= 4.2.0)
globalid (>= 0.3.0)
activemodel (4.2.0)
activesupport (= 4.2.0)
builder (~> 3.1)
activerecord (4.2.0)
activemodel (= 4.2.0)
activesupport (= 4.2.0)
arel (~> 6.0)
activesupport (4.2.0)
erubi (~> 1.4)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.3)
activejob (5.1.3)
activesupport (= 5.1.3)
globalid (>= 0.3.6)
activemodel (5.1.3)
activesupport (= 5.1.3)
activerecord (5.1.3)
activemodel (= 5.1.3)
activesupport (= 5.1.3)
arel (~> 8.0)
activesupport (5.1.3)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (~> 0.7)
json (~> 1.7, >= 1.7.7)
minitest (~> 5.1)
thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1)
addressable (2.3.6)
arel (6.0.0)
builder (3.2.2)
capybara (2.4.4)
mime-types (>= 1.16)
addressable (2.5.1)
public_suffix (~> 2.0, >= 2.0.2)
arel (8.0.0)
builder (3.2.3)
capybara (2.15.1)
addressable
mini_mime (>= 0.1.3)
nokogiri (>= 1.3.3)
rack (>= 1.0.0)
rack-test (>= 0.5.4)
xpath (~> 2.0)
celluloid (0.16.0)
timers (~> 4.0.0)
childprocess (0.5.5)
childprocess (0.7.1)
ffi (~> 1.0, >= 1.0.11)
coderay (1.1.0)
diff-lcs (1.2.5)
erubis (2.7.0)
ffi (1.9.6)
coderay (1.1.1)
concurrent-ruby (1.0.5)
diff-lcs (1.3)
erubi (1.6.1)
ffi (1.9.18)
formatador (0.2.5)
globalid (0.3.2)
activesupport (>= 4.1.0)
guard (2.10.2)
globalid (0.4.0)
activesupport (>= 4.2.0)
guard (2.14.1)
formatador (>= 0.2.4)
listen (~> 2.7)
listen (>= 2.7, < 4.0)
lumberjack (~> 1.0)
nenv (~> 0.1)
notiffany (~> 0.0)
pry (>= 0.9.12)
shellany (~> 0.0)
thor (>= 0.18.1)
guard-compat (1.1.0)
guard-rspec (4.5.0)
guard-compat (1.2.1)
guard-rspec (4.7.3)
guard (~> 2.1)
guard-compat (~> 1.1)
rspec (>= 2.99.0, < 4.0)
Expand All @@ -79,104 +85,109 @@ GEM
guard (~> 2.0)
guard-compat (~> 1.0)
spork (>= 0.8.4)
hike (1.2.3)
hitimes (1.2.2)
i18n (0.7.0)
json (1.8.2)
i18n (0.8.6)
launchy (2.4.3)
addressable (~> 2.3)
listen (2.8.3)
celluloid (>= 0.15.2)
rb-fsevent (>= 0.9.3)
rb-inotify (>= 0.9)
loofah (2.0.1)
listen (3.1.5)
rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7)
ruby_dep (~> 1.2)
loofah (2.0.3)
nokogiri (>= 1.5.9)
lumberjack (1.0.9)
mail (2.6.3)
mime-types (>= 1.16, < 3)
lumberjack (1.0.12)
mail (2.6.6)
mime-types (>= 1.16, < 4)
method_source (0.8.2)
mime-types (2.4.3)
mini_portile (0.6.1)
minitest (5.5.1)
multi_json (1.10.1)
nokogiri (1.6.5)
mini_portile (~> 0.6.0)
pry (0.10.1)
mime-types (3.1)
mime-types-data (~> 3.2015)
mime-types-data (3.2016.0521)
mini_mime (0.1.3)
mini_portile2 (2.2.0)
minitest (5.10.3)
nenv (0.3.0)
nio4r (2.1.0)
nokogiri (1.8.0)
mini_portile2 (~> 2.2.0)
notiffany (0.1.1)
nenv (~> 0.1)
shellany (~> 0.0)
pry (0.10.4)
coderay (~> 1.1.0)
method_source (~> 0.8.1)
slop (~> 3.4)
rack (1.6.0)
public_suffix (2.0.5)
rack (2.0.3)
rack-test (0.6.3)
rack (>= 1.0)
rails (4.2.0)
actionmailer (= 4.2.0)
actionpack (= 4.2.0)
actionview (= 4.2.0)
activejob (= 4.2.0)
activemodel (= 4.2.0)
activerecord (= 4.2.0)
activesupport (= 4.2.0)
bundler (>= 1.3.0, < 2.0)
railties (= 4.2.0)
sprockets-rails
rails-deprecated_sanitizer (1.0.3)
activesupport (>= 4.2.0.alpha)
rails-dom-testing (1.0.5)
activesupport (>= 4.2.0.beta, < 5.0)
nokogiri (~> 1.6.0)
rails-deprecated_sanitizer (>= 1.0.1)
rails-html-sanitizer (1.0.1)
rails (5.1.3)
actioncable (= 5.1.3)
actionmailer (= 5.1.3)
actionpack (= 5.1.3)
actionview (= 5.1.3)
activejob (= 5.1.3)
activemodel (= 5.1.3)
activerecord (= 5.1.3)
activesupport (= 5.1.3)
bundler (>= 1.3.0)
railties (= 5.1.3)
sprockets-rails (>= 2.0.0)
rails-dom-testing (2.0.3)
activesupport (>= 4.2.0)
nokogiri (>= 1.6)
rails-html-sanitizer (1.0.3)
loofah (~> 2.0)
railties (4.2.0)
actionpack (= 4.2.0)
activesupport (= 4.2.0)
railties (5.1.3)
actionpack (= 5.1.3)
activesupport (= 5.1.3)
method_source
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
rake (10.4.2)
rb-fsevent (0.9.4)
rb-inotify (0.9.5)
ffi (>= 0.5.0)
rspec (3.1.0)
rspec-core (~> 3.1.0)
rspec-expectations (~> 3.1.0)
rspec-mocks (~> 3.1.0)
rspec-core (3.1.7)
rspec-support (~> 3.1.0)
rspec-expectations (3.1.2)
rake (12.0.0)
rb-fsevent (0.10.2)
rb-inotify (0.9.10)
ffi (>= 0.5.0, < 2)
rspec (3.6.0)
rspec-core (~> 3.6.0)
rspec-expectations (~> 3.6.0)
rspec-mocks (~> 3.6.0)
rspec-core (3.6.0)
rspec-support (~> 3.6.0)
rspec-expectations (3.6.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.6.0)
rspec-mocks (3.6.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.1.0)
rspec-mocks (3.1.3)
rspec-support (~> 3.1.0)
rspec-rails (3.1.0)
rspec-support (~> 3.6.0)
rspec-rails (3.6.0)
actionpack (>= 3.0)
activesupport (>= 3.0)
railties (>= 3.0)
rspec-core (~> 3.1.0)
rspec-expectations (~> 3.1.0)
rspec-mocks (~> 3.1.0)
rspec-support (~> 3.1.0)
rspec-support (3.1.2)
rspec-core (~> 3.6.0)
rspec-expectations (~> 3.6.0)
rspec-mocks (~> 3.6.0)
rspec-support (~> 3.6.0)
rspec-support (3.6.0)
ruby_dep (1.5.0)
scatter_swap (0.0.3)
shellany (0.0.1)
slop (3.6.0)
spork (0.9.2)
sprockets (2.12.3)
hike (~> 1.2)
multi_json (~> 1.0)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
sprockets-rails (2.2.4)
actionpack (>= 3.0)
activesupport (>= 3.0)
sprockets (>= 2.8, < 4.0)
sqlite3 (1.3.10)
thor (0.19.1)
thread_safe (0.3.4)
tilt (1.4.1)
timers (4.0.1)
hitimes
tzinfo (1.2.2)
sprockets (3.7.1)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
sprockets-rails (3.2.0)
actionpack (>= 4.0)
activesupport (>= 4.0)
sprockets (>= 3.0.0)
sqlite3 (1.3.13)
thor (0.19.4)
thread_safe (0.3.6)
tzinfo (1.2.3)
thread_safe (~> 0.1)
xpath (2.0.0)
websocket-driver (0.6.5)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.2)
xpath (2.1.0)
nokogiri (~> 1.3)

PLATFORMS
Expand All @@ -192,3 +203,6 @@ DEPENDENCIES
rb-inotify
rspec-rails
sqlite3

BUNDLED WITH
1.15.3
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ ActiveRecord reverses this obfuscated id back to the plain id before building th

## Versions

This is tested with Rails 4.2.0. For other versions of Rails, please see [the releases](https://github.com/namick/obfuscate_id/releases).
This is tested with Rails 5.1.2. For other versions of Rails, please see [the releases](https://github.com/namick/obfuscate_id/releases).

If you are trying to get it to work with a different version of rails that is not tested, let me know in [the issues](https://github.com/namick/obfuscate_id/issues)

Expand Down
20 changes: 13 additions & 7 deletions lib/obfuscate_id.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,25 @@ def obfuscate_id(options = {})

extend ClassMethods
include InstanceMethods
cattr_accessor :obfuscate_id_spin
cattr_accessor :obfuscate_id_spin, :clean_url_class_name
self.obfuscate_id_spin = (options[:spin] || obfuscate_id_default_spin)
set_clean_url_class_name
end

def self.hide(id, spin)
ScatterSwap.hash(id, spin)
def self.hide(id,name, spin)
name + ScatterSwap.hash(id, spin)
end

def self.show(id, spin)
ScatterSwap.reverse_hash(id, spin)
def self.show(id,name, spin)
ScatterSwap.reverse_hash(id.gsub(name, ""), spin)
end

module ClassMethods

def set_clean_url_class_name
self.clean_url_class_name = self.name.gsub("::", "-").underscore
end

def find(*args)
scope = args.slice!(0)
options = args.slice!(0) || {}
Expand All @@ -35,7 +41,7 @@ def has_obfuscated_id?
end

def deobfuscate_id(obfuscated_id)
ObfuscateId.show(obfuscated_id, self.obfuscate_id_spin)
ObfuscateId.show(obfuscated_id, self.clean_url_class_name, self.obfuscate_id_spin)
end

# Generate a default spin from the Model name
Expand All @@ -53,7 +59,7 @@ def obfuscate_id_default_spin

module InstanceMethods
def to_param
ObfuscateId.hide(self.id, self.class.obfuscate_id_spin)
ObfuscateId.hide(self.id, self.clean_url_class_name, self.class.obfuscate_id_spin)
end

# Override ActiveRecord::Persistence#reload
Expand Down
2 changes: 1 addition & 1 deletion lib/obfuscate_id/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module ObfuscateId
VERSION = "0.2.0"
VERSION = "0.3.0"
end
Loading