merb_sequel 0.4.3 → 0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +4 -4
- data/lib/merb/orms/sequel/connection.rb +23 -14
- data/lib/merb/session/sequel_session.rb +39 -36
- data/lib/merb_sequel.rb +1 -1
- data/lib/merbtasks.rb +1 -1
- metadata +71 -78
data/Rakefile
CHANGED
@@ -3,9 +3,9 @@ require "rake/gempackagetask"
|
|
3
3
|
|
4
4
|
PLUGIN = "merb_sequel"
|
5
5
|
NAME = "merb_sequel"
|
6
|
-
VERSION = "0.
|
7
|
-
AUTHOR = "Wayne E. Seguin"
|
8
|
-
EMAIL = "wayneeseguin@gmail.com"
|
6
|
+
VERSION = "0.5"
|
7
|
+
AUTHOR = "Wayne E. Seguin, Lance Carlson"
|
8
|
+
EMAIL = "wayneeseguin@gmail.com, lancecarlson@gmail.com"
|
9
9
|
HOMEPAGE = "http://merb-plugins.rubyforge.org/merb_sequel/"
|
10
10
|
SUMMARY = "Merb plugin that provides support for Sequel and Sequel::Model"
|
11
11
|
|
@@ -23,7 +23,7 @@ specification = Gem::Specification.new do |spec|
|
|
23
23
|
spec.require_path = "lib"
|
24
24
|
spec.extra_rdoc_files = ["README", "LICENSE", 'TODO']
|
25
25
|
# Dependencies
|
26
|
-
spec.add_dependency("merb", ">= 0.
|
26
|
+
spec.add_dependency("merb", ">= 0.5")
|
27
27
|
spec.add_dependency("sequel", ">= 1.0.0")
|
28
28
|
spec.add_dependency("sequel_model", ">= 0.2")
|
29
29
|
spec.files = %w(LICENSE README Rakefile TODO) + Dir.glob("{lib,specs,sequel_generators}/**/*")
|
@@ -3,9 +3,11 @@ require "fileutils"
|
|
3
3
|
module Merb
|
4
4
|
module Orms
|
5
5
|
module Sequel
|
6
|
+
|
6
7
|
class << self
|
7
|
-
|
8
|
-
def
|
8
|
+
|
9
|
+
def config_file() Merb.root / "config" / "database.yml" end
|
10
|
+
def sample_dest() Merb.root / "config" / "database.sample.yml" end
|
9
11
|
def sample_source() File.dirname(__FILE__) / "database.sample.yml" end
|
10
12
|
|
11
13
|
def copy_sample_config
|
@@ -13,37 +15,42 @@ module Merb
|
|
13
15
|
end
|
14
16
|
|
15
17
|
def config
|
18
|
+
|
16
19
|
@config ||=
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
end
|
24
|
-
config
|
20
|
+
begin
|
21
|
+
# Convert string keys to symbols
|
22
|
+
full_config = Erubis.load_yaml_file(config_file)
|
23
|
+
config = (Merb::Plugins.config[:merb_sequel] = {})
|
24
|
+
(full_config[Merb.environment.to_sym] || full_config[Merb.environment]).each do |key, value|
|
25
|
+
config[key.to_sym] = value
|
25
26
|
end
|
27
|
+
config
|
28
|
+
end
|
29
|
+
|
26
30
|
end
|
27
31
|
|
28
32
|
# Database connects as soon as the gem is loaded
|
29
33
|
def connect
|
34
|
+
|
30
35
|
require "sequel"
|
31
36
|
require "sequel_model"
|
32
37
|
|
33
38
|
if File.exists?(config_file)
|
34
39
|
puts "#{Time.now.httpdate}: Connecting to the '#{config[:database]}' database on '#{config[:host]}' using '#{config[:adapter]}' ..."
|
35
40
|
connection = ::Sequel.connect(config_options(config))
|
36
|
-
|
41
|
+
Merb.logger.error("Connection Error: #{e}") unless connection
|
37
42
|
connection
|
38
43
|
else
|
39
44
|
copy_sample_config
|
40
|
-
puts "#{Time.now.httpdate}: No database.yml file found in #{
|
45
|
+
puts "#{Time.now.httpdate}: No database.yml file found in #{Merb.root}/config."
|
41
46
|
puts "A sample file was created called config/database.sample.yml for you to copy and edit."
|
42
47
|
exit(1)
|
43
48
|
end
|
49
|
+
|
44
50
|
end
|
45
51
|
|
46
52
|
def config_options(config = {})
|
53
|
+
|
47
54
|
options = {}
|
48
55
|
options[:adapter] = (config[:adapter] || "sqlite")
|
49
56
|
options[:host] = (config[:host] || "localhost")
|
@@ -53,20 +60,22 @@ module Merb
|
|
53
60
|
options[:encoding] = (config[:encoding] || config[:charset])
|
54
61
|
end
|
55
62
|
options[:database] = config[:database] if config[:database]
|
56
|
-
options[:logger] =
|
63
|
+
options[:logger] = Merb.logger
|
57
64
|
options
|
58
65
|
end
|
59
66
|
|
60
67
|
# Registering this ORM lets the user choose sequel as a session store
|
61
68
|
# in merb.yml's session_store: option.
|
62
69
|
def register_session_type
|
63
|
-
Merb::
|
70
|
+
Merb::BootLoader.register_session_type("sequel",
|
64
71
|
"merb/session/sequel_session",
|
65
72
|
"Using Sequel database sessions")
|
66
73
|
end
|
67
74
|
|
68
75
|
end
|
76
|
+
|
69
77
|
end
|
78
|
+
|
70
79
|
end
|
71
80
|
|
72
81
|
end
|
@@ -1,43 +1,45 @@
|
|
1
|
-
require
|
1
|
+
require "base64"
|
2
2
|
|
3
3
|
module Merb
|
4
|
+
|
4
5
|
module SessionMixin
|
5
|
-
|
6
|
+
|
6
7
|
def setup_session
|
7
|
-
|
8
|
+
Merb.logger.info("Setting up session")
|
8
9
|
before = cookies[_session_id_key]
|
9
10
|
request.session, cookies[_session_id_key] = Merb::SequelSession.persist(cookies[_session_id_key])
|
10
11
|
@_fingerprint = Marshal.dump(request.session.data).hash
|
11
12
|
@_new_cookie = cookies[_session_id_key] != before
|
12
13
|
end
|
13
|
-
|
14
|
+
|
14
15
|
def finalize_session
|
15
|
-
|
16
|
+
Merb.logger.info("Finalize session")
|
16
17
|
request.session.save if @_fingerprint != Marshal.dump(request.session.data).hash
|
17
18
|
set_cookie(_session_id_key, request.session.values[:session_id], _session_expiry) if (@_new_cookie || request.session.needs_new_cookie)
|
18
19
|
end
|
19
|
-
|
20
|
+
|
20
21
|
end
|
21
22
|
|
22
|
-
table_name = (Merb::Plugins.config[:
|
23
|
+
table_name = (Merb::Plugins.config[:merb_sequel][:session_table_name] || "sessions")
|
23
24
|
|
24
25
|
class SequelSession < Sequel::Model(table_name.to_sym)
|
26
|
+
|
25
27
|
set_schema do
|
26
28
|
primary_key :id
|
27
29
|
varchar :session_id
|
28
30
|
varchar :data
|
29
31
|
timestamp :created_at
|
30
32
|
end
|
31
|
-
|
33
|
+
|
32
34
|
attr_accessor :needs_new_cookie
|
33
|
-
|
35
|
+
|
34
36
|
class << self
|
35
37
|
# Generates a new session ID and creates a row for the new session in the database.
|
36
38
|
def generate
|
37
39
|
create(:session_id => Merb::SessionMixin::rand_uuid,
|
38
|
-
|
40
|
+
:data => marshal({}), :created_at => Time.now)
|
39
41
|
end
|
40
|
-
|
42
|
+
|
41
43
|
# Gets the existing session based on the <tt>session_id</tt> available in cookies.
|
42
44
|
# If none is found, generates a new session.
|
43
45
|
def persist(session_id)
|
@@ -49,90 +51,91 @@ module Merb
|
|
49
51
|
end
|
50
52
|
[session, session.values[:session_id]]
|
51
53
|
end
|
52
|
-
|
54
|
+
|
53
55
|
# Don't try to reload ARStore::Session in dev mode.
|
54
56
|
def reloadable? #:nodoc:
|
55
57
|
false
|
56
58
|
end
|
57
|
-
|
59
|
+
|
58
60
|
def data_column_size_limit
|
59
61
|
255
|
60
62
|
end
|
61
|
-
|
63
|
+
|
62
64
|
def marshal(data)
|
63
65
|
Base64.encode64(Marshal.dump(data)) if data
|
64
66
|
end
|
65
|
-
|
67
|
+
|
66
68
|
def unmarshal(data)
|
67
69
|
Marshal.load(Base64.decode64(data)) if data
|
68
70
|
end
|
69
|
-
|
71
|
+
|
70
72
|
alias :create_table! :create_table
|
71
73
|
alias :drop_table! :drop_table
|
72
74
|
end
|
73
|
-
|
75
|
+
|
74
76
|
# Regenerate the Session ID
|
75
77
|
def regenerate
|
76
78
|
update_attributes(:session_id => Merb::SessionMixin::rand_uuid)
|
77
79
|
self.needs_new_cookie = true
|
78
80
|
end
|
79
|
-
|
81
|
+
|
80
82
|
# Recreates the cookie with the default expiration time
|
81
83
|
# Useful during log in for pushing back the expiration date
|
82
84
|
def refresh_expiration
|
83
85
|
self.needs_new_cookie = true
|
84
86
|
end
|
85
|
-
|
87
|
+
|
86
88
|
# Lazy-delete of session data
|
87
89
|
def delete(key = nil)
|
88
90
|
key ? self.data.delete(key) : self.data.clear
|
89
91
|
end
|
90
|
-
|
92
|
+
|
91
93
|
def [](key)
|
92
94
|
data[key]
|
93
95
|
end
|
94
|
-
|
96
|
+
|
95
97
|
def []=(key, val)
|
96
98
|
data[key] = val
|
97
99
|
end
|
98
|
-
|
100
|
+
|
99
101
|
def empty?
|
100
102
|
data.empty?
|
101
103
|
end
|
102
|
-
|
104
|
+
|
103
105
|
def each(&b)
|
104
106
|
data.each(&b)
|
105
107
|
end
|
106
|
-
|
108
|
+
|
107
109
|
# Lazy-unmarshal session state.
|
108
110
|
def data
|
109
111
|
@data ||= self.class.unmarshal(@values[:data]) || {}
|
110
112
|
end
|
111
|
-
|
113
|
+
|
112
114
|
# Has the session been loaded yet?
|
113
115
|
def loaded?
|
114
116
|
!! @data
|
115
117
|
end
|
116
|
-
|
117
|
-
|
118
|
-
|
118
|
+
|
119
|
+
private
|
120
|
+
|
119
121
|
attr_writer :data
|
120
|
-
|
122
|
+
|
121
123
|
before_save do # marshal_data!
|
122
124
|
# return false if !loaded?
|
123
125
|
@values[:data] = self.class.marshal(self.data)
|
124
126
|
end
|
125
|
-
|
127
|
+
|
126
128
|
# Ensures that the data about to be stored in the database is not
|
127
129
|
# larger than the data storage column. Raises
|
128
130
|
# ActionController::SessionOverflowError.
|
129
131
|
# before_save do # raise_on_session_data_overflow!
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
132
|
+
# return false if !loaded?
|
133
|
+
# limit = self.class.data_column_size_limit
|
134
|
+
# if loaded? and limit and read_attribute(@@data_column_name).size > limit
|
135
|
+
# raise MerbController::SessionOverflowError
|
136
|
+
# end
|
135
137
|
# end
|
138
|
+
|
136
139
|
end
|
137
140
|
|
138
141
|
unless Sequel::Model.db.table_exists?(table_name.to_sym)
|
@@ -144,5 +147,5 @@ module Merb
|
|
144
147
|
|
145
148
|
puts "Created sessions table."
|
146
149
|
end
|
147
|
-
|
150
|
+
|
148
151
|
end
|
data/lib/merb_sequel.rb
CHANGED
data/lib/merbtasks.rb
CHANGED
@@ -16,7 +16,7 @@ namespace :sequel do
|
|
16
16
|
desc "Creates session migration"
|
17
17
|
task :create => :merb_env do
|
18
18
|
# TODO: this should not use '001' always...
|
19
|
-
dest = File.join(
|
19
|
+
dest = File.join(Merb.root, "schema", "migrations","001_add_sessions_table.rb")
|
20
20
|
source = File.join(File.dirname(__FILE__), "merb", "session","001_add_sessions_table.rb")
|
21
21
|
|
22
22
|
FileUtils.cp source, dest unless File.exists?(dest)
|
metadata
CHANGED
@@ -1,116 +1,109 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.9.0
|
3
|
+
specification_version: 1
|
2
4
|
name: merb_sequel
|
3
5
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
|
6
|
-
|
7
|
-
|
6
|
+
version: "0.5"
|
7
|
+
date: 2008-01-09 00:00:00 -08:00
|
8
|
+
summary: Merb plugin that provides support for Sequel and Sequel::Model
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
email: wayneeseguin@gmail.com, lancecarlson@gmail.com
|
12
|
+
homepage: http://merb-plugins.rubyforge.org/merb_sequel/
|
13
|
+
rubyforge_project:
|
14
|
+
description: Merb plugin that provides support for Sequel and Sequel::Model
|
8
15
|
autorequire: merb_sequel
|
9
|
-
bindir: bin
|
10
|
-
cert_chain: []
|
11
|
-
|
12
|
-
date: 2008-01-07 00:00:00 -05:00
|
13
16
|
default_executable:
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
requirements:
|
29
|
-
- - ">="
|
30
|
-
- !ruby/object:Gem::Version
|
31
|
-
version: 1.0.0
|
32
|
-
version:
|
33
|
-
- !ruby/object:Gem::Dependency
|
34
|
-
name: sequel_model
|
35
|
-
version_requirement:
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - ">="
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: "0.2"
|
41
|
-
version:
|
42
|
-
description: Merb plugin that provides support for Sequel and Sequel::Model
|
43
|
-
email: wayneeseguin@gmail.com
|
44
|
-
executables: []
|
45
|
-
|
46
|
-
extensions: []
|
47
|
-
|
48
|
-
extra_rdoc_files:
|
49
|
-
- README
|
50
|
-
- LICENSE
|
51
|
-
- TODO
|
17
|
+
bindir: bin
|
18
|
+
has_rdoc: true
|
19
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.0.0
|
24
|
+
version:
|
25
|
+
platform: ruby
|
26
|
+
signing_key:
|
27
|
+
cert_chain:
|
28
|
+
post_install_message:
|
29
|
+
authors:
|
30
|
+
- Wayne E. Seguin, Lance Carlson
|
52
31
|
files:
|
53
32
|
- LICENSE
|
54
33
|
- README
|
55
34
|
- Rakefile
|
56
35
|
- TODO
|
57
36
|
- lib/merb
|
37
|
+
- lib/merb_sequel.rb
|
38
|
+
- lib/merbtasks.rb
|
58
39
|
- lib/merb/orms
|
40
|
+
- lib/merb/session
|
59
41
|
- lib/merb/orms/sequel
|
60
42
|
- lib/merb/orms/sequel/connection.rb
|
61
43
|
- lib/merb/orms/sequel/database.sample.yml
|
62
|
-
- lib/merb/session
|
63
44
|
- lib/merb/session/001_add_sessions_table.rb
|
64
45
|
- lib/merb/session/sequel_session.rb
|
65
|
-
- lib/merb_sequel.rb
|
66
|
-
- lib/merbtasks.rb
|
67
46
|
- specs/merb_sequel_spec.rb
|
68
47
|
- specs/spec_helper.rb
|
69
48
|
- sequel_generators/migration
|
49
|
+
- sequel_generators/model
|
50
|
+
- sequel_generators/resource_controller
|
70
51
|
- sequel_generators/migration/migration_generator.rb
|
71
52
|
- sequel_generators/migration/templates
|
72
|
-
- sequel_generators/migration/templates/new_migration.erb
|
73
53
|
- sequel_generators/migration/USAGE
|
74
|
-
- sequel_generators/
|
54
|
+
- sequel_generators/migration/templates/new_migration.erb
|
75
55
|
- sequel_generators/model/model_generator.rb
|
76
56
|
- sequel_generators/model/templates
|
77
|
-
- sequel_generators/model/templates/sequel_model_template.erb
|
78
57
|
- sequel_generators/model/USAGE
|
79
|
-
- sequel_generators/
|
58
|
+
- sequel_generators/model/templates/sequel_model_template.erb
|
80
59
|
- sequel_generators/resource_controller/resource_controller_generator.rb
|
81
60
|
- sequel_generators/resource_controller/templates
|
61
|
+
- sequel_generators/resource_controller/USAGE
|
82
62
|
- sequel_generators/resource_controller/templates/controller.rb
|
83
63
|
- sequel_generators/resource_controller/templates/edit.html.erb
|
84
64
|
- sequel_generators/resource_controller/templates/helper.rb
|
85
65
|
- sequel_generators/resource_controller/templates/index.html.erb
|
86
66
|
- sequel_generators/resource_controller/templates/new.html.erb
|
87
67
|
- sequel_generators/resource_controller/templates/show.html.erb
|
88
|
-
|
89
|
-
|
90
|
-
homepage: http://merb-plugins.rubyforge.org/merb_sequel/
|
91
|
-
post_install_message:
|
68
|
+
test_files: []
|
69
|
+
|
92
70
|
rdoc_options: []
|
93
71
|
|
94
|
-
|
95
|
-
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
- !ruby/object:Gem::Version
|
100
|
-
version: "0"
|
101
|
-
version:
|
102
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
|
-
requirements:
|
104
|
-
- - ">="
|
105
|
-
- !ruby/object:Gem::Version
|
106
|
-
version: "0"
|
107
|
-
version:
|
108
|
-
requirements: []
|
72
|
+
extra_rdoc_files:
|
73
|
+
- README
|
74
|
+
- LICENSE
|
75
|
+
- TODO
|
76
|
+
executables: []
|
109
77
|
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
specification_version: 2
|
114
|
-
summary: Merb plugin that provides support for Sequel and Sequel::Model
|
115
|
-
test_files: []
|
78
|
+
extensions: []
|
79
|
+
|
80
|
+
requirements: []
|
116
81
|
|
82
|
+
dependencies:
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: merb
|
85
|
+
version_requirement:
|
86
|
+
version_requirements: !ruby/object:Gem::Version::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: "0.5"
|
91
|
+
version:
|
92
|
+
- !ruby/object:Gem::Dependency
|
93
|
+
name: sequel
|
94
|
+
version_requirement:
|
95
|
+
version_requirements: !ruby/object:Gem::Version::Requirement
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: 1.0.0
|
100
|
+
version:
|
101
|
+
- !ruby/object:Gem::Dependency
|
102
|
+
name: sequel_model
|
103
|
+
version_requirement:
|
104
|
+
version_requirements: !ruby/object:Gem::Version::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: "0.2"
|
109
|
+
version:
|