Class: Dropcaster::ChannelFileLocator
- Inherits:
-
Object
- Object
- Dropcaster::ChannelFileLocator
- Defined in:
- lib/dropcaster/channel_file_locator.rb
Overview
Encapsulates the strategy how to find the channel definition file
Class Method Summary collapse
-
.locate(sources) ⇒ Object
Locates the channel definition file based on the
sources
directory.
Class Method Details
.locate(sources) ⇒ Object
Locates the channel definition file based on the sources
directory.
-
If
sources
is a single file name, the channel definition file is expected
as channel.yml in the same directory.
-
If
sources
is a single directory name, the channel definition file is
expected as channel.yml in that directory.
-
If
sources
is an array of file names, the channel definition file is
expected as channel.yml in the directory common to all files. If the files are located in more than one directory, an AmbiguousSourcesError is raised. In that case, the caller should specify the channel.yml as command line parameter.
-
If
sources
is an array with more than a single directory name, an
AmbiguousSourcesError is raised. In that case, the caller should specify the channel.yml as command line parameter.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/dropcaster/channel_file_locator.rb', line 25 def locate(sources) channel_source_dir = nil if sources.respond_to?(:at) # More than one source given. Check that they are all in the same directory. distinct_dirs = sources.collect{|source| dir_or_self(source)}.uniq if 1 == distinct_dirs.size # If all are the in same directory, use that as source directory where channel.yml is expected. channel_source_dir = distinct_dirs.first else # Since no channel_file was specified at the command line, throw and quit raise AmbiguousSourcesError.new(sources) end else # If a single file or directory is given, use that as source directory where channel.yml is expected. channel_source_dir = dir_or_self(sources) end File.join(channel_source_dir, CHANNEL_YML) end |