jump_back 0.2.1 → 0.2.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e19b6572c0f28169e9d691a3c4a06d2e4ec2d18b
4
- data.tar.gz: 4613caae3a14d45a1c6bbc5d412d0dd63fa28b5e
3
+ metadata.gz: 13b46750e5e152338c99ca95598a07da26f2520c
4
+ data.tar.gz: bcfc2c6ff049737adca0d7d039ec284e76caae0d
5
5
  SHA512:
6
- metadata.gz: 6c40a2cbba6764332b545150487e96a07e705d4f9189b83079d13c956b46c6a72d0c893ed5731e6e26a19a7b6305f16796d2835b2c7dc549650b7eff2d0c5de7
7
- data.tar.gz: 589cd35d811e8a6ee2fd27c506d2d92e5887c66da9b08ae0cb159b4281a5bb77928c06f79ef65774a802b1a342d79b7817544462cf1a74ac2df1a98c4efc74e4
6
+ metadata.gz: ae36bde7619da211b1d0277079188c376734124f926ebb65ccce53e5251c742a26ffd37e03651e67e9baea4292f2078ff41be724724fe3ee16c15f35ebc844b0
7
+ data.tar.gz: 44ec9bd6e00a0fa7f45c9f43ffe603386ae9b8d4cf2978d5a538613831100c013fc9ce1d255f40db3f9d682fdf3c1778520a15a0a323e6f7c258d5f16c500a8a
@@ -6,7 +6,7 @@ module JumpBack
6
6
  g.helper false
7
7
  end
8
8
  initializer "jump_back.methods" do |app|
9
- ApplicationController.send :include, JumpBack
9
+ ApplicationController.send :include, JumpBack::Redirection
10
10
  end
11
11
  end
12
12
  end
@@ -0,0 +1,19 @@
1
+ module JumpBack
2
+
3
+ class OptionsParser
4
+
5
+ def self.parse(path, options, default)
6
+ if path.is_a? Hash
7
+ options = path
8
+ path = default
9
+ end
10
+
11
+ jump_back_options = { offsite: options.delete(:offsite) }
12
+ {
13
+ redirect_options: options,
14
+ jump_back_options: jump_back_options,
15
+ path: path
16
+ }
17
+ end
18
+ end
19
+ end
@@ -1,24 +1,14 @@
1
1
  require 'jump_back/referer_interpreter'
2
2
  require 'jump_back/redirection_determiner'
3
+ require 'jump_back/options_parser'
3
4
 
4
5
  module JumpBack
5
6
 
6
- def redirect_back(path=root_path, options={})
7
- parsed_args = parse_jump_back_arguments(path, options)
8
- redirect_to RedirectionDeterminer.new(request, parsed_args[:path], parsed_args[:jump_back_options]).path, parsed_args[:redirect_options]
9
- end
10
-
11
- def parse_jump_back_arguments(path, options)
12
- if path.is_a? Hash
13
- options = path
14
- path = root_path
15
- end
7
+ module Redirection
16
8
 
17
- jump_back_options = { offsite: options.delete(:offsite) }
18
- {
19
- redirect_options: options,
20
- jump_back_options: jump_back_options,
21
- path: path
22
- }
9
+ def redirect_back(path=root_path, options={})
10
+ parsed_args = OptionsParser.parse(path, options, root_path)
11
+ redirect_to RedirectionDeterminer.new(request, parsed_args[:path], parsed_args[:jump_back_options]).path, parsed_args[:redirect_options]
12
+ end
23
13
  end
24
14
  end
@@ -1,4 +1,5 @@
1
1
  module JumpBack
2
+
2
3
  class RedirectionDeterminer
3
4
  attr_reader :path
4
5
 
@@ -7,7 +8,7 @@ module JumpBack
7
8
  end
8
9
 
9
10
  def path_determiner(request, path, options)
10
- RefererInterpreter.new.back?(request, options) ? :back : path
11
+ RefererInterpreter.back?(request, options) ? :back : path
11
12
  end
12
13
  end
13
14
  end
@@ -2,15 +2,15 @@ module JumpBack
2
2
 
3
3
  class RefererInterpreter
4
4
 
5
- def back?(request, options)
5
+ def self.back?(request, options)
6
6
  has_referer?(request) ? is_local?(request, options) ? true : false : false
7
7
  end
8
8
 
9
- def has_referer?(request)
9
+ def self.has_referer?(request)
10
10
  !request.env["HTTP_REFERER"].blank? and request.env["HTTP_REFERER"] != request.env["REQUEST_URI"]
11
11
  end
12
12
 
13
- def is_local?(request, options)
13
+ def self.is_local?(request, options)
14
14
  return true if options[:offsite]
15
15
  host = host(request.env["HTTP_REFERER"])
16
16
  !(host && host != request.host)
@@ -18,11 +18,11 @@ module JumpBack
18
18
 
19
19
  private
20
20
 
21
- def host(string)
21
+ def self.host(string)
22
22
  return URI.parse(string).host if uri? string
23
23
  end
24
24
 
25
- def uri?(string)
25
+ def self.uri?(string)
26
26
  uri = URI.parse(string)
27
27
  %w( http https ).include?(uri.scheme)
28
28
  rescue URI::BadURIError
@@ -1,15 +1,20 @@
1
+ require 'jump_back/options_parser'
2
+
1
3
  module JumpBack
2
4
 
3
- def save_referer
4
- session[:jump_back_stored_referer] ||= request.referer
5
- end
6
-
7
- def return_to_referer(path=root_path, options={})
8
- parsed_args = parse_jump_back_arguments(path, options)
9
- session[:jump_back_stored_referer] ? redirect_to(clear_referer, parsed_args[:redirect_options]) : redirect_to(parsed_args[:path], parsed_args[:redirect_options])
10
- end
11
-
12
- def clear_referer
13
- session.delete(:jump_back_stored_referer)
5
+ module Redirection
6
+
7
+ def save_referer
8
+ session[:jump_back_stored_referer] ||= request.referer
9
+ end
10
+
11
+ def return_to_referer(path=root_path, options={})
12
+ parsed_args = OptionsParser.parse(path, options, root_path)
13
+ session[:jump_back_stored_referer] ? redirect_to(clear_referer, parsed_args[:redirect_options]) : redirect_to(parsed_args[:path], parsed_args[:redirect_options])
14
+ end
15
+
16
+ def clear_referer
17
+ session.delete(:jump_back_stored_referer)
18
+ end
14
19
  end
15
20
  end
@@ -1,3 +1,3 @@
1
1
  module JumpBack
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
@@ -1,18 +1,36 @@
1
1
  describe ApplicationController do
2
2
 
3
- it 'should have the redirect_back method' do
4
- expect(ApplicationController.new).to respond_to :redirect_back
5
- end
6
-
7
- it 'should have the save_referer method' do
8
- expect(ApplicationController.new).to respond_to :save_referer
9
- end
10
-
11
- it 'should have the return_to_referer method' do
12
- expect(ApplicationController.new).to respond_to :return_to_referer
3
+ describe 'jump_back methods' do
4
+
5
+ it 'should have the redirect_back method' do
6
+ expect(ApplicationController.new).to respond_to :redirect_back
7
+ end
8
+
9
+ it 'should have the save_referer method' do
10
+ expect(ApplicationController.new).to respond_to :save_referer
11
+ end
12
+
13
+ it 'should have the return_to_referer method' do
14
+ expect(ApplicationController.new).to respond_to :return_to_referer
15
+ end
16
+
17
+ it 'should have the clear_referer method' do
18
+ expect(ApplicationController.new).to respond_to :clear_referer
19
+ end
13
20
  end
14
-
15
- it 'should have the clear_referer method' do
16
- expect(ApplicationController.new).to respond_to :clear_referer
21
+
22
+ describe 'private jump_back classes' do
23
+
24
+ it 'should not have the OptionsParser class' do
25
+ expect { ApplicationController::OptionsParser.new }.to raise_error
26
+ end
27
+
28
+ it 'should not have the RefererInterpreter class' do
29
+ expect { ApplicationController::RefererInterpreter.new }.to raise_error
30
+ end
31
+
32
+ it 'should not have the RedirectionDeterminer class' do
33
+ expect { ApplicationController::RedirectionDeterminer.new }.to raise_error
34
+ end
17
35
  end
18
36
  end
@@ -13,6 +13,7 @@ require "jump_back"
13
13
 
14
14
  module Dummy
15
15
  class Application < Rails::Application
16
+ config.secret_key_base = '19af9ac3d6f4fdbae6dc48cb0dfb99a825f38c144ce34f456e81da6f87fbf24571f3a79c9999419fe9f26a340b2b4fac202bd3b0cb907146992d6e80bc94309f'
16
17
  # Settings in config/environments/* take precedence over those specified here.
17
18
  # Application configuration should go into files in config/initializers
18
19
  # -- all .rb files in that directory are automatically loaded.
@@ -1,4 +1,4 @@
1
- Rails.application.configure do
1
+ Dummy::Application.configure do
2
2
  # Settings specified here will take precedence over those in config/application.rb.
3
3
 
4
4
  # In the development environment your application's code is reloaded on
@@ -20,7 +20,7 @@ Rails.application.configure do
20
20
  # config.action_dispatch.rack_cache = true
21
21
 
22
22
  # Disable Rails's static asset server (Apache or nginx will already do this).
23
- config.serve_static_assets = false
23
+ # config.serve_static_assets = false
24
24
 
25
25
  # Compress JavaScripts and CSS.
26
26
  config.assets.js_compressor = :uglifier
@@ -1,4 +1,4 @@
1
- Rails.application.configure do
1
+ Dummy::Application.configure do
2
2
  # Settings specified here will take precedence over those in config/application.rb.
3
3
 
4
4
  # The test environment is used exclusively to run your application's
@@ -13,7 +13,7 @@ Rails.application.configure do
13
13
  config.eager_load = false
14
14
 
15
15
  # Configure static asset server for tests with Cache-Control for performance.
16
- config.serve_static_assets = true
16
+ # config.serve_static_assets = true
17
17
  config.static_cache_control = 'public, max-age=3600'
18
18
 
19
19
  # Show full error reports and disable caching.
@@ -12,3 +12,94 @@
12
12
   (1.7ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
13
13
   (0.2ms) SELECT version FROM "schema_migrations"
14
14
   (1.0ms) INSERT INTO "schema_migrations" (version) VALUES ('0')
15
+  (1.6ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL) 
16
+  (0.6ms) select sqlite_version(*)
17
+  (1.7ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
18
+  (0.2ms) SELECT version FROM "schema_migrations"
19
+  (1.1ms) INSERT INTO "schema_migrations" (version) VALUES ('0')
20
+  (8.5ms) CREATE TABLE "schema_migrations" ("version" varchar NOT NULL) 
21
+  (0.3ms) select sqlite_version(*)
22
+  (1.6ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
23
+  (0.2ms) SELECT version FROM "schema_migrations"
24
+  (1.0ms) INSERT INTO "schema_migrations" (version) VALUES ('0')
25
+  (1.4ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL) 
26
+  (1.2ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
27
+  (0.2ms) SELECT version FROM "schema_migrations"
28
+  (1.2ms) INSERT INTO "schema_migrations" (version) VALUES ('0')
29
+  (1.2ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL) 
30
+  (1.1ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
31
+  (0.1ms) SELECT version FROM "schema_migrations"
32
+  (0.9ms) INSERT INTO "schema_migrations" (version) VALUES ('0')
33
+  (9.3ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL) 
34
+  (1.2ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
35
+  (0.2ms) SELECT version FROM "schema_migrations"
36
+  (1.1ms) INSERT INTO "schema_migrations" (version) VALUES ('0')
37
+  (9.3ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL) 
38
+  (1.3ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
39
+  (0.2ms) SELECT version FROM "schema_migrations"
40
+  (1.1ms) INSERT INTO "schema_migrations" (version) VALUES ('0')
41
+  (1.3ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL) 
42
+  (1.2ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
43
+  (0.2ms) SELECT version FROM "schema_migrations"
44
+  (1.1ms) INSERT INTO "schema_migrations" (version) VALUES ('0')
45
+  (1.8ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL) 
46
+  (1.5ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
47
+  (0.2ms) SELECT version FROM "schema_migrations"
48
+  (1.1ms) INSERT INTO "schema_migrations" (version) VALUES ('0')
49
+  (1.7ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL) 
50
+  (1.6ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
51
+  (0.2ms) SELECT version FROM "schema_migrations"
52
+  (1.1ms) INSERT INTO "schema_migrations" (version) VALUES ('0')
53
+  (3.4ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL) 
54
+  (0.1ms) select sqlite_version(*)
55
+  (2.2ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
56
+  (0.2ms) SELECT version FROM "schema_migrations"
57
+  (1.2ms) INSERT INTO "schema_migrations" (version) VALUES ('0')
58
+  (1.4ms) CREATE TABLE "schema_migrations" ("version" varchar NOT NULL) 
59
+  (0.1ms) select sqlite_version(*)
60
+  (1.2ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
61
+  (0.1ms) SELECT version FROM "schema_migrations"
62
+  (1.2ms) INSERT INTO "schema_migrations" (version) VALUES ('0')
63
+  (1.7ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL) 
64
+  (1.9ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
65
+  (0.2ms) SELECT version FROM "schema_migrations"
66
+  (1.1ms) INSERT INTO "schema_migrations" (version) VALUES ('0')
67
+  (1.5ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL) 
68
+  (1.3ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
69
+  (0.2ms) SELECT version FROM "schema_migrations"
70
+  (1.0ms) INSERT INTO "schema_migrations" (version) VALUES ('0')
71
+  (1.2ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL) 
72
+  (1.2ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
73
+  (0.2ms) SELECT version FROM "schema_migrations"
74
+  (1.3ms) INSERT INTO "schema_migrations" (version) VALUES ('0')
75
+  (1.1ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL) 
76
+  (1.0ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
77
+  (0.1ms) SELECT version FROM "schema_migrations"
78
+  (1.1ms) INSERT INTO "schema_migrations" (version) VALUES ('0')
79
+  (9.3ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL) 
80
+  (0.6ms) select sqlite_version(*)
81
+  (1.4ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
82
+  (0.2ms) SELECT version FROM "schema_migrations"
83
+  (1.1ms) INSERT INTO "schema_migrations" (version) VALUES ('0')
84
+  (9.6ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL) 
85
+  (0.1ms) select sqlite_version(*)
86
+  (1.5ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
87
+  (0.2ms) SELECT version FROM "schema_migrations"
88
+  (1.2ms) INSERT INTO "schema_migrations" (version) VALUES ('0')
89
+  (8.5ms) CREATE TABLE "schema_migrations" ("version" varchar NOT NULL) 
90
+  (0.1ms) select sqlite_version(*)
91
+  (1.3ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
92
+  (0.2ms) SELECT version FROM "schema_migrations"
93
+  (1.2ms) INSERT INTO "schema_migrations" (version) VALUES ('0')
94
+  (1.5ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL) 
95
+  (1.3ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
96
+  (0.2ms) SELECT version FROM "schema_migrations"
97
+  (1.1ms) INSERT INTO "schema_migrations" (version) VALUES ('0')
98
+  (1.1ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL) 
99
+  (1.1ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
100
+  (0.1ms) SELECT version FROM "schema_migrations"
101
+  (0.9ms) INSERT INTO "schema_migrations" (version) VALUES ('0')
102
+  (3.0ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL) 
103
+  (1.7ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
104
+  (0.2ms) SELECT version FROM "schema_migrations"
105
+  (1.2ms) INSERT INTO "schema_migrations" (version) VALUES ('0')