-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.rb
66 lines (48 loc) · 1.37 KB
/
config.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# encoding: UTF-8
Encoding.default_external = "UTF-8"
Encoding.default_internal = "UTF-8"
# PRE-DEFINED VARS
TIME_START = Time.now
TEXT_COL_LEN = 80
APP_ROOT ||= File.expand_path(File.dirname(__FILE__))
APP_ENV ||= 'scraper'
APP_MODE ||= 'webapp'
DEBUG ||= false
# REQUIRE MODULES/GEMS
%w{active_record mysql2 paperclip twitter yaml aws-sdk}.each{|r| require r}
# GET APP CONFIG
APP_CONFIG = YAML::load(File.open("#{APP_ROOT}/config.yml"))[APP_ENV]
# SETUP DATABASE
ActiveRecord::Base.establish_connection( YAML::load(File.open("#{APP_ROOT}/database.yml"))[APP_ENV] )
# REQUIRE DATABASE MODELS
Dir.glob("#{APP_ROOT}/models/*.rb").each{|r| require r}
# MISCELLANEOUS FUNCTIONS
def camelize(str)
str.split('_').map {|w| w.capitalize}.join
end
def time_since_overall; time_since(TIME_START); end
def time_since(start=nil)
@_time_since ||= TIME_START
start ||= @_time_since
@_time_since = Time.now
"#{Time.now - start} seconds"
end
# TEXT FORMATTING
def _heading(str)
puts "\n\n\n"
_divider('#')
puts " #{str.upcase} ".center(TEXT_COL_LEN)
_divider('#')
end
def _subheading(str)
puts "\n\n"
puts " #{str.upcase} ".center(TEXT_COL_LEN, '-')
end
def _divider(str='-', t=false, b=false)
puts "\n\n" if t
puts "".center(TEXT_COL_LEN, str)
puts "\n\n" if b
end
def _debug(msg, spaces=0)
puts "#{' ' * spaces}#{msg}" if defined?(DEBUG) && DEBUG
end