current_me 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -20,22 +20,19 @@ Or install it yourself as:
20
20
 
21
21
  ### Controllers
22
22
 
23
- * When signing, use the `me=`
23
+ * When signing, use the `sign_in`
24
24
 
25
- self.me = user
25
+ sign_in user
26
+ (※`user` needs to be a user model)
26
27
 
27
28
  * To Transition to designated page if a user isn't signed in, use the `me!`
28
29
 
29
30
  me! signin_path
30
31
 
31
- * When redirect to the source before `me!`, use the `come_from`
32
-
33
- redirect_to come_from
34
-
35
- * When signing out, use the `bye`
32
+ * When signing out, use the `sign_out`
36
33
 
37
34
  def destroy
38
- bye
35
+ sign_out
39
36
  redirect_to :root
40
37
  end
41
38
 
data/lib/current_me.rb CHANGED
@@ -21,11 +21,11 @@ module CurrentMe
21
21
  end
22
22
 
23
23
  def me!(url)
24
- unless me?
25
- session[:come_from] = request.fullpath
24
+ redirect_to url unless me?
25
+ end
26
26
 
27
- redirect_to url
28
- end
27
+ def sign_in(user)
28
+ self.me = user
29
29
  end
30
30
 
31
31
  def me=(user)
@@ -35,11 +35,7 @@ module CurrentMe
35
35
  @me = user
36
36
  end
37
37
 
38
- def bye
38
+ def sign_out
39
39
  self.me = nil
40
40
  end
41
-
42
- def come_from
43
- session[:come_from]
44
- end
45
41
  end
@@ -1,3 +1,3 @@
1
1
  module CurrentMe
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -1,3 +1,10 @@
1
1
  class ApplicationController < ActionController::Base
2
2
  protect_from_forgery
3
+
4
+ private
5
+
6
+ def authenticate!
7
+ session[:origin] = request.fullpath
8
+ me! root_url
9
+ end
3
10
  end
@@ -1,7 +1,5 @@
1
1
  class RoomsController < ApplicationController
2
- before_filter do |c|
3
- c.me!(root_url)
4
- end
2
+ before_filter :authenticate!
5
3
 
6
4
  def index
7
5
  end
@@ -3,17 +3,18 @@ class SessionsController < ApplicationController
3
3
  end
4
4
 
5
5
  def create
6
+ origin = session[:origin]
6
7
  user = User.find_by_name(params[:name])
7
8
  if user
8
- self.me = user
9
- redirect_to come_from || user
9
+ sign_in user
10
+ redirect_to origin || user
10
11
  else
11
12
  render 'new'
12
13
  end
13
14
  end
14
15
 
15
16
  def destroy
16
- bye
17
+ sign_out
17
18
  redirect_to root_path
18
19
  end
19
20
  end
@@ -9,7 +9,7 @@ describe RoomsController do
9
9
 
10
10
  context 'ログインしている場合' do
11
11
  before {
12
- controller.me = user
12
+ controller.sign_in user
13
13
  get :index
14
14
  }
15
15
 
@@ -6,7 +6,7 @@ describe SessionsController do
6
6
 
7
7
  describe 'destroy' do
8
8
  before {
9
- controller.me = user
9
+ controller.sign_in user
10
10
  delete :destroy, {id: user.id}
11
11
  }
12
12
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: current_me
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
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: 2012-07-18 00:00:00.000000000 Z
12
+ date: 2012-07-31 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport