module DitzStr
Constants
- VERSION
- has_readline
Public Class Methods
debug(s)
click to toggle source
# File lib/ditzstr.rb, line 5 def debug s puts "# #{s}" if $verbose end
find_dir_containing(target, start=Pathname.new("."))
click to toggle source
helper for recursive search
# File lib/ditzstr.rb, line 35 def find_dir_containing target, start=Pathname.new(".") return start if (start + target).exist? unless start.parent.realpath == start.realpath find_dir_containing target, start.parent end end
find_ditz_file(fn)
click to toggle source
my brilliant solution to the ‘gem datadir’ problem
# File lib/ditzstr.rb, line 43 def find_ditz_file fn #dir = $:.find { |p| File.exist? File.expand_path(File.join(p, fn)) } dir = File.exist? File.expand_path(File.join(Gem.datadir("ditz-str"), fn)) raise "can't find #{fn} in any load path (tried #{File.join(Gem.datadir("ditz-str"),fn)}" unless dir File.expand_path File.join(Gem.datadir("ditz-str"), fn) end
has_readline=(val)
click to toggle source
# File lib/ditzstr.rb, line 14 def self.has_readline= val @has_readline = val end
has_readline?()
click to toggle source
# File lib/ditzstr.rb, line 10 def self.has_readline? @has_readline end
home_dir()
click to toggle source
# File lib/ditzstr.rb, line 26 def home_dir @home ||= ENV["HOME"] || (ENV["HOMEDRIVE"] && ENV["HOMEPATH"] ? ENV["HOMEDRIVE"] + ENV["HOMEPATH"] : nil) || begin $stderr.puts "warning: can't determine home directory, using '.'" "." end end
load_plugins(fn)
click to toggle source
# File lib/ditzstr.rb, line 50 def load_plugins fn DitzStr::debug "loading plugins from #{fn}" plugins = YAML::load_file $opts[:plugins_file] plugins.each do |p| fn = DitzStr::find_ditz_file "plugins/#{p}.rb" DitzStr::debug "loading plugin #{p.inspect} from #{fn}" require File.expand_path(fn) end plugins end
Private Instance Methods
debug(s)
click to toggle source
# File lib/ditzstr.rb, line 5 def debug s puts "# #{s}" if $verbose end
find_dir_containing(target, start=Pathname.new("."))
click to toggle source
helper for recursive search
# File lib/ditzstr.rb, line 35 def find_dir_containing target, start=Pathname.new(".") return start if (start + target).exist? unless start.parent.realpath == start.realpath find_dir_containing target, start.parent end end
find_ditz_file(fn)
click to toggle source
my brilliant solution to the ‘gem datadir’ problem
# File lib/ditzstr.rb, line 43 def find_ditz_file fn #dir = $:.find { |p| File.exist? File.expand_path(File.join(p, fn)) } dir = File.exist? File.expand_path(File.join(Gem.datadir("ditz-str"), fn)) raise "can't find #{fn} in any load path (tried #{File.join(Gem.datadir("ditz-str"),fn)}" unless dir File.expand_path File.join(Gem.datadir("ditz-str"), fn) end
home_dir()
click to toggle source
# File lib/ditzstr.rb, line 26 def home_dir @home ||= ENV["HOME"] || (ENV["HOMEDRIVE"] && ENV["HOMEPATH"] ? ENV["HOMEDRIVE"] + ENV["HOMEPATH"] : nil) || begin $stderr.puts "warning: can't determine home directory, using '.'" "." end end
load_plugins(fn)
click to toggle source
# File lib/ditzstr.rb, line 50 def load_plugins fn DitzStr::debug "loading plugins from #{fn}" plugins = YAML::load_file $opts[:plugins_file] plugins.each do |p| fn = DitzStr::find_ditz_file "plugins/#{p}.rb" DitzStr::debug "loading plugin #{p.inspect} from #{fn}" require File.expand_path(fn) end plugins end