Skip to content

Commit

Permalink
Loading ActiveRecord in console
Browse files Browse the repository at this point in the history
* Not very smart about getting its DB
* Takes a database.yml from ARGV[0] if you want
  • Loading branch information
trosen-r7 committed Feb 1, 2012
1 parent 208e74b commit 83788d0
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 6 deletions.
33 changes: 27 additions & 6 deletions bin/msstore_console
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#! /usr/bin/env ruby

begin
require 'pry'
require "msf_models"

banner = <<-BANNER
def metastore_banner
banner = {}
banner[:color] = "\e[34m"
banner[:text] = <<-BANNER
mm mm
MM MM
`7MMpMMMb.pMMMb. .gP"Ya mmMMmm ,6"Yb. ,pP"Ybd mmMMmm ,pW"Wq.`7Mb,od8 .gP"Ya
Expand All @@ -13,8 +12,30 @@ begin
MM MM MM YM. , MM 8M MM L. I8 MM YA. ,A9 MM YM. ,
.JMML JMML JMML.`Mbmmd' `Mbmo`Moo9^Yo.M9mmmP' `Mbmo`Ybmd9'.JMML. `Mbmmd'
BANNER
banner
end

begin
require 'pry'
require "msf_models"

# Set up a DB connection, preferring one from Pro if it's in the normal place
# Otherwise get from ARGV[0]
relative_dev_path = File.expand_path(File.dirname(__FILE__) + "/../../pro/ui/config/database.yml")
db_info_path = ARGV[0].blank? ? relative_dev_path : ARGV[0]

if File.readable?(db_info_path)
connection_info = YAML.load_file(db_info_path)
ActiveRecord::Base.establish_connection(connection_info['development'])
else
warn "Can't access DB -- check file path Exiting."
end

include MsfModels
MsfModels.create_and_load_ar_classes


puts "\e[34m#{banner}\e[0m"
puts "\n\n\n#{metastore_banner[:color]}#{metastore_banner[:text]}\e[0m\n\n\n"

Pry.config.prompt = proc { |obj, nest_level, _| "msstore:#{nest_level}> " }

Expand Down
9 changes: 9 additions & 0 deletions console_db.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
development:
adapter: postgresql
database: msf3_dev
host: localhost
port: 5432
username: msf3
password: pass123
pool: 5
timeout: 5

0 comments on commit 83788d0

Please sign in to comment.