jump_in 0.0.2 → 0.0.3
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 +4 -4
- data/lib/generators/jump_in/install_generator.rb +3 -4
- data/lib/jump_in.rb +0 -1
- data/lib/jump_in/authentication.rb +6 -4
- data/lib/jump_in/authentication/cookies.rb +9 -7
- data/lib/jump_in/authentication/session.rb +8 -5
- data/lib/jump_in/version.rb +1 -1
- data/spec/dummy/spec/modules/authentication_spec.rb +8 -3
- metadata +1 -3
- data/lib/generators/jump_in/config_initializer.rb +0 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 02f203abdbcb811bd639a3fa104d92a0652bd15c
|
4
|
+
data.tar.gz: f937a624cd2312f898fab4fea8100076501260d3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 02cea282d3b3aa8f9b4c965a048a9b8fd54f2064b6bc97665b08f20f3ec70932b13faaaf22b26f2eee8d30d4b77fd858b30b982fa73f4b837072191406055ff6
|
7
|
+
data.tar.gz: 614217631f5e9cad53d8899de4fd6e3ed45ae7de878ee7d2d0999b12435f18060dd375e5721845049d09cbba3f04a2b1060255e305a6446d32c09c624272137b
|
@@ -1,13 +1,12 @@
|
|
1
1
|
module JumpIn
|
2
2
|
module Generators
|
3
|
-
class
|
3
|
+
class InstallGenerator < Rails::Generators::Base
|
4
4
|
source_root File.expand_path('../../templates', __FILE__)
|
5
5
|
desc 'Creates JumpIn initializer for your application'
|
6
6
|
|
7
|
-
def
|
7
|
+
def copy_initializer
|
8
8
|
template 'jump_in_initializer.rb', 'config/initializers/jump_in.rb'
|
9
|
-
puts 'Install complete. You can now customize JumpIn defaults in your
|
10
|
-
config/initializers/jump_in.rb.'
|
9
|
+
puts 'Install complete. You can now customize JumpIn defaults in your config/initializers/jump_in.rb.'
|
11
10
|
end
|
12
11
|
end
|
13
12
|
end
|
data/lib/jump_in.rb
CHANGED
@@ -7,6 +7,8 @@ module JumpIn
|
|
7
7
|
base.extend(ClassMethods)
|
8
8
|
base.send :helper_method, :current_user, :logged_in? if
|
9
9
|
base.respond_to? :helper_method
|
10
|
+
base.const_set('GET_CURRENT_USER', [])
|
11
|
+
const_set('APP_MAIN_CONTROLLER', base)
|
10
12
|
end
|
11
13
|
|
12
14
|
# LOGGING IN
|
@@ -55,12 +57,12 @@ module JumpIn
|
|
55
57
|
# CLASS METHODS
|
56
58
|
|
57
59
|
module ClassMethods
|
58
|
-
def jumpin_callback(callback,
|
60
|
+
def jumpin_callback(callback, jumpin_method)
|
59
61
|
jumpin_constant = callback.upcase
|
60
|
-
unless constants.include?(jumpin_constant)
|
62
|
+
unless self.constants.include?(jumpin_constant)
|
61
63
|
const_set(jumpin_constant, [])
|
62
64
|
end
|
63
|
-
const_get(jumpin_constant) <<
|
65
|
+
const_get(jumpin_constant) << jumpin_method
|
64
66
|
end
|
65
67
|
|
66
68
|
def jumpin_use(persistence:)
|
@@ -77,7 +79,7 @@ module JumpIn
|
|
77
79
|
|
78
80
|
def get_current_user
|
79
81
|
current_user = nil
|
80
|
-
self.class
|
82
|
+
self.class.const_get(:GET_CURRENT_USER).each do |current_user_finder|
|
81
83
|
current_user = send(current_user_finder)
|
82
84
|
break if current_user
|
83
85
|
end
|
@@ -8,6 +8,15 @@ module JumpIn
|
|
8
8
|
klass.jumpin_callback :on_login, :set_user_cookies
|
9
9
|
klass.jumpin_callback :on_logout, :remove_user_cookies
|
10
10
|
klass.jumpin_callback :get_current_user, :current_user_from_cookies
|
11
|
+
|
12
|
+
APP_MAIN_CONTROLLER.class_eval do
|
13
|
+
def current_user_from_cookies
|
14
|
+
return nil unless cookies.signed[:jump_in_id] &&
|
15
|
+
cookies.signed[:jump_in_class]
|
16
|
+
klass = cookies.signed[:jump_in_class].constantize
|
17
|
+
klass.find_by(id: cookies.signed[:jump_in_id])
|
18
|
+
end
|
19
|
+
end
|
11
20
|
end
|
12
21
|
|
13
22
|
def set_user_cookies(user:)
|
@@ -22,13 +31,6 @@ module JumpIn
|
|
22
31
|
cookies.delete :jump_in_class
|
23
32
|
cookies.delete :jump_in_id
|
24
33
|
end
|
25
|
-
|
26
|
-
def current_user_from_cookies
|
27
|
-
return nil unless cookies.signed[:jump_in_id] &&
|
28
|
-
cookies.signed[:jump_in_class]
|
29
|
-
klass = cookies.signed[:jump_in_class].constantize
|
30
|
-
klass.find_by(id: cookies.signed[:jump_in_id])
|
31
|
-
end
|
32
34
|
end
|
33
35
|
end
|
34
36
|
end
|
@@ -8,6 +8,14 @@ module JumpIn
|
|
8
8
|
klass.jumpin_callback :on_login, :set_user_session
|
9
9
|
klass.jumpin_callback :on_logout, :remove_user_session
|
10
10
|
klass.jumpin_callback :get_current_user, :current_user_from_session
|
11
|
+
|
12
|
+
APP_MAIN_CONTROLLER.class_eval do
|
13
|
+
def current_user_from_session
|
14
|
+
return nil unless session[:jump_in_id] && session[:jump_in_class]
|
15
|
+
klass = session[:jump_in_class].constantize
|
16
|
+
klass.find_by(id: session[:jump_in_id])
|
17
|
+
end
|
18
|
+
end
|
11
19
|
end
|
12
20
|
|
13
21
|
def set_user_session(user:)
|
@@ -21,11 +29,6 @@ module JumpIn
|
|
21
29
|
session.delete :jump_in_id
|
22
30
|
end
|
23
31
|
|
24
|
-
def current_user_from_session
|
25
|
-
return nil unless session[:jump_in_id] && session[:jump_in_class]
|
26
|
-
klass = session[:jump_in_class].constantize
|
27
|
-
klass.find_by(id: session[:jump_in_id])
|
28
|
-
end
|
29
32
|
end
|
30
33
|
end
|
31
34
|
end
|
data/lib/jump_in/version.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
require_relative '../spec_helper'
|
2
|
-
|
3
|
-
class AuthenticationController < ActionController::Base
|
2
|
+
class AppMainController < ActionController::Base
|
4
3
|
include JumpIn::Authentication
|
4
|
+
end
|
5
|
+
|
6
|
+
class AuthenticationController < AppMainController
|
5
7
|
jumpin_use persistence: [:session, :cookies]
|
6
8
|
end
|
7
9
|
|
@@ -13,7 +15,10 @@ describe AuthenticationController, type: :controller do
|
|
13
15
|
it "it added default constants while including Session & Cookies" do
|
14
16
|
expect(subject.class.constants).to include(:ON_LOGIN)
|
15
17
|
expect(subject.class.constants).to include(:ON_LOGOUT)
|
16
|
-
|
18
|
+
end
|
19
|
+
|
20
|
+
it "it adds GET_CURRENT_USER to ApplicationController" do
|
21
|
+
expect(AppMainController.constants).to include(:GET_CURRENT_USER)
|
17
22
|
end
|
18
23
|
|
19
24
|
it "creates constant with method if constant didn't exist" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jump_in
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- KatarzynaT-B
|
@@ -22,7 +22,6 @@ extra_rdoc_files: []
|
|
22
22
|
files:
|
23
23
|
- MIT-LICENSE
|
24
24
|
- Rakefile
|
25
|
-
- lib/generators/jump_in/config_initializer.rb
|
26
25
|
- lib/generators/jump_in/install_generator.rb
|
27
26
|
- lib/generators/templates/jump_in_initializer.rb
|
28
27
|
- lib/jump_in.rb
|
@@ -154,4 +153,3 @@ test_files:
|
|
154
153
|
- spec/dummy/spec/modules/tokenator_spec.rb
|
155
154
|
- spec/dummy/spec/modules/authentication_spec.rb
|
156
155
|
- spec/dummy/Rakefile
|
157
|
-
has_rdoc:
|
@@ -1,13 +0,0 @@
|
|
1
|
-
module JumpIn
|
2
|
-
module Generators
|
3
|
-
class ConfigInitializerGenerator < Rails::Generators::Base
|
4
|
-
source_root File.expand_path("../../templates", __FILE__)
|
5
|
-
desc "Creates JumpIn initializer for your application"
|
6
|
-
|
7
|
-
def prepare_initializer
|
8
|
-
template "jump_in_initializer.rb", "config/initializers/jump_in.rb"
|
9
|
-
puts "Install complete. You can now customize JumpIn defaults in your config/initializers/jump_in.rb."
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|