Class: Proj

Inherits:
Object show all
Defined in:
lib/shorthand.rb

Instance Method Summary collapse

Constructor Details

#initialize(cwd = nil, cf = nil) ⇒ Proj

Returns a new instance of Proj.



273
274
275
276
277
278
# File 'lib/shorthand.rb', line 273

def initialize(cwd=nil, cf=nil)
  @cached_lookups = {}
  @p_cf           = nil
  @p_cwd          = (cwd || Path.pwd).exp
  @p_cf           = cf.exp unless cf.blank?
end

Instance Method Details

#[](pattern, refresh = false) ⇒ Object



292
293
294
295
# File 'lib/shorthand.rb', line 292

def [](pattern,refresh=false)
  @cached_lookups.delete(pattern) if refresh
  return @cached_lookups[pattern] ||= root_dir[pattern]
end

#root_dirObject



280
281
282
283
284
285
286
287
288
289
290
# File 'lib/shorthand.rb', line 280

def root_dir
  wd_root = root_dir_for(@p_cwd)
  return wd_root if @p_cf.blank?
  cf_root = root_dir_for(@p_cf)
  return @p_cwd  if wd_root.blank? && cf_root.blank?
  return cf_root if wd_root.blank?
  return wd_root if cf_root.blank?
  return wd_root if wd_root === cf_root
  return wd_root if wd_root.relation_to(cf_root) == :parent
  return cf_root
end