lib/spiderfw.rb in spiderfw-0.5.7 vs lib/spiderfw.rb in spiderfw-0.5.9
- old
+ new
@@ -57,17 +57,18 @@
setup_paths(@root)
all_apps = find_all_apps
all_apps.each do |path|
require path+'/config/options.rb' if File.exist?(path+'/config/options.rb')
end
+ @runmode = nil
+ self.runmode = $SPIDER_RUNMODE if $SPIDER_RUNMODE
load_configuration($SPIDER_PATH+'/config')
load_configuration(@root+'/config')
start_loggers
# @controller = Controller
@paths[:spider] = $SPIDER_PATH
- @runmode = nil
- self.runmode = $SPIDER_RUNMODE if $SPIDER_RUNMODE
+
if ($SPIDER_CONFIG_SETS)
$SPIDER_CONFIG_SETS.each{ |set| @configuration.include_set(set) }
end
if File.exist?($SPIDER_RUN_PATH+'/init.rb')
@home.instance_eval(File.read($SPIDER_RUN_PATH+'/init.rb'), $SPIDER_RUN_PATH+'/init.rb')
@@ -98,10 +99,13 @@
# end
# Invoked before a server is started. Apps may implement the app_startup method, that will be called.
def startup
+ unless File.exists?(Spider.paths[:root]+'/init.rb')
+ raise "The server must be started from the root directory"
+ end
if (Spider.conf.get('template.cache.reload_on_restart'))
FileUtils.touch("#{Spider.paths[:tmp]}/templates_reload.txt")
end
if (Spider.conf.get('request.mutex'))
mutex_requests!
@@ -271,10 +275,14 @@
@apps[mod.name] = mod
@apps_by_path[mod.relative_path] = mod
@apps_by_short_name[mod.short_name] = mod
end
+ def app?(path)
+ @apps_by_path[path] ? true : false
+ end
+
def load_configuration(path)
return unless File.directory?(path)
path += '/' unless path[-1] == ?o
require path+'options.rb' if File.exist?(path+'options.rb')
Dir.new(path).each do |f|
@@ -285,11 +293,11 @@
when /\.(yaml|yml)$/
begin
@configuration.load_yaml(path+f)
rescue ConfigurationException => exc
if (exc.type == :yaml)
- @logger.error("Configuration file #{path+f} is not falid YAML")
+ @logger.error("Configuration file #{path+f} is not valid YAML")
else
raise
end
end
end
@@ -366,13 +374,15 @@
return Resource.new(first_found(extensions, cur_path+path[1..-1]), owner_class)
elsif (path[0..1] == '../')
return Resource.new(first_found(extensions, File.dirname(cur_path)+path[2..-1]), owner_class)
end
end
+ app = nil
if (path[0].chr == '/')
+ first_part = path[1..-1].split('/')[0]
Spider.apps_by_path.each do |p, a|
- if (path.index(p) == 1)
+ if first_part == p
app = a
path = path[p.length+2..-1]
break
end
end
@@ -478,10 +488,14 @@
def locale
Locale.current[0]
end
+ def i18n(l = self.locale)
+ Spider::I18n.provider(l)
+ end
+
def test_setup
end
def test_teardown
end
@@ -499,10 +513,9 @@
end
end
end
-
# load instead of require for reload_sources to work correctly
load 'spiderfw/config/options/spider.rb'
Spider::init()