Sha256: 460acdfd077fda47d6bd0f42c7f19e2291f7a72a32bc312f9d8a95f9d6c3cff4
Contents?: true
Size: 1.61 KB
Versions: 2
Compression:
Stored size: 1.61 KB
Contents
require 'topicz/defaults' require 'topicz/repository' require 'yaml' module Topicz::Commands class RepositoryCommand def initialize(config_file = nil) @config = load_config(config_file) @repository = load_repository end def load_config(config_file) file = config_file != nil ? config_file : Topicz::DEFAULT_CONFIG_LOCATION unless File.exist? file raise "File doesn't exist: #{file}." end unless File.readable? file raise "File isn't readable: #{file}." end begin config = YAML.load_file(file) rescue raise "Not a valid YAML file: #{file}." end unless config.has_key?('repository') raise "Missing required property 'repository' in configuration file: #{file}." end config end def load_repository directory = @config['repository'] unless Dir.exist? directory raise "Repository directory doesn't exist: #{directory}." end Topicz::Repository.new(directory) end def find_exactly_one_topic(filter, strict) if strict topic = @repository[filter] if topic == nil raise "No topic found with ID: '#{filter}'" end topic else topics = @repository.find_all filter if topics.length == 0 raise "No topics found matching the search filter: '#{filter}'" end if topics.length > 1 matches = topics.map { |t| t.title }.join("\n") raise "Multiple topics match the search filter: '#{filter}'. Matches:\n#{matches}" end topics[0] end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
topicz-0.1.1 | lib/topicz/commands/repository_command.rb |
topicz-0.1.0 | lib/topicz/commands/repository_command.rb |