Module: Gloss::Utils

Defined in:
lib/gloss/utils.rb

Class Method Summary collapse

Class Method Details

.absolute_path(path) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/gloss/utils.rb', line 10

def absolute_path(path)
  pn = Pathname.new(path)
  (if pn.absolute?
    pn.to_s
  else
    ap = File.absolute_path(path)
    (if File.exist?(ap)
      ap
    else
      throw(:"error", "File path #{path} does not exist (also looked for #{ap})")
    end)
  end)
end

.gem_path_for(gem_name) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/gloss/utils.rb', line 23

def gem_path_for(gem_name)
  begin
    Gem.ui
.instance_variable_set(:"@outs", StringIO.new)
    Gem::GemRunner.new
.run(["which", gem_name])
    Gem.ui
.outs
.string
  rescue SystemExit => e
    nil
  end
end

.src_path_to_output_path(src_path) ⇒ Object



39
40
41
42
# File 'lib/gloss/utils.rb', line 39

def src_path_to_output_path(src_path)
  src_path.sub("#{Config.src_dir}/", "")
.sub(/\.gl$/, ".rb")
end

.with_file_header(str) ⇒ Object



36
37
38
# File 'lib/gloss/utils.rb', line 36

def with_file_header(str)
  "#{Visitor::FILE_HEADER}\n\n#{str}"
end