Sha256: 8339079a2bc9461a6ac9de42c3373089b5c1674085cc751c99c4b3083bef5324
Contents?: true
Size: 1.49 KB
Versions: 3
Compression:
Stored size: 1.49 KB
Contents
require 'fileutils' class APILookup class MissingHome < StandardError end class LookupBase < ActiveRecord::Base end if ENV["HOME"].nil? puts "The HOME environment variable should be set so lookup knows where" puts "to store it's lookup database." raise MissingHome, "HOME must be set to know where to store our local db." end LookupBase.establish_connection(:adapter => "sqlite3", :database => File.join(ENV["HOME"],".lookup", "lookup.sqlite3")) class Api < LookupBase set_table_name "apis" has_many :constants end class Constant < LookupBase set_table_name "constants" belongs_to :api has_many :entries end class Entry < LookupBase set_table_name "entries" belongs_to :constant end end class SetupTables < ActiveRecord::Migration def self.connection APILookup::Api.connection end def self.up create_table :apis do |t| t.string :name, :url end create_table :entries do |t| t.string :name, :url t.references :constant t.integer :weighting, :default => 0 t.integer :count, :default => 0 end create_table :constants do |t| t.string :name, :url t.references :api t.integer :weighting, :default => 0 t.integer :count, :default => 0 end end end FileUtils.mkdir_p(File.join(ENV["HOME"],".lookup")) if !APILookup::Api.table_exists? && !APILookup::Constant.table_exists? && !APILookup::Entry.table_exists? SetupTables.up APILookup.update end
Version data entries
3 entries across 3 versions & 2 rubygems
Version | Path |
---|---|
radar-lookup-0.2.1 | lib/models.rb |
lookup-0.3.0 | lib/models.rb |
lookup-0.2.2 | lib/models.rb |