session_off 0.3.1 → 0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/README.md +16 -10
  2. data/lib/session_off.rb +23 -3
  3. metadata +63 -41
data/README.md CHANGED
@@ -1,16 +1,16 @@
1
1
  SessionOff
2
2
  ==========
3
3
 
4
- If You're old enough in Rails age, You should remember the times when sessions
4
+ If you're old enough in Rails age, you should remember the times when sessions
5
5
  where not (that) lazy loaded and one could have turned them off declaratively.
6
6
 
7
7
  I really liked this explicit approach and sure started missing it ever since it
8
- got redesigned. Now in theory it sounds great that if You do not touch the session
9
- it won't be loaded, but in practice enforcing Your code to not invoke the session
8
+ got redesigned. Now in theory it sounds great that if you do not touch the session
9
+ it won't be loaded, but in practice enforcing your code to not invoke the session
10
10
  method (and thus not send a session cookie) for a (session-less) mobile client
11
11
  while sharing the same code for "normal" (session-aware) clients, is just *hard*.
12
- You need to come up with a session state management and even so it's non-trivial
13
- to track down "bugs" where You access the session while not really wanting to !
12
+ you need to come up with a session state management and even so it's non-trivial
13
+ to track down "bugs" where you access the session while not really wanting to.
14
14
 
15
15
  How about we bring the love back and allow (once again) for a session to be off :
16
16
 
@@ -27,7 +27,7 @@ But only while using the `session` (instance) method in controllers, it does
27
27
  leave the `request.session` as is. Accessing the `request.session` directly will
28
28
  work (and load the session) no matter if the session is off. This is intentional
29
29
  as the goal of the plugin is to provide session management for controller code
30
- and not the whole middleware stack !
30
+ and not the whole middleware stack.
31
31
  I also highly discourage against using `session` inside model classes, as it is a
32
32
  lack of good desing, after all session's just an abstracted request "extension".
33
33
 
@@ -41,7 +41,7 @@ If unhappy with what happens while the session is turned off for an action :
41
41
 
42
42
  def disable_session
43
43
  super # sets @_session = false (disabled)
44
- send_mama_a_kiss # or whatever You want !
44
+ send_mama_a_kiss # or whatever you want !
45
45
  end
46
46
 
47
47
  end
@@ -56,7 +56,7 @@ or as a plain-old rails plugin :
56
56
 
57
57
  script/plugin install git://github.com/kares/session_off.git
58
58
 
59
- The code has been tested and should work on Rails **3.x** as well as **2.3**.
59
+ Gem has been tested and should work with Rails **3.x** as well as **2.3**.
60
60
 
61
61
  Example
62
62
  =======
@@ -71,6 +71,12 @@ or how to be nice to robots :
71
71
  # turn off sessions if this is a request from a robot
72
72
  session :off, :if => proc { |request| request.user_agent =~ ROBOTS }
73
73
 
74
- end
74
+ def greetings
75
+ if session
76
+ render :text => "SHALL WE PLAY A GAME ?"
77
+ else
78
+ render :text => "F*ck OFF, Stupid BOT !"
79
+ end
80
+ end
75
81
 
76
- <http://log.kares.org/search/label/session_off>
82
+ end
@@ -33,6 +33,23 @@ module SessionOff
33
33
 
34
34
  module ClassMethods
35
35
 
36
+ def self.extended(base)
37
+ return if base.respond_to?(:session_options_array)
38
+ if base.respond_to?(:class_attribute)
39
+ base.class_attribute :session_options_array,
40
+ :instance_reader => false, :instance_writer => false
41
+ else
42
+ base.class_eval do
43
+ def session_options_array
44
+ read_inheritable_attribute(:session_options)
45
+ end
46
+ def session_options_array=(array)
47
+ write_inheritable_array(:session_options, array)
48
+ end
49
+ end
50
+ end
51
+ end
52
+
36
53
  # Specify how sessions ought to be managed for a subset of the actions on
37
54
  # the controller. Like filters, you can specify <tt>:only</tt> and
38
55
  # <tt>:except</tt> clauses to restrict the subset, otherwise options
@@ -84,12 +101,15 @@ module SessionOff
84
101
  if options[:only] && options[:except]
85
102
  raise ArgumentError, "only one of either :only or :except are allowed"
86
103
  end
87
-
88
- write_inheritable_array(:session_options, [ options ])
104
+
105
+ if session_options_array
106
+ self.session_options_array += [ options ]
107
+ else
108
+ self.session_options_array = [ options ]
109
+ end
89
110
  end
90
111
 
91
112
  def session_options_for(request, action)
92
- session_options_array = read_inheritable_attribute(:session_options)
93
113
  session_options =
94
114
  defined?(ActionController::Base.session_options) ?
95
115
  ActionController::Base.session_options.dup : {}
metadata CHANGED
@@ -1,47 +1,60 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: session_off
3
- version: !ruby/object:Gem::Version
4
- version: 0.3.1
3
+ version: !ruby/object:Gem::Version
4
+ hash: 3
5
5
  prerelease:
6
+ segments:
7
+ - 0
8
+ - 4
9
+ version: "0.4"
6
10
  platform: ruby
7
- authors:
11
+ authors:
8
12
  - Karol Bucek
9
13
  autorequire:
10
14
  bindir: bin
11
15
  cert_chain: []
12
- date: 2011-11-03 00:00:00.000000000Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
16
+
17
+ date: 2012-01-22 00:00:00 Z
18
+ dependencies:
19
+ - !ruby/object:Gem::Dependency
15
20
  name: actionpack
16
- requirement: &75250950 !ruby/object:Gem::Requirement
21
+ prerelease: false
22
+ requirement: &id001 !ruby/object:Gem::Requirement
17
23
  none: false
18
- requirements:
19
- - - ! '>='
20
- - !ruby/object:Gem::Version
21
- version: '2.3'
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ hash: 5
28
+ segments:
29
+ - 2
30
+ - 3
31
+ version: "2.3"
22
32
  type: :runtime
23
- prerelease: false
24
- version_requirements: *75250950
25
- - !ruby/object:Gem::Dependency
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
26
35
  name: mocha
27
- requirement: &75250630 !ruby/object:Gem::Requirement
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
28
38
  none: false
29
- requirements:
30
- - - ! '>='
31
- - !ruby/object:Gem::Version
32
- version: '0'
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ hash: 3
43
+ segments:
44
+ - 0
45
+ version: "0"
33
46
  type: :development
34
- prerelease: false
35
- version_requirements: *75250630
36
- description: session :off, :only => :foo, :if => Proc.new { |req| req.params[:bar]
37
- }
38
- email:
47
+ version_requirements: *id002
48
+ description: session :off, :only => :foo, :if => Proc.new { |req| req.params[:bar] }
49
+ email:
39
50
  - self@kares.org
40
51
  executables: []
52
+
41
53
  extensions: []
42
- extra_rdoc_files:
54
+
55
+ extra_rdoc_files:
43
56
  - README.md
44
- files:
57
+ files:
45
58
  - lib/session_off.rb
46
59
  - LICENSE
47
60
  - README.md
@@ -51,29 +64,38 @@ files:
51
64
  - test/test_helper.rb
52
65
  homepage: http://github.com/kares/session_off
53
66
  licenses: []
67
+
54
68
  post_install_message:
55
69
  rdoc_options: []
56
- require_paths:
70
+
71
+ require_paths:
57
72
  - lib
58
- required_ruby_version: !ruby/object:Gem::Requirement
73
+ required_ruby_version: !ruby/object:Gem::Requirement
59
74
  none: false
60
- requirements:
61
- - - ! '>='
62
- - !ruby/object:Gem::Version
63
- version: '0'
64
- required_rubygems_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ hash: 3
79
+ segments:
80
+ - 0
81
+ version: "0"
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
83
  none: false
66
- requirements:
67
- - - ! '>='
68
- - !ruby/object:Gem::Version
69
- version: '0'
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ hash: 3
88
+ segments:
89
+ - 0
90
+ version: "0"
70
91
  requirements: []
71
- rubyforge_project: ! '[none]'
72
- rubygems_version: 1.8.10
92
+
93
+ rubyforge_project: "[none]"
94
+ rubygems_version: 1.8.15
73
95
  signing_key:
74
96
  specification_version: 3
75
97
  summary: declarative session :off from Rails 2.2 'backported'
76
- test_files:
98
+ test_files:
77
99
  - test/session_off_test.rb
78
100
  - test/session_management_test.rb
79
101
  - test/test_helper.rb