Module: Sinatra::ActiveRecordExtension
- Defined in:
- lib/sinatra/activerecord.rb
Instance Method Summary collapse
Instance Method Details
#database ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/sinatra/activerecord.rb', line 20 def database @database ||= begin ActiveRecord::Base.logger = activerecord_logger ActiveRecord::Base.establish_connection(resolve_spec(database_url)) ActiveRecord::Base.connection ActiveRecord::Base end end |
#database=(url) ⇒ Object
14 15 16 17 18 |
# File 'lib/sinatra/activerecord.rb', line 14 def database=(url) set :database_url, url @database = nil database end |
#database_file=(path) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/sinatra/activerecord.rb', line 29 def database_file=(path) require 'pathname' return if app_file.nil? path = File.join(app_file, path) if Pathname.new(path).relative? if File.exists?(path) require 'yaml' require 'erb' database_hash = YAML.load(ERB.new(File.read(path)).result) || {} database_hash = database_hash[environment] if database_hash[environment] set :database, database_hash end end |