intercession 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.rdoc ADDED
@@ -0,0 +1,3 @@
1
+ === 1.0.0 (2009-02-24)
2
+
3
+ * Birthday!
data/Manifest.txt ADDED
@@ -0,0 +1,9 @@
1
+ CHANGELOG.rdoc
2
+ Manifest.txt
3
+ README.rdoc
4
+ Rakefile
5
+ install.rb
6
+ lib/intercession/lifecycle.rb
7
+ lib/intercession/version.rb
8
+ rails/init.rb
9
+ session.template
data/README.rdoc ADDED
@@ -0,0 +1,66 @@
1
+ = Intercession
2
+
3
+ Treat your sessions like models, not hashes. Intercession mixes a module into
4
+ the session on each request, allowing you to nicely encapsulate (and test!)
5
+ lots of user and session-specific behavior.
6
+
7
+ == Examples
8
+
9
+ Check out [this gist](http://gist.github.com/44506).
10
+
11
+ Unit tests for your session model! Mix it in to a Hash and go to town:
12
+
13
+ def setup
14
+ @session = Hash.new
15
+ @session.extend Transient::Session
16
+ end
17
+
18
+ def test_session_user_lazily_loads_from_user_id
19
+ assert_nil @session.user
20
+ @session[:user_id] = users(:default).id
21
+ assert_equal users(:default), @session.user
22
+ end
23
+
24
+ == Installation
25
+
26
+ Intercession works as a plugin or a gem. I've only used it as a plugin
27
+ against Rails 2.2, though, so YMMV. If you install it as a plugin,
28
+ it'll create you a stub session module in
29
+ <tt>app/models/transient/session.rb</tt>. If you're using it as a gem,
30
+ do it yourself. :)
31
+
32
+ As a plugin:
33
+
34
+ $ script/plugin install git://github.com/jbarnette/intercession.git
35
+
36
+ As a gem:
37
+
38
+ $ sudo gem install intercession
39
+
40
+ If you're using Intercession as a gem, add it to the gem dependencies
41
+ in one of your environment config files:
42
+
43
+ config.gem "intercession", :lib => "intercession/lifecycle"
44
+
45
+ == License
46
+
47
+ Copyright 2009 John Barnette <jbarnette@rubyforge.org>
48
+
49
+ Permission is hereby granted, free of charge, to any person obtaining
50
+ a copy of this software and associated documentation files (the
51
+ 'Software'), to deal in the Software without restriction, including
52
+ without limitation the rights to use, copy, modify, merge, publish,
53
+ distribute, sublicense, and/or sell copies of the Software, and to
54
+ permit persons to whom the Software is furnished to do so, subject to
55
+ the following conditions:
56
+
57
+ The above copyright notice and this permission notice shall be
58
+ included in all copies or substantial portions of the Software.
59
+
60
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
61
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
62
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
63
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
64
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
65
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
66
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,18 @@
1
+ require "rubygems"
2
+ require "hoe"
3
+
4
+ require "./lib/intercession/version.rb"
5
+
6
+ Hoe::SUPPORTED_TEST_FRAMEWORKS[:helper] = "helper"
7
+
8
+ Hoe.new "intercession", Intercession::VERSION do |p|
9
+ p.developer "John Barnette", "jbarnette@rubyforge.org"
10
+
11
+ p.url = "http://github.com/jbarnette/intercession"
12
+ p.history_file = "CHANGELOG.rdoc"
13
+ p.readme_file = "README.rdoc"
14
+ p.extra_rdoc_files = [p.readme_file]
15
+ p.need_tar = false
16
+ p.test_globs = %w(test/**/*_test.rb)
17
+ p.testlib = :helper
18
+ end
data/install.rb ADDED
@@ -0,0 +1,11 @@
1
+ source = File.join File.dirname(__FILE__), "session.template"
2
+ relative = File.join "app", "models", "transient", "session.rb"
3
+ destination = File.join Rails.root, relative
4
+
5
+ if File.exist? destination
6
+ puts "#{relative} already exists, so I won't overwrite it."
7
+ else
8
+ FileUtils.mkdir_p File.dirname(destination)
9
+ FileUtils.cp source, destination
10
+ puts "Installed an empty session module in #{destination}. Go edit it!"
11
+ end
@@ -0,0 +1,23 @@
1
+ module Intercession
2
+ module Lifecycle
3
+ def self.included klass
4
+ klass.prepend_before_filter :intercede_before
5
+ klass.append_after_filter :intercede_after
6
+ end
7
+
8
+ def intercede_before
9
+ session.extend Transient::Session
10
+
11
+ session.controller = self if session.respond_to?(:controller=)
12
+ session.request = request if session.respond_to?(:request=)
13
+ session.response = response if session.respond_to?(:response=)
14
+
15
+ session.after_initialize if session.respond_to? :after_initialize
16
+ end
17
+
18
+ def intercede_after
19
+ # FIXME: this obviously won't work with after filters in subclasses.
20
+ session.before_save if session.respond_to? :before_save
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,3 @@
1
+ module Intercession
2
+ VERSION = "1.0.0"
3
+ end
data/rails/init.rb ADDED
@@ -0,0 +1,2 @@
1
+ require "application"
2
+ ApplicationController.send :include, Intercession::Lifecycle
data/session.template ADDED
@@ -0,0 +1,23 @@
1
+ module Transient
2
+
3
+ # This module gets mixed in to the Rails session, and lets you
4
+ # treat the session more like a real object. Note that while most things
5
+ # this module is mixed in to are Hashlike, they vary in capabilitites.
6
+ # Safest to assume that the index[] op is the only thing that's available.
7
+
8
+ module Session
9
+ attr_accessor :controller, :request, :response
10
+
11
+ # Called by a before_filter in the application controller. A good place
12
+ # to eagerly populate member models from IDs, if you're not feeling lazy.
13
+
14
+ def after_initialize
15
+ end
16
+
17
+ # Called by an after_filter in the application controller. A good
18
+ # opportunity to turn heavy lists of stuff into IDs, etc.
19
+
20
+ def before_save
21
+ end
22
+ end
23
+ end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: intercession
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - John Barnette
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-02-24 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: hoe
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.9.0
24
+ version:
25
+ description: ""
26
+ email:
27
+ - jbarnette@rubyforge.org
28
+ executables: []
29
+
30
+ extensions: []
31
+
32
+ extra_rdoc_files:
33
+ - Manifest.txt
34
+ - README.rdoc
35
+ files:
36
+ - CHANGELOG.rdoc
37
+ - Manifest.txt
38
+ - README.rdoc
39
+ - Rakefile
40
+ - install.rb
41
+ - lib/intercession/lifecycle.rb
42
+ - lib/intercession/version.rb
43
+ - rails/init.rb
44
+ - session.template
45
+ has_rdoc: true
46
+ homepage: http://github.com/jbarnette/intercession
47
+ post_install_message:
48
+ rdoc_options:
49
+ - --main
50
+ - README.rdoc
51
+ require_paths:
52
+ - lib
53
+ required_ruby_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: "0"
58
+ version:
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: "0"
64
+ version:
65
+ requirements: []
66
+
67
+ rubyforge_project: intercession
68
+ rubygems_version: 1.3.1
69
+ signing_key:
70
+ specification_version: 2
71
+ summary: ""
72
+ test_files: []
73
+