module Sinatra::ActiveRecordExtension
Protected Class Methods
registered(app)
click to toggle source
# File lib/magistrate_monitor/sinatra-activerecord.rb, line 32 def self.registered(app) app.set :database_options, Hash.new app.set :database_extras, Hash.new app.set :activerecord_logger, Logger.new(STDOUT) # app.database # force connection app.helpers ActiveRecordHelper app.configure do unless defined?(Rails) env = ENV['RACK_ENV'] || 'development' file = File.join('config', 'database.yml') app.database = YAML::load(ERB.new(IO.read(file)).result).with_indifferent_access[env] end end end
Public Instance Methods
database()
click to toggle source
# File lib/magistrate_monitor/sinatra-activerecord.rb, line 21 def database @database ||= if defined?(Rails) ActiveRecord::Base else #ActiveRecord::Base.logger ||= activerecord_logger # Having this enabled overrides Rails TODO: Find a way to make it not override Rails ActiveRecord::Base.establish_connection(database_options) ActiveRecord::Base end end
database=(cfg)
click to toggle source
# File lib/magistrate_monitor/sinatra-activerecord.rb, line 15 def database=(cfg) @database = nil set :database_options, cfg database end