lib/vtools/shared_methods.rb in vtools-0.0.3 vs lib/vtools/shared_methods.rb in vtools-0.1.0
- old
+ new
@@ -6,19 +6,19 @@
module SharedMethods
# both static & instance bindings
module Common
@@logger = nil
-
+
# custom logger
def logger= logger
@@logger = logger
end
# logger mechanics
def log level, message = ""
-
+
if CONFIG[:logging]
unless @@logger
output = CONFIG[:log_file] || STDOUT
logger = Logger.new(output, 1000, 1024000)
logger.level = Logger::INFO
@@ -26,11 +26,11 @@
end
@@logger.send(level, message) if @@logger
end
end
-
+
# converts json to the ruby object
# returns nil on invalid JSON
def json_to_obj json_str
hash_to_obj(parse_json(json_str))
end
@@ -76,21 +76,31 @@
response
end
# function to create correct subdirectories to the file
def generate_path file_name, scope = "video"
- storage = CONFIG[:"#{scope}_storage"]
- return instance_exec(file_name, &storage) if storage.is_a? Proc
- (!storage || storage.empty? ? CONFIG[:PWD] : storage).to_s.strip.gsub(%r#/$#, '')
+ generator = CONFIG[:"#{scope}_path_generator"]
+ begin
+ generator = instance_exec(file_name, &generator).to_s if generator.is_a? Proc
+ rescue => e
+ generator = nil
+ raise ConfigError, "Path generator error (#{e})"
+ end
+
+ storage = CONFIG[:"#{scope}_storage"].to_s
+ storage += "/" unless storage.empty?
+ storage += generator || ""
+
+ (!storage || storage.empty? ? CONFIG[:PWD] : storage).to_s.strip.gsub(%r#/+#, '/').gsub(%r#/$#, '')
end
# path generator setter
def path_generator scope = nil, &block
if scope
scope = "thumb" unless scope == "video"
- CONFIG[:"#{scope}_storage"] = block
+ CONFIG[:"#{scope}_path_generator"] = block
else
- CONFIG[:thumb_storage] = CONFIG[:video_storage] = block
+ CONFIG[:thumb_path_generator] = CONFIG[:video_path_generator] = block
end if block_given?
end
# encoding fixer for iso-8859-1
def fix_encoding(output)