back_former 0.1.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 2d14b25426daed3f12f6815d94356b7e023707f5e7164ba09556c83d124890d8
4
+ data.tar.gz: 3090cef08a97ace4dd49bf17490d0d846ba4ffd013b777d83b657a4735c092ef
5
+ SHA512:
6
+ metadata.gz: c0fbaa14553463bfdc2c9767d41388903b70b92a35b16d0b9a95aec4c4cd3dafab5b7ed4fe95d475aa4a9f125fb6ce0b824700df48e51311d4cf65ecb342a39c
7
+ data.tar.gz: 13d437b9fa7c4ac8008dfbc148a3084228c623cfc4a0e949c48a87d66d9f940d31da299e2eaaa8345e6cc02fec5c02f0f7d0cc7495dc0ed7a51aeb9d848436d0
@@ -0,0 +1,20 @@
1
+ Copyright 2019 naari3
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,60 @@
1
+ # BackFormer
2
+ Improved redirect back in rails.
3
+
4
+ In Rails 5, we have new method `#redirect_back`, but this method is feature which seeing referer only. This may be lack of function.
5
+ Example, please imagine when you implement controller they have to login.
6
+ You should redirect from login needed controller to `new` action ( `GET /login` form, input) and then redirect to `create` action ( `POST /login` evaluate),
7
+ but when user has moved from new to create, referer is expectly overriding `GET /login` and you can't redirect back to login needed controller with `#redirect_back`.
8
+
9
+ This gem provide feature which store previous url, redirect stored url and skip storing url. they makes it possible to redirect after logging in.
10
+
11
+ ## Installation
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'back_former'
16
+ ```
17
+
18
+ And then execute:
19
+ ```bash
20
+ $ bundle
21
+ ```
22
+
23
+ Or install it yourself as:
24
+ ```bash
25
+ $ gem install back_former
26
+ ```
27
+
28
+ ## Usage
29
+
30
+ ```ruby
31
+ class ApplicationController
32
+ before_action :save_previous_path # save current page path to your session
33
+ end
34
+
35
+ class LoginNeededController
36
+ before_action -> {
37
+ redirect_to login_path unless logged_in?
38
+ }
39
+ def index; end
40
+ end
41
+
42
+ class LoginController
43
+ skip_before_action :save_previous_path
44
+ def new; end
45
+
46
+ def create
47
+ redirect_back_former
48
+ end
49
+ end
50
+ ```
51
+
52
+ 1. Access to `/login_needed/` then redirect `/login`
53
+ 2. Post request to `/login (create)`
54
+ 3. redirect to `/login_needed/`
55
+
56
+ ## Contributing
57
+ Contribution directions go here.
58
+
59
+ ## License
60
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ begin
4
+ require 'bundler/setup'
5
+ rescue LoadError
6
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
7
+ end
8
+
9
+ require 'rdoc/task'
10
+
11
+ RDoc::Task.new(:rdoc) do |rdoc|
12
+ rdoc.rdoc_dir = 'rdoc'
13
+ rdoc.title = 'BackFormer'
14
+ rdoc.options << '--line-numbers'
15
+ rdoc.rdoc_files.include('README.md')
16
+ rdoc.rdoc_files.include('lib/**/*.rb')
17
+ end
18
+
19
+ require 'bundler/gem_tasks'
20
+
21
+ # add rspec rake task
22
+ require 'rspec/core/rake_task'
23
+ RSpec::Core::RakeTask.new(:spec)
24
+ task default: :spec
25
+
26
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'back_former/engine'
4
+ require 'back_former/redirecting'
5
+
6
+ module BackFormer
7
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BackFormer
4
+ class Engine < ::Rails::Engine
5
+ config.generators do |g|
6
+ g.test_framework :rspec, fixture: false
7
+ g.assets false
8
+ g.helper false
9
+ end
10
+
11
+ initializer 'back_former.methods' do |_app|
12
+ ActiveSupport.on_load :action_controller do
13
+ include BackFormer::Redirecting
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BackFormer
4
+ module Redirecting
5
+ def redirect_back_former(path = root_path, options = {})
6
+ redirect_to(session[:back_former_previous_path] || path, options)
7
+ end
8
+
9
+ def save_previous_path
10
+ session[:back_former_previous_path] = request.path
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BackFormer
4
+ VERSION = '0.1.1'
5
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ # desc "Explaining what the task does"
4
+ # task :back_former do
5
+ # # Task goes here
6
+ # end
metadata ADDED
@@ -0,0 +1,136 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: back_former
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - naari3
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-02-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 5.1.6
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 5.1.6
27
+ - !ruby/object:Gem::Dependency
28
+ name: pry
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry-byebug
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: rubocop
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: sqlite3
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 1.3.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 1.3.0
97
+ description: Improved redirect back in rails
98
+ email:
99
+ - naari.named@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - MIT-LICENSE
105
+ - README.md
106
+ - Rakefile
107
+ - lib/back_former.rb
108
+ - lib/back_former/engine.rb
109
+ - lib/back_former/redirecting.rb
110
+ - lib/back_former/version.rb
111
+ - lib/tasks/back_former_tasks.rake
112
+ homepage: https://github.com/naari3/back_former
113
+ licenses:
114
+ - MIT
115
+ metadata: {}
116
+ post_install_message:
117
+ rdoc_options: []
118
+ require_paths:
119
+ - lib
120
+ required_ruby_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ required_rubygems_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ requirements: []
131
+ rubyforge_project:
132
+ rubygems_version: 2.7.3
133
+ signing_key:
134
+ specification_version: 4
135
+ summary: Improved redirect back in rails
136
+ test_files: []