merb_activerecord 0.4.3 → 0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Rakefile
CHANGED
@@ -3,7 +3,7 @@ require 'rake/gempackagetask'
|
|
3
3
|
|
4
4
|
PLUGIN = "merb_activerecord"
|
5
5
|
NAME = "merb_activerecord"
|
6
|
-
VERSION = "0.
|
6
|
+
VERSION = "0.5"
|
7
7
|
AUTHOR = "Duane Johnson"
|
8
8
|
EMAIL = "canadaduane@gmail.com"
|
9
9
|
HOMEPAGE = "http://merbivore.com"
|
@@ -20,7 +20,7 @@ spec = Gem::Specification.new do |s|
|
|
20
20
|
s.author = AUTHOR
|
21
21
|
s.email = EMAIL
|
22
22
|
s.homepage = HOMEPAGE
|
23
|
-
s.add_dependency('merb', '>= 0.
|
23
|
+
s.add_dependency('merb', '>= 0.5')
|
24
24
|
s.require_path = 'lib'
|
25
25
|
s.autorequire = PLUGIN
|
26
26
|
s.files = %w(LICENSE README Rakefile TODO) + Dir.glob("{lib,specs,activerecord_generators}/**/*")
|
@@ -34,3 +34,7 @@ task :install do
|
|
34
34
|
sh %{rake package}
|
35
35
|
sh %{sudo gem install pkg/#{NAME}-#{VERSION}}
|
36
36
|
end
|
37
|
+
|
38
|
+
task :release => :package do
|
39
|
+
sh %{rubyforge add_release merb #{PLUGIN} #{VERSION} pkg/#{NAME}-#{VERSION}.gem}
|
40
|
+
end
|
@@ -5,8 +5,8 @@ module Merb
|
|
5
5
|
module Orms
|
6
6
|
module ActiveRecord
|
7
7
|
class << self
|
8
|
-
def config_file()
|
9
|
-
def sample_dest()
|
8
|
+
def config_file() Merb.root / "config" / "database.yml" end
|
9
|
+
def sample_dest() Merb.root / "config" / "database.sample.yml" end
|
10
10
|
def sample_source() File.dirname(__FILE__) / "database.sample.yml" end
|
11
11
|
|
12
12
|
def copy_sample_config
|
@@ -19,7 +19,7 @@ module Merb
|
|
19
19
|
# Convert string keys to symbols
|
20
20
|
full_config = Erubis.load_yaml_file(config_file)
|
21
21
|
config = (Merb::Plugins.config[:merb_active_record] = {})
|
22
|
-
(full_config[
|
22
|
+
(full_config[Merb.environment.to_sym] || full_config[Merb.environment]).each { |k, v| config[k.to_sym] = v }
|
23
23
|
::ActiveRecord::Base.configurations= full_config
|
24
24
|
config
|
25
25
|
end
|
@@ -33,11 +33,11 @@ module Merb
|
|
33
33
|
Thread.new{ loop{ sleep(60*60); ::ActiveRecord::Base.verify_active_connections! } }.priority = -10
|
34
34
|
|
35
35
|
::ActiveRecord::Base.verification_timeout = 14400
|
36
|
-
::ActiveRecord::Base.logger =
|
36
|
+
::ActiveRecord::Base.logger = Merb.logger
|
37
37
|
::ActiveRecord::Base.establish_connection config
|
38
38
|
else
|
39
39
|
copy_sample_config
|
40
|
-
puts "No database.yml file found in #{
|
40
|
+
puts "No database.yml file found in #{Merb.root}/config."
|
41
41
|
puts "A sample file was created called database.sample.yml for you to copy and edit."
|
42
42
|
exit(1)
|
43
43
|
end
|
@@ -46,7 +46,7 @@ module Merb
|
|
46
46
|
# Registering this ORM lets the user choose active_record as a session
|
47
47
|
# in merb.yml's session_store: option.
|
48
48
|
def register_session_type
|
49
|
-
Merb::
|
49
|
+
Merb::BootLoader.register_session_type("activerecord",
|
50
50
|
"merb/session/active_record_session",
|
51
51
|
"Using ActiveRecord database sessions")
|
52
52
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
task :environment do
|
2
|
-
|
2
|
+
Merb.environment = ( ENV['Merb.environment'] || Merb.environment ).to_sym
|
3
3
|
end
|
4
4
|
|
5
5
|
namespace :db do
|
@@ -12,9 +12,9 @@ namespace :db do
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
-
desc 'Create the local database defined in config/database.yml for the current
|
15
|
+
desc 'Create the local database defined in config/database.yml for the current Merb.environment'
|
16
16
|
task :create => :environment do
|
17
|
-
create_local_database(ActiveRecord::Base.configurations[
|
17
|
+
create_local_database(ActiveRecord::Base.configurations[Merb.environment])
|
18
18
|
end
|
19
19
|
|
20
20
|
def create_local_database(config)
|
@@ -53,13 +53,13 @@ namespace :db do
|
|
53
53
|
|
54
54
|
desc 'Drops the database for the current environment'
|
55
55
|
task :drop => :environment do
|
56
|
-
config = ActiveRecord::Base.configurations[
|
56
|
+
config = ActiveRecord::Base.configurations[Merb.environment || :development]
|
57
57
|
p config
|
58
58
|
case config[:adapter]
|
59
59
|
when 'mysql'
|
60
60
|
ActiveRecord::Base.connection.drop_database config[:database]
|
61
61
|
when /^sqlite/
|
62
|
-
FileUtils.rm_f File.join(
|
62
|
+
FileUtils.rm_f File.join(Merb.root, config[:database])
|
63
63
|
when 'postgresql'
|
64
64
|
`dropdb "#{config[:database]}"`
|
65
65
|
end
|
@@ -76,7 +76,7 @@ namespace :db do
|
|
76
76
|
|
77
77
|
# desc "Retrieves the charset for the current environment's database"
|
78
78
|
# task :charset => :environment do
|
79
|
-
# config = ActiveRecord::Base.configurations[
|
79
|
+
# config = ActiveRecord::Base.configurations[Merb.environment || :development]
|
80
80
|
# case config[:adapter]
|
81
81
|
# when 'mysql'
|
82
82
|
# ActiveRecord::Base.establish_connection(config)
|
@@ -88,7 +88,7 @@ namespace :db do
|
|
88
88
|
|
89
89
|
# desc "Retrieves the collation for the current environment's database"
|
90
90
|
# task :collation => :environment do
|
91
|
-
# config = ActiveRecord::Base.configurations[
|
91
|
+
# config = ActiveRecord::Base.configurations[Merb.environment || :development]
|
92
92
|
# case config[:adapter]
|
93
93
|
# when 'mysql'
|
94
94
|
# ActiveRecord::Base.establish_connection(config)
|
@@ -107,61 +107,61 @@ namespace :db do
|
|
107
107
|
desc "Load fixtures into the current environment's database. Load specific fixtures using FIXTURES=x,y"
|
108
108
|
task :load => :environment do
|
109
109
|
require 'active_record/fixtures'
|
110
|
-
ActiveRecord::Base.establish_connection(
|
111
|
-
(ENV['FIXTURES'] ? ENV['FIXTURES'].split(/,/) : Dir.glob(File.join(
|
110
|
+
ActiveRecord::Base.establish_connection(Merb.environment.to_sym)
|
111
|
+
(ENV['FIXTURES'] ? ENV['FIXTURES'].split(/,/) : Dir.glob(File.join(Merb.root, 'test', 'fixtures', '*.{yml,csv}'))).each do |fixture_file|
|
112
112
|
Fixtures.create_fixtures('test/fixtures', File.basename(fixture_file, '.*'))
|
113
113
|
end
|
114
114
|
end
|
115
115
|
end
|
116
116
|
|
117
117
|
namespace :schema do
|
118
|
-
desc
|
119
|
-
task :dump
|
118
|
+
desc 'Create a schema/schema.rb file that can be portably used against any DB supported by AR'
|
119
|
+
task :dump do
|
120
120
|
require 'active_record/schema_dumper'
|
121
121
|
File.open(ENV['SCHEMA'] || "schema/schema.rb", "w") do |file|
|
122
122
|
ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, file)
|
123
123
|
end
|
124
124
|
end
|
125
|
-
|
125
|
+
|
126
126
|
desc "Load a schema.rb file into the database"
|
127
|
-
task :load
|
127
|
+
task :load do
|
128
128
|
file = ENV['SCHEMA'] || "schema/schema.rb"
|
129
129
|
load(file)
|
130
130
|
end
|
131
131
|
end
|
132
132
|
|
133
|
-
|
133
|
+
namespace :structure do
|
134
134
|
desc "Dump the database structure to a SQL file"
|
135
|
-
task :dump
|
136
|
-
|
137
|
-
case
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
135
|
+
task :dump do
|
136
|
+
config = ActiveRecord::Base.configurations[Merb.environment.to_sym]
|
137
|
+
case config[:adapter]
|
138
|
+
when "mysql", "oci", "oracle"
|
139
|
+
ActiveRecord::Base.establish_connection(config[Merb.environment])
|
140
|
+
File.open("schema/#{Merb.environment}_structure.sql", "w+") { |f| f << ActiveRecord::Base.connection.structure_dump }
|
141
|
+
when "postgresql"
|
142
|
+
ENV['PGHOST'] = config[:host] if config[:host]
|
143
|
+
ENV['PGPORT'] = config[:port].to_s if config[:port]
|
144
|
+
ENV['PGPASSWORD'] = config[:password].to_s if config[:password]
|
145
|
+
search_path = config[:schema_search_path]
|
146
|
+
search_path = "--schema=#{search_path}" if search_path
|
147
|
+
`pg_dump -i -U "#{config[:username]}" -s -x -O -f schema/#{Merb.environment}_structure.sql #{search_path} #{config[:database]}`
|
148
|
+
raise "Error dumping database" if $?.exitstatus == 1
|
149
|
+
when "sqlite", "sqlite3"
|
150
|
+
dbfile = config[:database] || config[:dbfile]
|
151
|
+
`#{config[:adapter]} #{dbfile} .schema > schema/#{Merb.environment}_structure.sql`
|
152
|
+
when "sqlserver"
|
153
|
+
`scptxfr /s #{config[:host]} /d #{config[:database]} /I /f schema\\#{Merb.environment}_structure.sql /q /A /r`
|
154
|
+
`scptxfr /s #{config[:host]} /d #{config[:database]} /I /F schema\ /q /A /r`
|
155
|
+
when "firebird"
|
156
|
+
set_firebird_env(config[Merb.environment])
|
157
|
+
db_string = firebird_db_string(config[Merb.environment])
|
158
|
+
sh "isql -a #{db_string} > schema/#{Merb.environment}_structure.sql"
|
159
|
+
else
|
160
|
+
raise "Task not supported by '#{config[:adapter]}'"
|
161
161
|
end
|
162
162
|
|
163
163
|
if ActiveRecord::Base.connection.supports_migrations?
|
164
|
-
File.open("schema/#{
|
164
|
+
File.open("schema/#{Merb.environment}_structure.sql", "a") { |f| f << ActiveRecord::Base.connection.dump_schema_information }
|
165
165
|
end
|
166
166
|
end
|
167
167
|
end
|
@@ -169,84 +169,78 @@ namespace :db do
|
|
169
169
|
namespace :test do
|
170
170
|
desc "Recreate the test database from the current environment's database schema"
|
171
171
|
task :clone => %w(db:schema:dump db:test:purge) do
|
172
|
-
ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations[
|
172
|
+
ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations[:test])
|
173
173
|
ActiveRecord::Schema.verbose = false
|
174
174
|
Rake::Task["db:schema:load"].invoke
|
175
175
|
end
|
176
176
|
|
177
|
-
|
178
177
|
desc "Recreate the test databases from the development structure"
|
179
178
|
task :clone_structure => [ "db:structure:dump", "db:test:purge" ] do
|
180
|
-
|
181
|
-
case
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
179
|
+
config = ActiveRecord::Base.configurations[:test]
|
180
|
+
case config[:adapter]
|
181
|
+
when "mysql"
|
182
|
+
ActiveRecord::Base.establish_connection(:test)
|
183
|
+
ActiveRecord::Base.connection.execute('SET foreign_key_checks = 0')
|
184
|
+
IO.readlines("schema/#{Merb.environment}_structure.sql").join.split("\n\n").each do |table|
|
185
|
+
ActiveRecord::Base.connection.execute(table)
|
186
|
+
end
|
187
|
+
when "postgresql"
|
188
|
+
ENV['PGHOST'] = config[:host] if config[:host]
|
189
|
+
ENV['PGPORT'] = config[:port].to_s if config[:port]
|
190
|
+
ENV['PGPASSWORD'] = config[:password].to_s if config[:password]
|
191
|
+
`psql -U "#{config[:username]}" -f schema/#{Merb.environment}_structure.sql #{config[:database]}`
|
192
|
+
when "sqlite", "sqlite3"
|
193
|
+
dbfile = config[:database] ||config[:dbfile]
|
194
|
+
`#{config[:adapter]} #{dbfile} < schema/#{Merb.environment}_structure.sql`
|
195
|
+
when "sqlserver"
|
196
|
+
`osql -E -S #{config[:host]} -d #{config[:database]} -i schema\\#{Merb.environment}_structure.sql`
|
197
|
+
when "oci", "oracle"
|
198
|
+
ActiveRecord::Base.establish_connection(:test)
|
199
|
+
IO.readlines("schema/#{Merb.environment}_structure.sql").join.split(";\n\n").each do |ddl|
|
200
|
+
ActiveRecord::Base.connection.execute(ddl)
|
201
|
+
end
|
202
|
+
when "firebird"
|
203
|
+
set_firebird_env(config)
|
204
|
+
db_string = firebird_db_string(config)
|
205
|
+
sh "isql -i schema/#{Merb.environment}_structure.sql #{db_string}"
|
206
|
+
else
|
207
|
+
raise "Task not supported by '#{config[:adapter]}'"
|
209
208
|
end
|
210
209
|
end
|
211
|
-
|
210
|
+
|
212
211
|
desc "Empty the test database"
|
213
|
-
task :purge
|
214
|
-
|
215
|
-
case
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
when "firebird"
|
241
|
-
ActiveRecord::Base.establish_connection(:test)
|
242
|
-
ActiveRecord::Base.connection.recreate_database!
|
243
|
-
else
|
244
|
-
raise "Task not supported by '#{abcs["test"]["adapter"]}'"
|
212
|
+
task :purge do
|
213
|
+
config = ActiveRecord::Base.configurations[:test]
|
214
|
+
case config[:adapter]
|
215
|
+
when "mysql"
|
216
|
+
ActiveRecord::Base.establish_connection(:test)
|
217
|
+
ActiveRecord::Base.connection.recreate_database(config[:database])
|
218
|
+
when "postgresql"
|
219
|
+
ENV['PGHOST'] = config[:host] if config[:host]
|
220
|
+
ENV['PGPORT'] = configs[:port].to_s if config[:port]
|
221
|
+
ENV['PGPASSWORD'] = configs[:password].to_s if config[:password]
|
222
|
+
enc_option = "-E #{config[:encoding]}" if config[:encoding]
|
223
|
+
ActiveRecord::Base.clear_active_connections!
|
224
|
+
`dropdb -U "#{config[:username]}" #{config[:database]}`
|
225
|
+
`createdb #{enc_option} -U "#{config[:username]}" #{config[:database]}`
|
226
|
+
when "sqlite","sqlite3"
|
227
|
+
dbfile = config[:database] || config[:dbfile]
|
228
|
+
File.delete(dbfile) if File.exist?(dbfile)
|
229
|
+
when "sqlserver"
|
230
|
+
config ActiveRecord::Base.establish_connection(:test)
|
231
|
+
ActiveRecord::Base.connection.structure_drop.split(";\n\n").each do |ddl|
|
232
|
+
ActiveRecord::Base.connection.execute(ddl)
|
233
|
+
end
|
234
|
+
when "firebird"
|
235
|
+
ActiveRecord::Base.establish_connection(:test)
|
236
|
+
ActiveRecord::Base.connection.recreate_database!
|
237
|
+
else
|
238
|
+
raise "Task not supported by '#{config[:adapter]}'"
|
245
239
|
end
|
246
240
|
end
|
247
241
|
|
248
|
-
desc
|
249
|
-
task :prepare => :
|
242
|
+
desc "Prepare the test database and load the schema"
|
243
|
+
task :prepare => ["db:test:clone_structure", "db:test:clone"] do
|
250
244
|
if defined?(ActiveRecord::Base) && !ActiveRecord::Base.configurations.blank?
|
251
245
|
Rake::Task[{ :sql => "db:test:clone_structure", :ruby => "db:test:clone" }[ActiveRecord::Base.schema_format]].invoke
|
252
246
|
end
|
@@ -1,9 +1,9 @@
|
|
1
|
-
require
|
1
|
+
require "active_record"
|
2
2
|
|
3
3
|
module Merb
|
4
4
|
module SessionMixin
|
5
5
|
def setup_session
|
6
|
-
|
6
|
+
Merb.logger.info("Setting up session")
|
7
7
|
before = cookies[_session_id_key]
|
8
8
|
request.session, cookies[_session_id_key] = Merb::ActiveRecordSession.persist(cookies[_session_id_key])
|
9
9
|
@_fingerprint = Marshal.dump(request.session.data).hash
|
@@ -11,7 +11,7 @@ module Merb
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def finalize_session
|
14
|
-
|
14
|
+
Merb.logger.info("Finalize session")
|
15
15
|
request.session.save if @_fingerprint != Marshal.dump(request.session.data).hash
|
16
16
|
set_cookie(_session_id_key, request.session.session_id, _session_expiry) if (@_new_cookie || request.session.needs_new_cookie)
|
17
17
|
end
|
@@ -84,14 +84,22 @@ module Merb
|
|
84
84
|
end
|
85
85
|
|
86
86
|
# Lazy-delete of session data
|
87
|
-
def delete
|
88
|
-
self.data
|
87
|
+
def delete(key = nil)
|
88
|
+
key ? self.data.delete(key) : self.data.clear
|
89
89
|
end
|
90
90
|
|
91
91
|
def [](key)
|
92
92
|
data[key]
|
93
93
|
end
|
94
94
|
|
95
|
+
def empty?
|
96
|
+
data.empty?
|
97
|
+
end
|
98
|
+
|
99
|
+
def each(&b)
|
100
|
+
data.each(&b)
|
101
|
+
end
|
102
|
+
|
95
103
|
def []=(key, val)
|
96
104
|
data[key] = val
|
97
105
|
end
|
data/lib/merb_activerecord.rb
CHANGED
metadata
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.9.
|
2
|
+
rubygems_version: 0.9.0
|
3
3
|
specification_version: 1
|
4
4
|
name: merb_activerecord
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.
|
7
|
-
date:
|
6
|
+
version: "0.5"
|
7
|
+
date: 2008-01-09 00:00:00 -08:00
|
8
8
|
summary: Merb plugin that provides ActiveRecord support for Merb
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -92,5 +92,5 @@ dependencies:
|
|
92
92
|
requirements:
|
93
93
|
- - ">="
|
94
94
|
- !ruby/object:Gem::Version
|
95
|
-
version: 0.
|
95
|
+
version: "0.5"
|
96
96
|
version:
|