action-segue 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.editorconfig +9 -0
- data/.gitignore +3 -0
- data/.rspec +2 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +97 -0
- data/README.md +37 -0
- data/Rakefile +7 -0
- data/action-segue.gemspec +23 -0
- data/lib/action-segue.rb +19 -0
- data/lib/action_segue/segue.rb +10 -0
- data/lib/action_segue/segue_registration.rb +40 -0
- data/spec/action_segue/integration_spec.rb +35 -0
- data/spec/fixtures/controllers.rb +23 -0
- data/spec/fixtures/fake_application.rb +20 -0
- data/spec/spec_helper.rb +12 -0
- metadata +125 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b90ce3d4469b84001c3943b782e42fd6cfdf1b95
|
4
|
+
data.tar.gz: e892a1627ab29669d3f66c7d1148d8a2dd7b38a7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8efd253601337c233e0bb5a4cd94edf3c141f96567db1f9688eda0093784c58fd4209db6b3d8e4618f83b29dffac428c38ed0d64a12bfedb39d020ec9ceaa767
|
7
|
+
data.tar.gz: 384ba41ad591820698b6cd81bfcde02d76bd0b2165772ea14ac2c87a15f3fd317b93b645d4d7eda24f380086ac16f0e85dcb59b5adc383e6714a1c304c2dbb6f
|
data/.editorconfig
ADDED
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
action-segue (0.0.1)
|
5
|
+
railties (>= 4.2.0, < 5)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
actionpack (4.2.4)
|
11
|
+
actionview (= 4.2.4)
|
12
|
+
activesupport (= 4.2.4)
|
13
|
+
rack (~> 1.6)
|
14
|
+
rack-test (~> 0.6.2)
|
15
|
+
rails-dom-testing (~> 1.0, >= 1.0.5)
|
16
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
17
|
+
actionview (4.2.4)
|
18
|
+
activesupport (= 4.2.4)
|
19
|
+
builder (~> 3.1)
|
20
|
+
erubis (~> 2.7.0)
|
21
|
+
rails-dom-testing (~> 1.0, >= 1.0.5)
|
22
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
23
|
+
activesupport (4.2.4)
|
24
|
+
i18n (~> 0.7)
|
25
|
+
json (~> 1.7, >= 1.7.7)
|
26
|
+
minitest (~> 5.1)
|
27
|
+
thread_safe (~> 0.3, >= 0.3.4)
|
28
|
+
tzinfo (~> 1.1)
|
29
|
+
builder (3.2.2)
|
30
|
+
coderay (1.1.0)
|
31
|
+
diff-lcs (1.2.5)
|
32
|
+
erubis (2.7.0)
|
33
|
+
i18n (0.7.0)
|
34
|
+
json (1.8.3)
|
35
|
+
loofah (2.0.3)
|
36
|
+
nokogiri (>= 1.5.9)
|
37
|
+
method_source (0.8.2)
|
38
|
+
mini_portile (0.6.2)
|
39
|
+
minitest (5.8.0)
|
40
|
+
nokogiri (1.6.6.2)
|
41
|
+
mini_portile (~> 0.6.0)
|
42
|
+
pry (0.10.1)
|
43
|
+
coderay (~> 1.1.0)
|
44
|
+
method_source (~> 0.8.1)
|
45
|
+
slop (~> 3.4)
|
46
|
+
rack (1.6.4)
|
47
|
+
rack-test (0.6.3)
|
48
|
+
rack (>= 1.0)
|
49
|
+
rails-deprecated_sanitizer (1.0.3)
|
50
|
+
activesupport (>= 4.2.0.alpha)
|
51
|
+
rails-dom-testing (1.0.7)
|
52
|
+
activesupport (>= 4.2.0.beta, < 5.0)
|
53
|
+
nokogiri (~> 1.6.0)
|
54
|
+
rails-deprecated_sanitizer (>= 1.0.1)
|
55
|
+
rails-html-sanitizer (1.0.2)
|
56
|
+
loofah (~> 2.0)
|
57
|
+
railties (4.2.4)
|
58
|
+
actionpack (= 4.2.4)
|
59
|
+
activesupport (= 4.2.4)
|
60
|
+
rake (>= 0.8.7)
|
61
|
+
thor (>= 0.18.1, < 2.0)
|
62
|
+
rake (10.4.2)
|
63
|
+
rspec (3.3.0)
|
64
|
+
rspec-core (~> 3.3.0)
|
65
|
+
rspec-expectations (~> 3.3.0)
|
66
|
+
rspec-mocks (~> 3.3.0)
|
67
|
+
rspec-core (3.3.2)
|
68
|
+
rspec-support (~> 3.3.0)
|
69
|
+
rspec-expectations (3.3.1)
|
70
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
71
|
+
rspec-support (~> 3.3.0)
|
72
|
+
rspec-mocks (3.3.2)
|
73
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
74
|
+
rspec-support (~> 3.3.0)
|
75
|
+
rspec-rails (3.3.3)
|
76
|
+
actionpack (>= 3.0, < 4.3)
|
77
|
+
activesupport (>= 3.0, < 4.3)
|
78
|
+
railties (>= 3.0, < 4.3)
|
79
|
+
rspec-core (~> 3.3.0)
|
80
|
+
rspec-expectations (~> 3.3.0)
|
81
|
+
rspec-mocks (~> 3.3.0)
|
82
|
+
rspec-support (~> 3.3.0)
|
83
|
+
rspec-support (3.3.0)
|
84
|
+
slop (3.6.0)
|
85
|
+
thor (0.19.1)
|
86
|
+
thread_safe (0.3.5)
|
87
|
+
tzinfo (1.2.2)
|
88
|
+
thread_safe (~> 0.1)
|
89
|
+
|
90
|
+
PLATFORMS
|
91
|
+
ruby
|
92
|
+
|
93
|
+
DEPENDENCIES
|
94
|
+
action-segue!
|
95
|
+
pry (~> 0.10)
|
96
|
+
rspec (~> 3.3)
|
97
|
+
rspec-rails (~> 3.3)
|
data/README.md
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# ActionSegue
|
2
|
+
|
3
|
+
Allows you to create simple flows between controllers and actions which you can then complete or resume.
|
4
|
+
|
5
|
+
To begin with, you can register the beginning of a segue in a controller:
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
class MyController < ApplicationController
|
9
|
+
register_segue action: :index, as: :looking_at_index
|
10
|
+
|
11
|
+
def index
|
12
|
+
...
|
13
|
+
end
|
14
|
+
end
|
15
|
+
```
|
16
|
+
|
17
|
+
Then, at any point in the future, you can return to this segue start point. You must also pass in a fallback location which is used in the event no segue with the id is in progress.
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
complete_segue_with_redirect :looking_at_index, or_redirect_to: dashboard_path
|
21
|
+
```
|
22
|
+
|
23
|
+
If you just want to clear a segue to remove it from the stack, you can use `clear_segue`:
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
clear_segue :looking_at_index
|
27
|
+
```
|
28
|
+
|
29
|
+
If you don't know (or care) what current segue is in progress (useful in situations where many actions could lead away from their flow, and you just want to return to the original flow), you can just complete the current segue. This also requires a fallback location in case there is no current segue in progress.
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
complete_current_segue_with_redirect or_redirect_to: dashboard_path
|
33
|
+
```
|
34
|
+
|
35
|
+
## TODO
|
36
|
+
|
37
|
+
* Make it possible to use something other than the session to store segue info
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
$:.push File.expand_path("../lib", __FILE__)
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = "action-segue"
|
5
|
+
s.version = "1.0.0"
|
6
|
+
s.authors = ["Damien Timewell"]
|
7
|
+
s.email = ["mail@damientimewell.com"]
|
8
|
+
s.licenses = ['MIT']
|
9
|
+
s.homepage = "https://github.com/iZettle/action-segue"
|
10
|
+
s.summary = "Control Rails redirect flows with smarter redirect logic"
|
11
|
+
s.description = ""
|
12
|
+
|
13
|
+
s.add_dependency "railties", ">= 4.2.0", "< 5"
|
14
|
+
|
15
|
+
s.add_development_dependency "rspec", '~> 3.3'
|
16
|
+
s.add_development_dependency "rspec-rails", '~> 3.3'
|
17
|
+
s.add_development_dependency "pry", '~> 0.10'
|
18
|
+
|
19
|
+
s.files = `git ls-files`.split("\n")
|
20
|
+
s.test_files = `git ls-files -- spec/*`.split("\n")
|
21
|
+
|
22
|
+
s.require_paths = ["lib"]
|
23
|
+
end
|
data/lib/action-segue.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'action_controller'
|
2
|
+
require 'rails/railtie'
|
3
|
+
|
4
|
+
module ActionSegue
|
5
|
+
autoload :Segue, 'action_segue/segue'
|
6
|
+
autoload :SegueRegistration, 'action_segue/segue_registration'
|
7
|
+
|
8
|
+
def self.load_action_segue
|
9
|
+
ActiveSupport.on_load(:action_controller) do
|
10
|
+
include ActionSegue::SegueRegistration
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
class Railtie < Rails::Railtie
|
15
|
+
initializer "action-segue" do
|
16
|
+
ActionSegue.load_action_segue
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module ActionSegue
|
2
|
+
module SegueRegistration
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
module ClassMethods
|
6
|
+
def register_segue(action:, as:)
|
7
|
+
before_action only: action do
|
8
|
+
session[:action_segues] ||= ActiveSupport::OrderedHash.new
|
9
|
+
Rails.logger.debug "[ActionSegue] registering new segue as '#{as}' with params: #{params}"
|
10
|
+
session[:action_segues][as] = Segue.new(id: as, params: params)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
# Completes the segue named ++id++ and redirects back to the start point, or
|
16
|
+
# fallback url.
|
17
|
+
def complete_segue_with_redirect(id, or_redirect_to:)
|
18
|
+
if segue = session[:action_segues].delete(id)
|
19
|
+
Rails.logger.debug "[ActionSegue] completed '#{id}'. Redirecting to #{or_redirect_to}"
|
20
|
+
redirect_to url_for(segue.params)
|
21
|
+
else
|
22
|
+
Rails.logger.debug "[ActionSegue] no segue matched '#{id}'. Redirecting to #{or_redirect_to}"
|
23
|
+
redirect_to or_redirect_to
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
# Remove a segue from the stack
|
28
|
+
def clear_segue(id)
|
29
|
+
Rails.logger.debug "[ActionSegue] clearing segue '#{id}'"
|
30
|
+
session[:action_segues].delete(id)
|
31
|
+
end
|
32
|
+
|
33
|
+
# Completes the last segue, regardless of what it was, or redirects to the fallback
|
34
|
+
# if no segues are in progress.
|
35
|
+
def complete_current_segue_with_redirect(or_redirect_to:)
|
36
|
+
complete_segue_with_redirect session[:action_segues].keys.last, or_redirect_to: or_redirect_to
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe NamedSeguesController, type: :controller do
|
4
|
+
|
5
|
+
after(:each) do
|
6
|
+
session[:action_segues] = nil
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should store the segue on the first page" do
|
10
|
+
get :segue_start_page
|
11
|
+
expect(session[:action_segues][:named_segue].params).to eq({ "controller" => "named_segues", "action" => "segue_start_page" })
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should redirect to the segue entry point" do
|
15
|
+
get :segue_start_page
|
16
|
+
get :normal_page
|
17
|
+
get :segue_complete_page
|
18
|
+
expect(response).to redirect_to(segue_start_page_named_segue_path)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should remove the segue from the stack after it is completed" do
|
22
|
+
get :segue_start_page
|
23
|
+
get :normal_page
|
24
|
+
get :segue_complete_page
|
25
|
+
expect(session[:action_segues]).to eq({})
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should be possible to remove the segue" do
|
29
|
+
get :segue_start_page
|
30
|
+
get :segue_clear_page
|
31
|
+
get :segue_complete_page
|
32
|
+
expect(response).to redirect_to(normal_page_named_segue_path)
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class NamedSeguesController < ActionController::Base
|
2
|
+
include Rails.application.routes.url_helpers
|
3
|
+
|
4
|
+
register_segue action: :segue_start_page, as: :named_segue
|
5
|
+
|
6
|
+
def segue_start_page
|
7
|
+
render text: "Start page"
|
8
|
+
end
|
9
|
+
|
10
|
+
def normal_page
|
11
|
+
render text: "Normal page"
|
12
|
+
end
|
13
|
+
|
14
|
+
def segue_complete_page
|
15
|
+
complete_segue_with_redirect :named_segue, or_redirect_to: { action: :normal_page }
|
16
|
+
end
|
17
|
+
|
18
|
+
def segue_clear_page
|
19
|
+
clear_segue :named_segue
|
20
|
+
render text: "Clear page"
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Rails
|
2
|
+
class App
|
3
|
+
def env_config; {} end
|
4
|
+
def routes
|
5
|
+
return @routes if defined?(@routes)
|
6
|
+
@routes = ActionDispatch::Routing::RouteSet.new
|
7
|
+
@routes.draw do
|
8
|
+
resource :named_segue, only: [] do
|
9
|
+
collection do
|
10
|
+
get :segue_start_page, :normal_page, :segue_complete_page, :segue_clear_page
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
@routes
|
15
|
+
end
|
16
|
+
end
|
17
|
+
def self.application
|
18
|
+
@app ||= App.new
|
19
|
+
end
|
20
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require "pry"
|
2
|
+
require "rails/all"
|
3
|
+
require "action-segue"
|
4
|
+
|
5
|
+
ActionSegue.load_action_segue
|
6
|
+
|
7
|
+
require "rspec/rails"
|
8
|
+
require "fixtures/fake_application"
|
9
|
+
require "fixtures/controllers"
|
10
|
+
|
11
|
+
Rails.logger = Logger.new(STDOUT)
|
12
|
+
Rails.logger.level = Logger::ERROR
|
metadata
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: action-segue
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Damien Timewell
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-09-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: railties
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 4.2.0
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '5'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 4.2.0
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '5'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: rspec
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '3.3'
|
40
|
+
type: :development
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '3.3'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rspec-rails
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '3.3'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '3.3'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: pry
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0.10'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - "~>"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0.10'
|
75
|
+
description: ''
|
76
|
+
email:
|
77
|
+
- mail@damientimewell.com
|
78
|
+
executables: []
|
79
|
+
extensions: []
|
80
|
+
extra_rdoc_files: []
|
81
|
+
files:
|
82
|
+
- ".editorconfig"
|
83
|
+
- ".gitignore"
|
84
|
+
- ".rspec"
|
85
|
+
- Gemfile
|
86
|
+
- Gemfile.lock
|
87
|
+
- README.md
|
88
|
+
- Rakefile
|
89
|
+
- action-segue.gemspec
|
90
|
+
- lib/action-segue.rb
|
91
|
+
- lib/action_segue/segue.rb
|
92
|
+
- lib/action_segue/segue_registration.rb
|
93
|
+
- spec/action_segue/integration_spec.rb
|
94
|
+
- spec/fixtures/controllers.rb
|
95
|
+
- spec/fixtures/fake_application.rb
|
96
|
+
- spec/spec_helper.rb
|
97
|
+
homepage: https://github.com/iZettle/action-segue
|
98
|
+
licenses:
|
99
|
+
- MIT
|
100
|
+
metadata: {}
|
101
|
+
post_install_message:
|
102
|
+
rdoc_options: []
|
103
|
+
require_paths:
|
104
|
+
- lib
|
105
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
112
|
+
- - ">="
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '0'
|
115
|
+
requirements: []
|
116
|
+
rubyforge_project:
|
117
|
+
rubygems_version: 2.2.2
|
118
|
+
signing_key:
|
119
|
+
specification_version: 4
|
120
|
+
summary: Control Rails redirect flows with smarter redirect logic
|
121
|
+
test_files:
|
122
|
+
- spec/action_segue/integration_spec.rb
|
123
|
+
- spec/fixtures/controllers.rb
|
124
|
+
- spec/fixtures/fake_application.rb
|
125
|
+
- spec/spec_helper.rb
|