devise-better_routes 0.0.1 → 0.0.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.
- data/README.md +19 -0
- data/devise-better_routes.gemspec +1 -1
- data/lib/devise/better_routes.rb +11 -4
- data/lib/devise/better_routes/version.rb +1 -1
- data/spec/devise/better_routes_spec.rb +19 -19
- data/spec/rails_app/app/controllers/me_controller.rb +2 -0
- data/spec/rails_app/config/routes.rb +1 -1
- metadata +7 -7
- data/spec/rails_app/app/controllers/current_rails_programmers_controller.rb +0 -2
data/README.md
CHANGED
@@ -56,6 +56,25 @@ Then you can create two controllers as follows:
|
|
56
56
|
end
|
57
57
|
|
58
58
|
|
59
|
+
## Option
|
60
|
+
|
61
|
+
If you don't like "current_user", you can specify the name.
|
62
|
+
|
63
|
+
# config/routes.rb
|
64
|
+
devise_for :users, path_names: {current_user: 'me'}
|
65
|
+
|
66
|
+
Do you like this one?
|
67
|
+
|
68
|
+
users POST /users(.:format) users#create
|
69
|
+
new_user GET /users/new(.:format) users#new
|
70
|
+
cancel_me GET /me/cancel(.:format) me#cancel
|
71
|
+
edit_me GET /me/edit(.:format) me#edit
|
72
|
+
me PATCH /me(.:format) me#update
|
73
|
+
PUT /me(.:format) me#update
|
74
|
+
DELETE /me(.:format) me#destroy
|
75
|
+
|
76
|
+
|
77
|
+
|
59
78
|
## Installation
|
60
79
|
|
61
80
|
Add this line to your application's Gemfile:
|
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.email = ['tkawa@4bit.net']
|
11
11
|
spec.description = %q{Better routes patch for Devise}
|
12
12
|
spec.summary = %q{Better routes patch for Devise}
|
13
|
-
spec.homepage = ''
|
13
|
+
spec.homepage = 'https://github.com/tkawa/devise-better_routes'
|
14
14
|
spec.license = 'MIT'
|
15
15
|
|
16
16
|
spec.files = `git ls-files`.split($/)
|
data/lib/devise/better_routes.rb
CHANGED
@@ -9,15 +9,16 @@ module Devise
|
|
9
9
|
def self.override_registration_helpers!(registration_routes = nil)
|
10
10
|
helper_mappings = {
|
11
11
|
new_registration: 'new_#{scope}',
|
12
|
-
edit_registration: '
|
13
|
-
cancel_registration: '
|
12
|
+
edit_registration: 'edit_#{current_resource_name}',
|
13
|
+
cancel_registration: 'cancel_#{current_resource_name}'
|
14
14
|
}
|
15
15
|
[:path, :url].each do |path_or_url|
|
16
16
|
class_eval <<-URL_HELPERS, __FILE__, __LINE__ + 1
|
17
17
|
def registration_#{path_or_url}(resource_or_scope, *args)
|
18
18
|
scope = Devise::Mapping.find_scope!(resource_or_scope)
|
19
|
-
|
20
|
-
|
19
|
+
current_resource_name = _devise_path_name(scope, "current_\#{scope}")
|
20
|
+
if respond_to?(:controller_name) && controller_name == current_resource_name.pluralize
|
21
|
+
send("\#{current_resource_name}_#{path_or_url}", *args)
|
21
22
|
else
|
22
23
|
send("\#{scope.to_s.pluralize}_#{path_or_url}", *args)
|
23
24
|
end
|
@@ -28,6 +29,7 @@ module Devise
|
|
28
29
|
class_eval <<-URL_HELPERS, __FILE__, __LINE__ + 1
|
29
30
|
def #{method}(resource_or_scope, *args)
|
30
31
|
scope = Devise::Mapping.find_scope!(resource_or_scope)
|
32
|
+
current_resource_name = _devise_path_name(scope, "current_\#{scope}")
|
31
33
|
send("#{new_name}_#{path_or_url}", *args)
|
32
34
|
end
|
33
35
|
URL_HELPERS
|
@@ -39,6 +41,11 @@ module Devise
|
|
39
41
|
def self.run_generate_hooks!
|
40
42
|
self.override_registration_helpers!(Devise::URL_HELPERS[:registration])
|
41
43
|
end
|
44
|
+
|
45
|
+
def _devise_path_name(scope, name)
|
46
|
+
Devise.mappings[scope].path_names[name.to_sym]
|
47
|
+
end
|
48
|
+
private :_devise_path_name
|
42
49
|
end
|
43
50
|
end
|
44
51
|
|
@@ -36,18 +36,18 @@ describe Devise::BetterRoutes do
|
|
36
36
|
it 'routes to rails_programmers#new' do
|
37
37
|
expect(get('/rails_programmers/new')).to route_to('rails_programmers#new')
|
38
38
|
end
|
39
|
-
it 'routes to
|
40
|
-
expect(get('/
|
39
|
+
it 'routes to me#cancel' do
|
40
|
+
expect(get('/me/cancel')).to route_to('me#cancel')
|
41
41
|
end
|
42
|
-
it 'routes to
|
43
|
-
expect(get('/
|
42
|
+
it 'routes to me#edit' do
|
43
|
+
expect(get('/me/edit')).to route_to('me#edit')
|
44
44
|
end
|
45
|
-
it 'routes to
|
46
|
-
expect(put('/
|
47
|
-
#expect(patch('/
|
45
|
+
it 'routes to me#update' do
|
46
|
+
expect(put('/me')).to route_to('me#update')
|
47
|
+
#expect(patch('/me')).to route_to('me#update')
|
48
48
|
end
|
49
|
-
it 'routes to
|
50
|
-
expect(delete('/
|
49
|
+
it 'routes to me#destroy' do
|
50
|
+
expect(delete('/me')).to route_to('me#destroy')
|
51
51
|
end
|
52
52
|
end
|
53
53
|
end
|
@@ -83,25 +83,25 @@ describe Devise::BetterRoutes do
|
|
83
83
|
describe 'rails_programmers' do
|
84
84
|
specify { expect(rails_programmers_path).to eq '/rails_programmers' }
|
85
85
|
specify { expect(new_rails_programmer_path).to eq '/rails_programmers/new' }
|
86
|
-
specify { expect(
|
87
|
-
specify { expect(
|
88
|
-
specify { expect(
|
86
|
+
specify { expect(cancel_me_path).to eq '/me/cancel' }
|
87
|
+
specify { expect(edit_me_path).to eq '/me/edit' }
|
88
|
+
specify { expect(me_path).to eq '/me' }
|
89
89
|
it 'registration_path is delegated to rails_programmers_path' do
|
90
90
|
expect(registration_path(:rails_programmer)).to eq rails_programmers_path
|
91
91
|
end
|
92
|
-
it 'registration_path is delegated to
|
93
|
-
instance_eval { def controller_name; '
|
94
|
-
expect(registration_path(:rails_programmer)).to eq
|
92
|
+
it 'registration_path is delegated to me_path on me' do
|
93
|
+
instance_eval { def controller_name; 'me' end }
|
94
|
+
expect(registration_path(:rails_programmer)).to eq me_path
|
95
95
|
instance_eval { undef controller_name }
|
96
96
|
end
|
97
97
|
it 'new_registration_path is delegated to new_rails_programmer_path' do
|
98
98
|
expect(new_registration_path(:rails_programmer)).to eq new_rails_programmer_path
|
99
99
|
end
|
100
|
-
it 'cancel_registration_path is delegated to
|
101
|
-
expect(cancel_registration_path(:rails_programmer)).to eq
|
100
|
+
it 'cancel_registration_path is delegated to cancel_me_path' do
|
101
|
+
expect(cancel_registration_path(:rails_programmer)).to eq cancel_me_path
|
102
102
|
end
|
103
|
-
it 'edit_registration_path is delegated to
|
104
|
-
expect(edit_registration_path(:rails_programmer)).to eq
|
103
|
+
it 'edit_registration_path is delegated to edit_me_path' do
|
104
|
+
expect(edit_registration_path(:rails_programmer)).to eq edit_me_path
|
105
105
|
end
|
106
106
|
end
|
107
107
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: devise-better_routes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-06-
|
12
|
+
date: 2013-06-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: devise
|
@@ -147,8 +147,8 @@ files:
|
|
147
147
|
- spec/rails_app/app/assets/stylesheets/application.css
|
148
148
|
- spec/rails_app/app/controllers/application_controller.rb
|
149
149
|
- spec/rails_app/app/controllers/concerns/.keep
|
150
|
-
- spec/rails_app/app/controllers/current_rails_programmers_controller.rb
|
151
150
|
- spec/rails_app/app/controllers/current_users_controller.rb
|
151
|
+
- spec/rails_app/app/controllers/me_controller.rb
|
152
152
|
- spec/rails_app/app/controllers/rails_programmers_controller.rb
|
153
153
|
- spec/rails_app/app/controllers/users_controller.rb
|
154
154
|
- spec/rails_app/app/helpers/application_helper.rb
|
@@ -184,7 +184,7 @@ files:
|
|
184
184
|
- spec/rails_app/public/500.html
|
185
185
|
- spec/rails_app/public/favicon.ico
|
186
186
|
- spec/spec_helper.rb
|
187
|
-
homepage:
|
187
|
+
homepage: https://github.com/tkawa/devise-better_routes
|
188
188
|
licenses:
|
189
189
|
- MIT
|
190
190
|
post_install_message:
|
@@ -199,7 +199,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
199
199
|
version: '0'
|
200
200
|
segments:
|
201
201
|
- 0
|
202
|
-
hash:
|
202
|
+
hash: 4262153083475956853
|
203
203
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
204
204
|
none: false
|
205
205
|
requirements:
|
@@ -208,7 +208,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
208
208
|
version: '0'
|
209
209
|
segments:
|
210
210
|
- 0
|
211
|
-
hash:
|
211
|
+
hash: 4262153083475956853
|
212
212
|
requirements: []
|
213
213
|
rubyforge_project:
|
214
214
|
rubygems_version: 1.8.24
|
@@ -223,8 +223,8 @@ test_files:
|
|
223
223
|
- spec/rails_app/app/assets/stylesheets/application.css
|
224
224
|
- spec/rails_app/app/controllers/application_controller.rb
|
225
225
|
- spec/rails_app/app/controllers/concerns/.keep
|
226
|
-
- spec/rails_app/app/controllers/current_rails_programmers_controller.rb
|
227
226
|
- spec/rails_app/app/controllers/current_users_controller.rb
|
227
|
+
- spec/rails_app/app/controllers/me_controller.rb
|
228
228
|
- spec/rails_app/app/controllers/rails_programmers_controller.rb
|
229
229
|
- spec/rails_app/app/controllers/users_controller.rb
|
230
230
|
- spec/rails_app/app/helpers/application_helper.rb
|