-
Notifications
You must be signed in to change notification settings - Fork 0
/
environment.rb
75 lines (71 loc) · 2.76 KB
/
environment.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
67
68
69
70
71
72
73
74
require 'bundler'
require 'ostruct'
require 'logger'
require 'mysql2'
require 'active_record'
require 'active_support/all'
require 'composite_primary_keys'
require 'rest_client'
require 'json'
require 'find'
require 'unicode_utils'
require 'addressable/uri'
require 'nokogiri'
require 'sanitize'
require 'htmlentities'
require 'elasticsearch'
require 'haml'
require 'sass'
require 'rinku'
require 'will_paginate'
require 'will_paginate/collection'
require 'will_paginate/view_helpers/sinatra'
require 'rinku'
require 'docsplit'
require 'sinatra'
require 'sinatra/content_for'
require 'yaml'
require 'rack/google-analytics'
module ArticleSemanticizer
def self.symbolize_keys(obj)
if obj.class == Array
obj.map {|o| ArticleSemanticizer.symbolize_keys(o)}
elsif obj.class == Hash
obj.inject({}) {|res, data| res.merge(data[0].to_sym => ArticleSemanticizer.symbolize_keys(data[1]))}
else
obj
end
end
root_path = File.expand_path(File.dirname(__FILE__))
CONF_DATA = ArticleSemanticizer.symbolize_keys(YAML.load(open(File.join(root_path, 'config.yml')).read))
conf = CONF_DATA
environment = ENV['ARTICLESEMANTICIZER_DEV'] || 'development'
Config = OpenStruct.new(
gnrd_api_url: conf[:gnrd_api_url],
resolver_api_url: conf[:resolver_api_url],
crossref_api_url: conf[:crossref_api_url],
biblio_api_url: conf[:biblio_api_url],
eol_search_api_url: conf[:eol_search_api_url],
eol_pages_api_url: conf[:eol_pages_api_url],
alchemy_api_url: conf[:alchemy_api_url],
alchemy_api_key: conf[:alchemy_api_key],
root_path: root_path,
root_file_path: conf[:root_file_path],
environment: environment,
carousel_size: conf[:carousel_size],
elastic_server: conf[:elastic_server],
elastic_index: conf[:elastic_index],
enable_downloads: conf[:enable_downloads],
google_ua_account: conf[:google_ua_account],
google_ua_domain: conf[:google_ua_domain]
)
# load models
db_settings = conf[Config.environment.to_sym]
# ActiveRecord::Base.logger = Logger.new(STDOUT, :debug) if environment == 'test'
ActiveRecord::Base.establish_connection(db_settings)
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), 'lib'))
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), 'lib', 'article_semanticizer'))
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), 'models'))
Dir.glob(File.join(File.dirname(__FILE__), 'lib', '**', '*.rb')) { |lib| require File.basename(lib, '.*') }
Dir.glob(File.join(File.dirname(__FILE__), 'models', '*.rb')) { |model| require File.basename(model, '.*') }
end