scatter_swapper 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (106) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +22 -0
  3. data/README.md +21 -0
  4. data/Rakefile +30 -0
  5. data/lib/ext/rails/action_controller/obfuscator.rb +18 -0
  6. data/lib/ext/rails/active_record/obfuscator.rb +9 -0
  7. data/lib/scatter_swap.rb +30 -0
  8. data/lib/scatter_swap/hasher.rb +98 -0
  9. data/lib/scatter_swap/run.rb +93 -0
  10. data/lib/scatter_swap/version.rb +3 -0
  11. data/lib/scatter_swapper.rb +8 -0
  12. data/lib/scatter_swapper/configuration.rb +21 -0
  13. data/lib/scatter_swapper/engine.rb +23 -0
  14. data/lib/scatter_swapper/version.rb +3 -0
  15. data/spec/dummy/Rakefile +6 -0
  16. data/spec/dummy/app/assets/config/manifest.js +4 -0
  17. data/spec/dummy/app/assets/javascripts/application.js +13 -0
  18. data/spec/dummy/app/assets/javascripts/cable.js +13 -0
  19. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  20. data/spec/dummy/app/channels/application_cable/channel.rb +4 -0
  21. data/spec/dummy/app/channels/application_cable/connection.rb +4 -0
  22. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  23. data/spec/dummy/app/controllers/products_controller.rb +5 -0
  24. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  25. data/spec/dummy/app/jobs/application_job.rb +2 -0
  26. data/spec/dummy/app/mailers/application_mailer.rb +4 -0
  27. data/spec/dummy/app/models/application_record.rb +3 -0
  28. data/spec/dummy/app/models/product.rb +2 -0
  29. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  30. data/spec/dummy/app/views/layouts/mailer.html.erb +13 -0
  31. data/spec/dummy/app/views/layouts/mailer.text.erb +1 -0
  32. data/spec/dummy/app/views/products/show.html.erb +1 -0
  33. data/spec/dummy/bin/bundle +3 -0
  34. data/spec/dummy/bin/rails +4 -0
  35. data/spec/dummy/bin/rake +4 -0
  36. data/spec/dummy/bin/setup +34 -0
  37. data/spec/dummy/bin/update +29 -0
  38. data/spec/dummy/config.ru +5 -0
  39. data/spec/dummy/config/application.rb +15 -0
  40. data/spec/dummy/config/boot.rb +5 -0
  41. data/spec/dummy/config/cable.yml +9 -0
  42. data/spec/dummy/config/database.yml +25 -0
  43. data/spec/dummy/config/environment.rb +5 -0
  44. data/spec/dummy/config/environments/development.rb +54 -0
  45. data/spec/dummy/config/environments/production.rb +86 -0
  46. data/spec/dummy/config/environments/test.rb +42 -0
  47. data/spec/dummy/config/initializers/application_controller_renderer.rb +6 -0
  48. data/spec/dummy/config/initializers/assets.rb +11 -0
  49. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  50. data/spec/dummy/config/initializers/cookies_serializer.rb +5 -0
  51. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  52. data/spec/dummy/config/initializers/inflections.rb +16 -0
  53. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  54. data/spec/dummy/config/initializers/new_framework_defaults.rb +24 -0
  55. data/spec/dummy/config/initializers/session_store.rb +3 -0
  56. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  57. data/spec/dummy/config/locales/en.yml +23 -0
  58. data/spec/dummy/config/puma.rb +47 -0
  59. data/spec/dummy/config/routes.rb +4 -0
  60. data/spec/dummy/config/secrets.yml +22 -0
  61. data/spec/dummy/config/spring.rb +6 -0
  62. data/spec/dummy/db/migrate/20161005174710_create_products.rb +6 -0
  63. data/spec/dummy/db/schema.rb +18 -0
  64. data/spec/dummy/db/test.sqlite3 +0 -0
  65. data/spec/dummy/log/development.log +0 -0
  66. data/spec/dummy/log/test.log +2094 -0
  67. data/spec/dummy/public/404.html +67 -0
  68. data/spec/dummy/public/422.html +67 -0
  69. data/spec/dummy/public/500.html +66 -0
  70. data/spec/dummy/public/apple-touch-icon-precomposed.png +0 -0
  71. data/spec/dummy/public/apple-touch-icon.png +0 -0
  72. data/spec/dummy/public/favicon.ico +0 -0
  73. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/4X/4XqW7VPZr2Y6Zqt02vR0CcMUOTOjCd25G2oW7u9KhBc.cache +0 -0
  74. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/6L/6L4feDvIbZEbLi3sESVSzmMvY3tFWkBTHTRwQfzLzoI.cache +1 -0
  75. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Bu/BuE1MKiZRiA2ei8bcxwYLjyJdTpEy4wxW852s55oNNk.cache +1 -0
  76. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/CE/CE5DGZEH9y0snNT45v25qIPc45wsznAviN6HLO6e04o.cache +1 -0
  77. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/DO/DORBTyAOLvfL9rAmgDHLzChNdxQSC12MecLn9eigz8g.cache +1 -0
  78. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/FQ/FQxGtXX5z7AKIBv1JU_-tAR-KiyoPaYdpDGdatI-HsA.cache +0 -0
  79. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/GT/GT-f7w_E3cEGHS6pJrn83Cix3Z8lEWnosqX-x1Hh42c.cache +1 -0
  80. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/IK/IKb0FntHxXnlCyVchY4VUrzWmqysAPvPqVCJhc_AJjU.cache +1 -0
  81. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/JD/JDCUTDoF2rC0R-NS53x4NhZ_wcTPq8E_ccURRvkjrbg.cache +3 -0
  82. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/M4/M4D-0ZpI2t7XsfOVSm85cQfXE9GVBWVH1Y7vzI00d7o.cache +2 -0
  83. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Mh/Mhzf0rpLZVXBSmJkZSw7S8BjpYsj8HmgsG6nGRDEcLQ.cache +0 -0
  84. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Qp/Qpkoqed0UuRM6qvNCxiFc3SPEjhkfsuMSukOq4dYUNo.cache +1 -0
  85. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/VH/VHaBur7LnA7kgAtiXpY22v0aQkBWOFSTzVH3i3hH2Bg.cache +0 -0
  86. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Vv/VviPzDHPOuLlGJWdGBm5P3F3xUDHrDm8Ulz2K5R0RYU.cache +0 -0
  87. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/W0/W0uTQRHqzQj0C4wgLX55zhV3K0cnz0Q_JBhdYzsbRls.cache +1 -0
  88. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/b-/b-ZN5Mf92R5XLHvBNThDj9wY56ctPdfONViJHGIbJAg.cache +0 -0
  89. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/b_/b_Itlk9QZZd7Rvf8kcA4yLP1R5Acu7jB-m1xQiSU0qE.cache +2 -0
  90. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/lV/lVt8G4NTNqewg9C9PXeaR1Abtx7AHu0vaSkHAhGWR0M.cache +1 -0
  91. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/mX/mX1nlsL_SWOB4y22W5FheRX0YEONKyOY7xUeIvRiHco.cache +2 -0
  92. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/mt/mtcHS-4C2owd8bjhO4wTCvArR0UZjvhGnn7bxyxUmec.cache +1 -0
  93. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/nC/nC5Vv_N9ICSY-OdjPBzWULwOUy7IO7ugOGV2RAQPYRw.cache +1 -0
  94. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/n_/n_xYqQYhwEMQknb3jFQnjlxxBE9TzMNHCdJ-bEyZFIw.cache +2 -0
  95. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/nx/nxTv3sKVUQZADJyM3dPaVmUA78MIsMLD_K279yN_GsI.cache +2 -0
  96. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/rJ/rJs4Papy2IL4JNryEPrcUBNrc64xnKDvqo0tfQu7NS4.cache +1 -0
  97. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/sE/sEz6mxBNwtI3fGWPauHZO9BzFXOvCivWdI9oGRKFT1o.cache +1 -0
  98. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/x7/x7PYh8DJvPykcEqpVab2vcY9-GFz-3cqtoMlRAu94Uc.cache +2 -0
  99. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/yR/yRtopfP_e1z4fqF6apVsxZDI3pCtWFSRfFkmpIOFcq0.cache +1 -0
  100. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/yX/yX8aXb78CFZHgzB3A6MVhi9nC0V-efr_Z8CvseJ6T0M.cache +0 -0
  101. data/spec/ext/rails/action_controller/obfuscator_spec.rb +30 -0
  102. data/spec/ext/rails/active_record/obfuscator_spec.rb +10 -0
  103. data/spec/rails_helper.rb +59 -0
  104. data/spec/scatter_swap_spec.rb +179 -0
  105. data/spec/spec_helper.rb +99 -0
  106. metadata +310 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ce8d2cc8324748134de851ff2700b17d1d9bc88b
4
+ data.tar.gz: 35096e12bfde8a594d2a2dfabcffd4db480636f3
5
+ SHA512:
6
+ metadata.gz: a6cc2d11257893757f3c17a515514ac377fb7f0f731c6550f24ecf494af03329738ce995255258263b361ad2618d8bf83116730dcbbd0b928429ab67252a0945
7
+ data.tar.gz: 1ef6a2cc17ca82c27d0ea8b0882229ac94d3bebdc940082797ebd2901e377c186457a4c76c6fae11b2c3a8b984ff6a30aa3d8572ce640aa6c9a4c602326bda29
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Nathan and David Amick
2
+
3
+ Copyright 2016 Patrice Lebel
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,21 @@
1
+ # ScatterSwapper
2
+
3
+ ### Installation
4
+
5
+ Add to your Gemfile:
6
+
7
+ ```ruby
8
+ gem 'scatter_swapper'
9
+ ```
10
+
11
+ Now, everytime an URL has a parameter with a name like `id` or `any_name_id`, it will be automatically converted to the decoded id.
12
+ So, no need to change your controller code when accessing resources.
13
+
14
+ Although, **URL generation isn't modified**... yet (still not sure if overriding `to_param` is the best solution), so you will need to pass the encoded id which is available through your model by the method `encoded_id`.
15
+
16
+ ### [Scatter Swap](https://github.com/altabyte/scatter_swap)
17
+
18
+ Since `scatter_swap` isn't maintained anymore, the code has been brought back into this gem.
19
+
20
+
21
+ This project rocks and uses MIT-LICENSE.
@@ -0,0 +1,30 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'ScatterSwapper'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.md')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+
21
+ load 'rails/tasks/statistics.rake'
22
+
23
+
24
+
25
+ require 'bundler/gem_tasks'
26
+ require 'rspec/core/rake_task'
27
+
28
+ RSpec::Core::RakeTask.new(:spec)
29
+
30
+ task :default => :spec
@@ -0,0 +1,18 @@
1
+ module ActionController
2
+ module Obfuscator
3
+ extend ActiveSupport::Concern
4
+
5
+ def params
6
+ return super if ScatterSwapper.config.skip_controller_params || self.class.try(:skip_obfuscator)
7
+
8
+ @_params ||= begin
9
+ super.each do |key, value|
10
+ if key =~ /(?:^|_)id$/
11
+ super[key] = ScatterSwap.reverse_hash(value, 0, 9).try(:to_i) # use 9, so standard 32-bit Int won't overflow
12
+ end
13
+ end
14
+ super
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,9 @@
1
+ module ActiveRecord
2
+ module Obfuscator
3
+ extend ActiveSupport::Concern
4
+
5
+ def encoded_id
6
+ ScatterSwap.hash(id, 0, 9).try(:to_i) # use 9, so standard 32-bit Int won't overflow
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,30 @@
1
+ require 'scatter_swap/version'
2
+ require 'scatter_swap/hasher'
3
+
4
+ module ScatterSwap
5
+
6
+ # Hash the given +plain_integer+ into its obfuscated +String+ form.
7
+ #
8
+ # @note To obtain the corresponding hashed *integer* value call {ScatterSwap.hash}(plain_integer).to_i
9
+ # @param [Fixnum] plain_integer the numeric value to be hashed.
10
+ # @param [Fixnum] spin the seed value for the hashing algorithm.
11
+ # @param [Fixnum] length the number of digits in the returned hash.
12
+ # @return [String] a '0' padded string of +length+ digits containing the hashed numeric value.
13
+ #
14
+ def self.hash(plain_integer, spin = 0, length = 10)
15
+ Hasher.new(plain_integer, spin, length).hash
16
+ end
17
+
18
+
19
+ # Reverse +hashed_integer+ from its obfuscated form to its serial value.
20
+ #
21
+ # @note To obtain the corresponding reverse-hashed *integer* value call {ScatterSwap.reverse_hash}(hashed_integer).to_i
22
+ # @param [Fixnum] hashed_integer the numeric value to be hashed.
23
+ # @param [Fixnum] spin the seed value for the hashing algorithm.
24
+ # @param [Fixnum] length the number of digits in the returned hash.
25
+ # @return [String] a '0' padded string of +length+ digits containing the reverse-hashed numeric value.
26
+ #
27
+ def self.reverse_hash(hashed_integer, spin = 0, length = 10)
28
+ Hasher.new(hashed_integer, spin, length).reverse_hash
29
+ end
30
+ end
@@ -0,0 +1,98 @@
1
+ module ScatterSwap
2
+ class Hasher
3
+
4
+ # @return [Array[Fixnum]]
5
+ attr_reader :working_array
6
+
7
+ # @return [Fixnum] the number of digits in the computed hashes.
8
+ attr_reader :length
9
+
10
+ # @return [Fixnum] A seed value to add some spice, so that different apps can have differently mapped hashes.
11
+ attr_reader :spin
12
+
13
+ # Construct a new +Hasher+.
14
+ # @param [Fixnum] integer the numeric value to be hashed/reversed.
15
+ # @param [Fixnum] spin a seed value.
16
+ # @param [Fixnum] length the number of digits in the computed hashes.
17
+ #
18
+ def initialize(integer, spin = 0, length = 10)
19
+ @original_integer = integer.freeze
20
+ @spin = (spin || 0).freeze
21
+ @length = length.freeze
22
+ zero_pad = integer.to_s.rjust(length, '0')
23
+ @working_array = zero_pad.split('').collect { |d| d.to_i }
24
+ end
25
+
26
+ # Obfuscate the original integer value to a zero-padded String of {#length} digits.
27
+ # @return [String] the obfuscated hash.
28
+ #
29
+ def hash
30
+ swap
31
+ scatter
32
+ completed_string
33
+ end
34
+
35
+ # De-obfuscate the original integer value to a zero-padded String of {#length} digits.
36
+ # @return [String] the de-obfuscated hash.
37
+ #
38
+ def reverse_hash
39
+ unscatter
40
+ unswap
41
+ completed_string
42
+ end
43
+
44
+
45
+ #-------------------------------------------------------------------------
46
+ private
47
+
48
+ def completed_string
49
+ @working_array.join
50
+ end
51
+
52
+ # We want a unique map for each place in the original number
53
+ def swapper_map(index)
54
+ array = (0..9).to_a
55
+ 10.times.collect.with_index do |i|
56
+ array.rotate!(index + i ^ spin).pop
57
+ end
58
+ end
59
+
60
+ # Using a unique map for each of the ten places,
61
+ # we swap out one number for another
62
+ def swap
63
+ @working_array = @working_array.collect.with_index do |digit, index|
64
+ swapper_map(index)[digit]
65
+ end
66
+ end
67
+
68
+ # Reverse swap
69
+ def unswap
70
+ @working_array = @working_array.collect.with_index do |digit, index|
71
+ swapper_map(index).rindex(digit)
72
+ end
73
+ end
74
+
75
+ # Rearrange the order of each digit in a reversible way by using the
76
+ # sum of the digits (which doesn't change regardless of order)
77
+ # as a key to record how they were scattered
78
+ def scatter
79
+ sum_of_digits = @working_array.inject(:+).to_i
80
+ @working_array = length.times.collect do
81
+ @working_array.rotate!(spin ^ sum_of_digits).pop
82
+ end
83
+ end
84
+
85
+ # Reverse the scatter
86
+ def unscatter
87
+ scattered_array = @working_array
88
+ sum_of_digits = scattered_array.inject(:+).to_i
89
+ @working_array = []
90
+ @working_array.tap do |unscatter|
91
+ length.times do
92
+ unscatter.push scattered_array.pop
93
+ unscatter.rotate! (sum_of_digits ^ spin) * -1
94
+ end
95
+ end
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,93 @@
1
+ require 'scatter_swap'
2
+
3
+ # This file is spike code and is not part of the library
4
+ #
5
+ # While developing this, I used this file to visualize what was going on with the numbers
6
+ #
7
+ # You can uncomment various methods at the bottom and then run it like this:
8
+ #
9
+ # watch -n1 ruby run_scatter_swap.rb
10
+ #
11
+ # tweak the code a bit and see instant visual changes in the generated numbers
12
+
13
+ def visualize_scatter_and_unscatter
14
+ # change this number to experiment with different values
15
+ rotations = 99
16
+
17
+ original = ScatterSwap.arrayify(123456789)
18
+ scattered = []
19
+ unscattered = []
20
+ puts original.join
21
+ puts "rotate!(#{rotations})"
22
+ 10.times do
23
+ puts original.rotate!(rotations).join + "->" + scattered.push(original.pop).join
24
+ end
25
+ puts "scattered"
26
+ puts scattered.join
27
+ 10.times do
28
+ puts unscattered.push(scattered.pop).join + "->" + unscattered.rotate!(rotations * -1).join
29
+ end
30
+
31
+ puts unscattered.join
32
+ end
33
+
34
+
35
+ def visualize_swapper_map
36
+ puts "swapper map"
37
+ 10.times do |index|
38
+ key = 1
39
+ puts ScatterSwap.swapper_map(index).join.to_s
40
+ end
41
+ end
42
+
43
+ def visualize_hash
44
+ puts "hash"
45
+ 40.times do |integer|
46
+ output = "|"
47
+ 3.times do |index|
48
+ output += " #{(integer + (123456789 * index)).to_s.rjust(5, ' ')}"
49
+ output += " => #{hashed = ScatterSwap.hash(integer + (123456789 * index) ) }"
50
+ output += " => #{ScatterSwap.reverse_hash(hashed) } |"
51
+ end
52
+ puts output
53
+ end
54
+ end
55
+
56
+
57
+ def visualize_scatter
58
+ puts "original scattered unscattered"
59
+ 20.times do |integer|
60
+ output = ""
61
+ 2.times do |index|
62
+ original = ScatterSwap.arrayify(integer + (123456789 * index))
63
+ scattered = ScatterSwap.scatter(original.clone)
64
+ unscattered = ScatterSwap.unscatter(scattered.clone)
65
+ output += "#{original.join}"
66
+ output += " => #{scattered.join}"
67
+ output += " => #{unscattered.join} | "
68
+ end
69
+ puts output
70
+ end
71
+ end
72
+
73
+
74
+ # find hash for lots of spins
75
+ def visualize_spin
76
+ 2000.times do |original|
77
+ hashed_values = []
78
+ 9000000000.times do |spin|
79
+ hashed = ScatterSwap.hash(original, spin)
80
+ if hashed_values.include? hashed
81
+ puts "collision: #{original} - #{spin} - #{hashed}"
82
+ break
83
+ end
84
+ hashed_values.push hashed
85
+ end
86
+ end
87
+ end
88
+
89
+ #visualize_spin
90
+ #visualize_hash
91
+ #visualize_scatter_and_unscatter
92
+ #visualize_scatter
93
+ #visualize_swapper_map
@@ -0,0 +1,3 @@
1
+ module ScatterSwap
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,8 @@
1
+ require 'scatter_swap'
2
+ require "scatter_swapper/engine"
3
+ require "ext/rails/active_record/obfuscator"
4
+ require "ext/rails/action_controller/obfuscator"
5
+
6
+ module ScatterSwapper
7
+ # Your code goes here...
8
+ end
@@ -0,0 +1,21 @@
1
+ module ScatterSwapper
2
+ @@config = nil
3
+
4
+ def self.configure
5
+ @@config ||= Configuration.new
6
+
7
+ if block_given?
8
+ yield config
9
+ end
10
+
11
+ config
12
+ end
13
+
14
+ def self.config
15
+ @@config || configure
16
+ end
17
+
18
+ class Configuration
19
+ attr_accessor :skip_controller_params
20
+ end
21
+ end
@@ -0,0 +1,23 @@
1
+ require 'scatter_swapper/configuration'
2
+
3
+ module ScatterSwapper
4
+ class Engine < ::Rails::Engine
5
+ initializer "scatter_swapper.configure" do
6
+ ActiveSupport.on_load :active_record do
7
+ ::ActiveRecord::Base.class_eval do
8
+ include ActiveRecord::Obfuscator
9
+ end
10
+ end
11
+
12
+ ActiveSupport.on_load :action_controller do
13
+ ::ActionController::Base.class_eval do
14
+ include ActionController::Obfuscator
15
+ end
16
+
17
+ ::ActionController::API.class_eval do
18
+ include ActionController::Obfuscator
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,3 @@
1
+ module ScatterSwapper
2
+ VERSION = '0.3.0'
3
+ end
@@ -0,0 +1,6 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require_relative 'config/application'
5
+
6
+ Rails.application.load_tasks
@@ -0,0 +1,4 @@
1
+
2
+ //= link_tree ../images
3
+ //= link_directory ../javascripts .js
4
+ //= link_directory ../stylesheets .css
@@ -0,0 +1,13 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file. JavaScript code in this file should be added after the last require_* statement.
9
+ //
10
+ // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require_tree .
@@ -0,0 +1,13 @@
1
+ // Action Cable provides the framework to deal with WebSockets in Rails.
2
+ // You can generate new channels where WebSocket features live using the rails generate channel command.
3
+ //
4
+ //= require action_cable
5
+ //= require_self
6
+ //= require_tree ./channels
7
+
8
+ (function() {
9
+ this.App || (this.App = {});
10
+
11
+ App.cable = ActionCable.createConsumer();
12
+
13
+ }).call(this);