lib/daemon-ogre.rb in daemon-ogre-1.4.4 vs lib/daemon-ogre.rb in daemon-ogre-1.4.5
- old
+ new
@@ -6,12 +6,14 @@
begin
class << self
#Based on the rb location
def load_directory(directory,*args)
arg = Hash[*args]
- directory = File.expand_path(directory)
+ #directory = File.expand_path(directory)
+ delayed_loads = Array.new
+
if !arg[:delayed].nil?
raise ArgumentError, "Delayed items must be in an "+\
"Array! Example:\n:delayed => ['abc']" if arg[:delayed].class != Array
end
@@ -20,40 +22,58 @@
"Array! Example:\n:exclude => ['abc']" if arg[:excluded].class != Array
end
arg[:type]= "rb" if arg[:type].nil?
- #=================================================================================================================
+ #=============================================================================================================
- puts "LOADING_FILES_FROM_"+directory.to_s.split('/').last.split('.').first.capitalize if $DEBUG
+ ### GET Pre path + validation
+ begin
+ #get method callers path
+ pre_path = caller[1].split('.rb:').first+('.rb')
+ separator_symbol= String.new
+ pre_path.include?('/') ? separator_symbol = '/' : separator_symbol = '\\'
+ pre_path= ((pre_path.split(separator_symbol))-([pre_path.split(separator_symbol).pop])).join(separator_symbol)
+ end
- delayed_loads = Array.new
- Dir["#{directory}/**/*.#{arg[:type]}"].each do |file|
+ puts "LOADING_FILES_FROM_"+directory.to_s.split(separator_symbol).last.split('.').first.capitalize if $DEBUG
- arg[:delayed]= [nil] if arg[:delayed].nil?
+ puts "Elements found in #{directory}" if $DEBUG
+ puts File.join("#{pre_path}","#{directory}","**","*.#{arg[:type]}") if $DEBUG
+ puts Dir[File.join("#{pre_path}","#{directory}","**","*.#{arg[:type]}")].sort.inspect if $DEBUG
+
+ Dir[File.join("#{pre_path}","#{directory}","**","*.#{arg[:type]}")].sort.each do |file|
+
+ arg[:delayed]= [nil] if arg[:delayed].nil?
arg[:excluded]= [nil] if arg[:excluded].nil?
arg[:excluded].each do |except|
- if file.split('/').last.split('.').first == except.to_s.split('.').first
+ if file.split(separator_symbol).last.split('.').first == except.to_s.split('.').first
+
puts file.to_s + " cant be loaded because it's an exception" if $DEBUG
+
else
+
arg[:delayed].each do |delay|
- if file.split('/').last.split('.').first == delay.to_s.split('.').first
+
+ if file.split(separator_symbol).last.split('.').first == delay.to_s.split('.').first
delayed_loads.push(file)
else
load(file)
puts file.to_s if $DEBUG
end
+
end
+
end
end
end
delayed_loads.each do |delayed_load_element|
load(delayed_load_element)
puts delayed_load_element.to_s if $DEBUG
end
- puts "DONE_LOAD_FILES_FROM_"+directory.to_s.split('/').last.split('.').first.capitalize if $DEBUG
+ puts "DONE_LOAD_FILES_FROM_"+directory.to_s.split(separator_symbol).last.split('.').first.capitalize if $DEBUG
end
def get_port(port,max_port=65535 ,host="0.0.0.0")
@@ -71,11 +91,11 @@
end
def error_logger(error_msg,prefix="",log_file=App.log_path)
- ###convert error msg to more humanfriendly one
+ ###convert error msg to more human friendly one
begin
error_msg= error_msg.to_s.gsub('", "','",'+"\n\"")
rescue Exception
error_msg= error_msg.inspect.gsub('", "','",'+"\n\"")
end
@@ -96,16 +116,29 @@
def load_ymls(directory)
require 'yaml'
#require "hashie"
- yaml_files = Dir["#{directory}/**/*.yml"].each { |f| puts f.to_s if $DEBUG }
- puts "\nyaml file found: "+yaml_files.inspect.to_s if $DEBUG
+ begin
+ pre_path = caller[1].split('.rb:').first+('.rb')
+ separator_symbol= String.new
+ pre_path.include?('/') ? separator_symbol = '/' : separator_symbol = '\\'
+ pre_path= ((pre_path.split(separator_symbol))-([pre_path.split(separator_symbol).pop])).join(separator_symbol)
+ end
+
+ puts "Elements found in #{directory}" if $DEBUG
+ puts File.join("#{pre_path}","#{directory}","**","*.yml") if $DEBUG
+ puts Dir[File.join("#{pre_path}","#{directory}","**","*.yml")].sort.inspect if $DEBUG
+
+ yaml_files = Dir[File.join("#{pre_path}","#{directory}","**","*.yml")].sort
+
+ puts "\nyaml file found: "+yaml_files.inspect if $DEBUG
+
@result_hash = {}
yaml_files.each_with_index do |full_path_file_name|
- file_name = full_path_file_name.split('/').last.split('.').first
+ file_name = full_path_file_name.split(separator_symbol).last.split(separator_symbol).first
hash_key = file_name
@result_hash[hash_key] = YAML.load(File.read("#{full_path_file_name}"))
#@result_hash = @result_hash.merge!(tmp_hash)
\ No newline at end of file