Skip to content

Instantly share code, notes, and snippets.

@itspriddle
Created April 16, 2009 23:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save itspriddle/96740 to your computer and use it in GitHub Desktop.
Save itspriddle/96740 to your computer and use it in GitHub Desktop.
require 'activerecord'
DB_HOST = 'localhost'
DB_USER = 'username'
DB_PASS = 'password'
DB_NAME = 'database'
class Movie < ActiveRecord::Base
class << self
def connect_db
return if self.table_name == 'movies'
conf = {'username' => DB_USER, 'host' => DB_HOST, 'password' => DB_PASS, 'database' => DB_NAME, 'adapter' => 'mysql'}
self.establish_connection(conf)
self
end
def scan_for_new
Dir['/media/iptv/hd2/movies/**'].each do |path|
Movie.create({:filename => path})
end
end
end
end
Movie.connect_db
Movie.scan_for_new
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment