Module: Reditor

Extended by:
Reditor
Included in:
Reditor, Command
Defined in:
lib/reditor.rb,
lib/reditor/command.rb,
lib/reditor/version.rb

Defined Under Namespace

Classes: Command, LibraryNotFound

Constant Summary collapse

VERSION =
'0.0.3'

Instance Method Summary collapse

Instance Method Details

#detect(name) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/reditor.rb', line 23

def detect(name)
  path = detect_library_path(name) or raise LibraryNotFound, 'No library found'

  if path.file?
    [path.dirname.to_path, path.basename.to_path]
  else
    [path.to_path, '.']
  end
end

#detect_library_path(name) ⇒ Object



33
34
35
# File 'lib/reditor.rb', line 33

def detect_library_path(name)
  detect_library_path_from_loadpath(name) || detect_library_path_from_gem(name)
end

#detect_library_path_from_gem(name) ⇒ Object

TODO: care version specification



48
49
50
51
52
53
54
# File 'lib/reditor.rb', line 48

def detect_library_path_from_gem(name)
  spec = Gem::Specification.find_by_name(name.to_s)

  Pathname.new(spec.full_gem_path)
rescue Gem::LoadError
  nil
end

#detect_library_path_from_loadpath(name) ⇒ Object



37
38
39
40
41
42
43
44
45
# File 'lib/reditor.rb', line 37

def detect_library_path_from_loadpath(name)
  basename = "#{name}.rb"

  $LOAD_PATH.map {|path|
    full_path = File.expand_path(path + '/' + basename)

    Pathname.new(full_path)
  }.detect(&:exist?)
end