obfuscatable 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 869c127a994e1b082fb9e6fde29dacf41586cef1
4
+ data.tar.gz: 76217edbe7ac6c21664c65c72168a41a54e145aa
5
+ SHA512:
6
+ metadata.gz: aca135fad2c1f76d0f617d0b98a58bd9ea48c4256c4073a2affaec07a83fc8fbee1f95718bead64e91f146944f424cbb0314d79a059bee94f36f42988acc4c96
7
+ data.tar.gz: bf75aa59b08b58832d806359f3ad74fd28cdd9d9dd83d9462b4d649411f96d9c9d1f21e8f11693eff36ca3cb38d6bb86fa3c732cc00ae5e7936e879fbf397f99
@@ -0,0 +1,20 @@
1
+ Copyright 2012 Nathan Amick
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,58 @@
1
+ # obfuscatable
2
+
3
+ [![Build Status](https://secure.travis-ci.org/namick/obfuscatable.png)](http://travis-ci.org/namick/obfuscatable) [![Dependency Status](https://gemnasium.com/namick/obfuscatable.png)](https://gemnasium.com/namick/obfuscatable) [![Code Climate](https://codeclimate.com/github/namick/obfuscatable.png)](https://codeclimate.com/github/namick/obfuscatable)
4
+
5
+ **Make your ActiveRecord ids non-obvious**
6
+
7
+ This gem is just a fork from [obfuscate_id](https://github.com/namick/obfuscate_id) but I made the obfuscation optional because it affects to some conditions and causes errors.
8
+
9
+ ## Installation
10
+
11
+ Add the gem to your Gemfile.
12
+
13
+ ```ruby
14
+ gem "obfuscatable"
15
+ ```
16
+
17
+ Run bundler.
18
+
19
+ ```ruby
20
+ bundle install
21
+ ```
22
+
23
+ ## Usage
24
+
25
+ In your model, add a single line.
26
+
27
+ ```ruby
28
+ class Post < ActiveRecord::Base
29
+ obfuscatable
30
+ end
31
+ ```
32
+
33
+ Then use it with `to_param` or direct object passing in the view.
34
+
35
+ ```ruby
36
+ link_to 'Post', post_path(@post.to_param)
37
+ link_to 'Post', post_path(@post)
38
+ ```
39
+
40
+ And in your controller.
41
+
42
+ ```ruby
43
+ class PostController < ApplicationController
44
+ def show
45
+ Post.find(params[:id], obfuscated: true)
46
+ end
47
+ end
48
+ ```
49
+
50
+ ## Customization
51
+
52
+ If you want your obfuscated ids to be different than some other website using the same plugin, you can throw a random number (spin) at obfuscatable to make it hash out unique ids for your app.
53
+
54
+ ```ruby
55
+ class Post < ActiveRecord::Base
56
+ obfuscatable :spin => 89238723
57
+ end
58
+ ```
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'ObfuscateId'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+ Bundler::GemHelper.install_tasks
24
+
25
+ require 'rspec/core/rake_task'
26
+
27
+ RSpec::Core::RakeTask.new(:spec)
28
+
29
+ task :default => :spec
@@ -0,0 +1,67 @@
1
+ module Obfuscatable
2
+
3
+ def obfuscatable(options = {})
4
+ require 'scatter_swap'
5
+
6
+ extend ClassMethods
7
+ include InstanceMethods
8
+ cattr_accessor :obfuscatable_spin
9
+ self.obfuscatable_spin = (options[:spin] || obfuscatable_default_spin)
10
+ end
11
+
12
+ def self.hide(id, spin)
13
+ ScatterSwap.hash(id, spin)
14
+ end
15
+
16
+ def self.show(id, spin)
17
+ ScatterSwap.reverse_hash(id, spin)
18
+ end
19
+
20
+
21
+ module ClassMethods
22
+ def find_obfuscated(*args)
23
+ scope = args.slice!(0)
24
+ options = args.slice!(0) || {}
25
+ if has_obfuscated_id?
26
+ if scope.is_a?(Array)
27
+ scope.map! {|a| deobfuscatable(a).to_i}
28
+ else
29
+ scope = deobfuscatable(scope)
30
+ end
31
+ end
32
+ find(scope)
33
+ end
34
+
35
+ def has_obfuscated_id?
36
+ true
37
+ end
38
+
39
+ def deobfuscatable(obfuscated_id)
40
+ Obfuscatable.show(obfuscated_id, self.obfuscatable_spin)
41
+ end
42
+
43
+ # Generate a default spin from the Model name
44
+ # This makes it easy to drop obfuscatable onto any model
45
+ # and produce different obfuscated ids for different models
46
+ def obfuscatable_default_spin
47
+ alphabet = Array("a".."z")
48
+ number = name.split("").collect do |char|
49
+ alphabet.index(char)
50
+ end
51
+ number.shift(12).join.to_i
52
+ end
53
+
54
+ end
55
+
56
+ module InstanceMethods
57
+ def to_param
58
+ Obfuscatable.hide(self.id, self.class.obfuscatable_spin)
59
+ end
60
+
61
+ def deobfuscatable(obfuscated_id)
62
+ self.class.deobfuscatable(obfuscated_id)
63
+ end
64
+ end
65
+ end
66
+
67
+ ActiveRecord::Base.extend Obfuscatable
@@ -0,0 +1,3 @@
1
+ module Obfuscatable
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,161 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: obfuscatable
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Daisuke Taniwaki
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-11-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: scatter_swap
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.0.3
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.0.3
27
+ - !ruby/object:Gem::Dependency
28
+ name: rails
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '3.2'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '3.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: sqlite3
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec-rails
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: capybara
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: guard-rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: guard-spork
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rb-inotify
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description: Make your ActiveRecord IDs non-obvious
126
+ email:
127
+ - daisuketaniwaki@gmail.com
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - MIT-LICENSE
133
+ - README.md
134
+ - Rakefile
135
+ - lib/obfuscatable.rb
136
+ - lib/obfuscatable/version.rb
137
+ homepage: https://github.com/dtaniwaki/obfuscatable
138
+ licenses:
139
+ - MIT
140
+ metadata: {}
141
+ post_install_message:
142
+ rdoc_options: []
143
+ require_paths:
144
+ - lib
145
+ required_ruby_version: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - ">="
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ required_rubygems_version: !ruby/object:Gem::Requirement
151
+ requirements:
152
+ - - ">="
153
+ - !ruby/object:Gem::Version
154
+ version: '0'
155
+ requirements: []
156
+ rubyforge_project:
157
+ rubygems_version: 2.2.2
158
+ signing_key:
159
+ specification_version: 4
160
+ summary: Mask ActiveRecord IDs
161
+ test_files: []