Sha256: cd066eb8ceb4c9a8e41daa66e96b6f2f8fc5ed043ebe77109011f77ffc75b5ba
Contents?: true
Size: 1.31 KB
Versions: 4
Compression:
Stored size: 1.31 KB
Contents
require 'yaml' module Prj class App class << self attr_accessor :config_path end @config_path = File.expand_path("~/.prj.yml").freeze def initialize(output, args = []) @letters = String(args.first).each_char.to_a @output = output end def run if @letters.empty? @output.puts File.expand_path(config.fetch("projects_root")) return 0 end finder = Finder.new(config.fetch("projects_root"), symbolize_keys(config)) filter = Filter.new(@letters, config.fetch("case_sensitive")) directories = finder.find_project_directories filtered_directories = filter.filter(directories) target_directory = File.expand_path(File.join(config.fetch("projects_root"), filtered_directories.first.to_s)) @output.puts target_directory 0 end def config @config ||= begin config = File.exist?(self.class.config_path) ? YAML.load(File.read(self.class.config_path)) : {} default_config.merge(config) end end private def default_config default_config = { "projects_root" => File.expand_path("~/Projects"), "vcs_directories" => [".git"], "case_sensitive" => true } end def symbolize_keys(hash) Hash[hash.map { |k, v| [k.to_sym, v] }] end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
prj-2.0.1 | lib/prj/app.rb |
prj-2.0.1.pre.2 | lib/prj/app.rb |
prj-2.0.1.pre.1 | lib/prj/app.rb |
prj-2.0.0 | lib/prj/app.rb |