Refactored some of the code to match Rubocop style guidelines; will need to create rubocop config to make the style better
This commit is contained in:
parent
4c3ea4ea87
commit
bc799ff2cb
@ -1,5 +1,6 @@
|
|||||||
require 'toml'
|
require 'toml'
|
||||||
|
|
||||||
|
# Loads and handles the application configuration.
|
||||||
class Config
|
class Config
|
||||||
|
|
||||||
# class constructor
|
# class constructor
|
||||||
@ -16,7 +17,7 @@ class Config
|
|||||||
value = @config
|
value = @config
|
||||||
bits = path.split('.')
|
bits = path.split('.')
|
||||||
bits.each { |bit|
|
bits.each { |bit|
|
||||||
if (value.has_key?(bit))
|
if (value.key?(bit))
|
||||||
value = value[bit]
|
value = value[bit]
|
||||||
else
|
else
|
||||||
abort("Configuration value #{path} does exist.")
|
abort("Configuration value #{path} does exist.")
|
||||||
|
@ -2,44 +2,45 @@ require_relative 'util.rb'
|
|||||||
|
|
||||||
require 'fileutils'
|
require 'fileutils'
|
||||||
|
|
||||||
|
# Handles anything pertaining to the video file repository.
|
||||||
class Repository
|
class Repository
|
||||||
|
|
||||||
def initialize(path)
|
def initialize(path)
|
||||||
@basePath = path
|
@base_path = path
|
||||||
|
|
||||||
# create repository base directory
|
# create repository base directory
|
||||||
createDirectory(@basePath)
|
create_directory(@base_path)
|
||||||
|
|
||||||
# create sub-directories
|
# create sub-directories
|
||||||
subPaths = ['ingest', 'archive', 'output']
|
sub_paths = ['ingest', 'archive', 'output']
|
||||||
subPaths.each { |p|
|
sub_paths.each { |p|
|
||||||
createDirectory(File.join(@basePath, p))
|
create_directory(File.join(@base_path, p))
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
def searchIngest
|
def search_ingest
|
||||||
# create our ingest directory path
|
# create our ingest directory path
|
||||||
ingestPath = File.join(@basePath, 'ingest')
|
ingest_path = File.join(@base_path, 'ingest')
|
||||||
# search for files in ingest; ignore non-files (e.g. directories)
|
# search for files in ingest; ignore non-files (e.g. directories)
|
||||||
ingestFiles = Dir.entries(ingestPath).select { |f| File.file? File.join(ingestPath, f) }
|
ingest_files = Dir.entries(ingest_path).select { |f| File.file? File.join(ingest_path, f) }
|
||||||
|
|
||||||
return ingestFiles
|
return ingest_files
|
||||||
end
|
end
|
||||||
|
|
||||||
def archiveFile(filename)
|
def archive_file(filename)
|
||||||
# create source and destination paths for the copy
|
# create source and destination paths for the copy
|
||||||
ingestPath = File.join(@basePath, 'ingest', filename)
|
ingest_path = File.join(@base_path, 'ingest', filename)
|
||||||
archivePath = File.join(@basePath, 'archive', filename)
|
archive_path = File.join(@base_path, 'archive', filename)
|
||||||
|
|
||||||
# perform the copy, preserving file attributes
|
# perform the copy, preserving file attributes
|
||||||
FileUtils.cp(ingestPath, archivePath, preserve: true)
|
FileUtils.cp(ingest_path, archive_path, preserve: true)
|
||||||
end
|
end
|
||||||
|
|
||||||
def cleanupFile(filename)
|
def cleanup_file(filename)
|
||||||
# create ingest path
|
# create ingest path
|
||||||
ingestPath = File.join(@basePath, 'ingest', filename)
|
ingest_path = File.join(@base_path, 'ingest', filename)
|
||||||
# remove the file
|
# remove the file
|
||||||
FileUtils.remove_file(ingestPath)
|
FileUtils.remove_file(ingest_path)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
# Handles the actual transcoding.
|
||||||
class Transcoder
|
class Transcoder
|
||||||
|
|
||||||
def initialize(config, repository)
|
def initialize(config, repository)
|
||||||
@ -6,17 +7,17 @@ class Transcoder
|
|||||||
end
|
end
|
||||||
|
|
||||||
def start
|
def start
|
||||||
puts "Starting transcoder..."
|
puts 'Starting transcoder...'
|
||||||
|
|
||||||
# search for files in ingest
|
# search for files in ingest
|
||||||
ingestFiles = @repository.searchIngest()
|
ingest_files = @repository.search_ingest()
|
||||||
ingestFiles.each { |ifile|
|
ingest_files.each { |ifile|
|
||||||
# archive the file
|
# archive the file
|
||||||
@repository.archiveFile(ifile)
|
@repository.archive_file(ifile)
|
||||||
# perform the transcode
|
# perform the transcode
|
||||||
# // TODO self.transcode(ifile)
|
# // TODO self.transcode(ifile)
|
||||||
# clean up the file from ingest
|
# clean up the file from ingest
|
||||||
@repository.cleanupFile(ifile)
|
@repository.cleanup_file(ifile)
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
def createDirectory(path)
|
def create_directory(path)
|
||||||
if Dir.exists?(path)
|
if Dir.exist?(path)
|
||||||
puts "Directory #{path} already exists."
|
puts "Directory #{path} already exists."
|
||||||
else
|
else
|
||||||
puts "Creating directory #{path}."
|
puts "Creating directory #{path}."
|
||||||
|
Loading…
Reference in New Issue
Block a user