Class: Orange::Middleware::Database
- Inherits:
-
Base
show all
- Defined in:
- lib/orange-core/middleware/database.rb
Instance Method Summary
collapse
Methods inherited from Base
#call, #initialize, #inspect, #orange, #pass, #recapture
Instance Method Details
#init(opts = {}) ⇒ Object
6
7
8
9
10
|
# File 'lib/orange-core/middleware/database.rb', line 6
def init(opts = {})
opts = opts.with_defaults(:migration_url => (orange.options[:development_mode] ? '/__ORANGE_DB__/migrate' : false), :no_auto_upgrade => false)
orange.mixin Orange::Mixins::DBLoader
@options = opts
end
|
#packet_call(packet) ⇒ Object
20
21
22
23
24
25
26
27
28
|
# File 'lib/orange-core/middleware/database.rb', line 20
def packet_call(packet)
path = packet['route.path'] || packet.request.path_info
if @options[:migration_url] && @options[:migration_url] == path
orange.migrate_db!
after = packet.flash('redirect_to') || '/'
packet.reroute(after)
end
pass packet
end
|
#stack_init ⇒ Object
12
13
14
15
16
17
18
|
# File 'lib/orange-core/middleware/database.rb', line 12
def stack_init
unless orange.options.has_key?('database') && orange.options['database'] == false
db = orange.options['database'] || 'sqlite3::memory:'
orange.load_db!(db)
orange.upgrade_db! unless @options[:no_auto_upgrade] || orange.options['db_no_auto_upgrade']
end
end
|