lib/lookup.rb in lookup-1.0.0 vs lib/lookup.rb in lookup-1.1.0

- old
+ new

@@ -1,27 +1,23 @@ -require 'rubygems' require 'net/http' +require 'fileutils' -gemfile = File.expand_path('../../Gemfile', __FILE__) -require 'bundler' -ENV['BUNDLE_GEMFILE'] = gemfile -Bundler.require(:default) +require 'active_record' + # Because some of you don't have ActiveSupport 3.0 # And I'm too lazy to require all the shit for 2.3.8 just for this. - class Hash def stringify_keys! keys.each do |key| self[key.to_s] = delete(key) end self end end module Lookup - VERSION = "1.0.0" APIS = [] class APINotFound < StandardError; end class << self @@ -37,10 +33,15 @@ def apis apis = config["apis"].stringify_keys! end def update! + FileUtils.mkdir_p(home) + if !File.exists?(home + "config") + FileUtils.cp(File.dirname(__FILE__) + "/../config/lookup", home + "config") + end + puts "Updating API, this may take a minute or two. Please be patient!" [Constant, Entry, Api].map { |klass| klass.delete_all } puts "Updating #{apis.size} APIs." for api in apis.values update_api!(api["name"], api["url"]) @@ -189,6 +190,6 @@ end end end -require File.join(File.dirname(__FILE__), 'models') +require 'lookup/models'