Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Using autoload to require the different session stores #8

Merged
merged 1 commit into from over 2 years ago

2 participants

Arvid Andersson Brian Hempel
Arvid Andersson

I added autoload for requiring the session stores so you don't have to rescue on LoadError and not require files that is not used by the app using the gem.
I guess it comes down to personal coding style/preferences about using rescue LoadError vs autoload for handling stuff like this =) What you think?

Brian Hempel

Thanks! Autoload is definitely cleaner, you're right. I'll take a look to make sure isn't some behavior that rescue gives us that autoload doesn't (e.g. robustness when the programmer loads stuff in a strange order, or sets the collection name before declaring the sessions store).

Arvid Andersson

Cool, let me know if you need any help.

Brian Hempel brianhempel merged commit 66baa11 into from September 22, 2011
Brian Hempel brianhempel closed this September 22, 2011
Brian Hempel

Merged. Thanks for the cleanup!

Arvid Andersson

Nice :+1:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Sep 20, 2011
Using autoload to require the different session stores 66baa11
This page is out of date. Refresh to see the latest.
6  lib/mongo_session_store-rails3.rb
@@ -27,6 +27,6 @@ def self.collection_name
27 27
   self.collection_name = "sessions"
28 28
 end
29 29
 
30  
-require 'mongo_session_store/mongo_mapper_store'
31  
-require 'mongo_session_store/mongoid_store'
32  
-require 'mongo_session_store/mongo_store'
  30
+autoload :MongoMapperStore,'mongo_session_store/mongo_mapper_store'
  31
+autoload :MongoidStore, 'mongo_session_store/mongoid_store'
  32
+autoload :MongoStore, 'mongo_session_store/mongo_store'
38  lib/mongo_session_store/mongo_mapper_store.rb
... ...
@@ -1,26 +1,22 @@
1  
-begin
2  
-  require 'mongo_mapper'
3  
-  require 'mongo_session_store/mongo_store_base'
  1
+require 'mongo_mapper'
  2
+require 'mongo_session_store/mongo_store_base'
4 3
 
5  
-  module ActionDispatch
6  
-    module Session
7  
-      class MongoMapperStore < MongoStoreBase
8  
-        
9  
-        class Session
10  
-          include MongoMapper::Document
11  
-          set_collection_name MongoSessionStore.collection_name
12  
-          
13  
-          key :_id,  String
14  
-          key :data, Binary, :default => Marshal.dump({})
15  
-          
16  
-          timestamps!
17  
-        end
18  
-        
  4
+module ActionDispatch
  5
+  module Session
  6
+    class MongoMapperStore < MongoStoreBase
  7
+
  8
+      class Session
  9
+        include MongoMapper::Document
  10
+        set_collection_name MongoSessionStore.collection_name
  11
+
  12
+        key :_id,  String
  13
+        key :data, Binary, :default => Marshal.dump({})
  14
+
  15
+        timestamps!
19 16
       end
  17
+
20 18
     end
21 19
   end
  20
+end
22 21
 
23  
-  MongoMapperStore = ActionDispatch::Session::MongoMapperStore
24  
-
25  
-rescue LoadError
26  
-end
  22
+MongoMapperStore = ActionDispatch::Session::MongoMapperStore
44  lib/mongo_session_store/mongoid_store.rb
... ...
@@ -1,31 +1,27 @@
1  
-begin
2  
-  require 'mongoid'
3  
-  require 'mongo_session_store/mongo_store_base'
  1
+require 'mongoid'
  2
+require 'mongo_session_store/mongo_store_base'
4 3
 
5  
-  module ActionDispatch
6  
-    module Session
7  
-      class MongoidStore < MongoStoreBase
8  
-        
9  
-        class Session
10  
-          include Mongoid::Document
11  
-          include Mongoid::Timestamps
12  
-          self.collection_name = MongoSessionStore.collection_name
13  
-        
14  
-          identity :type => String
  4
+module ActionDispatch
  5
+  module Session
  6
+    class MongoidStore < MongoStoreBase
15 7
 
16  
-          field :data, :type => BSON::Binary, :default => BSON::Binary.new(Marshal.dump({}))
17  
-        end
  8
+      class Session
  9
+        include Mongoid::Document
  10
+        include Mongoid::Timestamps
  11
+        self.collection_name = MongoSessionStore.collection_name
18 12
 
19  
-        private
20  
-          def pack(data)
21  
-            BSON::Binary.new(Marshal.dump(data))
22  
-          end
23  
-      
  13
+        identity :type => String
  14
+
  15
+        field :data, :type => BSON::Binary, :default => BSON::Binary.new(Marshal.dump({}))
  16
+      end
  17
+
  18
+      private
  19
+      def pack(data)
  20
+        BSON::Binary.new(Marshal.dump(data))
24 21
       end
  22
+
25 23
     end
26 24
   end
27  
-  
28  
-  MongoidStore = ActionDispatch::Session::MongoidStore
  25
+end
29 26
 
30  
-rescue LoadError
31  
-end
  27
+MongoidStore = ActionDispatch::Session::MongoidStore
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.