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 28 29 30 |
# File 'lib/sinatra/activerecord.rb', line 20 def database @database ||= begin ActiveRecord::Base.logger = activerecord_logger ActiveRecord::Base.establish_connection(resolve_spec(database_spec)) begin ActiveRecord::Base.connection rescue Exception => e end ActiveRecord::Base end end |
#database=(spec) ⇒ Object
14 15 16 17 18 |
# File 'lib/sinatra/activerecord.rb', line 14 def database=(spec) set :database_spec, spec @database = nil database end |
#database_file=(path) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/sinatra/activerecord.rb', line 32 def database_file=(path) require 'pathname' return if root.nil? path = File.join(root, path) if Pathname.new(path).relative? if File.exists?(path) require 'yaml' require 'erb' database_hash = YAML.load(ERB.new(File.read(path)).result) || {} ActiveRecord::Base.configurations = database_hash database_hash = database_hash[environment.to_s] if database_hash[environment.to_s] set :database, database_hash end end |