Sha256: 5175d092d1cadb1b0ac2ffe2f982e8fa4e82febffc4974d0f4485cfb4a7f085b
Contents?: true
Size: 1.14 KB
Versions: 3
Compression:
Stored size: 1.14 KB
Contents
# rubocop: disable all require 'pathname' require 'erb' Import = Object.new class << Import def script @script ||= nil @script end def config @config ||= nil @config end def init(name) @script = read(name) @config = ERB.new(read("#{name}.yml") || '').result info end # returns Hash { 'pull' => '/home/dk/.doit/pull', ... } def list @list ||= list2 end def info return unless Doit.options[:verbose] My.verbose 'SCRIPT', @script My.verbose 'CONFIG(yml)', @config end private def list2 res = {} Pathname.pwd.descend { |dir| doit_dir = dir + '.doit' next unless File.directory?(doit_dir) lst = [] Dir.entries(doit_dir).each { |name| name = File.join(doit_dir, name) next unless File.executable?(name) next if File.directory?(name) lst << name } lst.each { |itm| res[File.basename(itm)] = itm } } res end def read(name) try_ascend(".doit/#{name}") end def try_ascend(filename) Pathname.pwd.ascend { |dir| str = dir + filename return File.read(str) if File.exist?(str) } nil end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
doit-1.0.2 | lib/import.rb |
doit-1.0.1 | lib/import.rb |
doit-0.3.9 | lib/import.rb |