Module: Gloss::Utils

Defined in:
lib/gloss/utils.rb

Class Method Summary collapse

Class Method Details

.abs_path_with_contents(path) ⇒ Object



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

def abs_path_with_contents(path)
  abs_path = absolute_path(path)
return [abs_path, File.open(abs_path)
.read].freeze
end

.absolute_path(path) ⇒ Object



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

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



22
23
24
25
26
27
28
# File 'lib/gloss/utils.rb', line 22

def gem_path_for(gem_name)
  spec = Gem::Specification.find_by_path(gem_name)
  (if spec
    spec.full_require_paths
.first
  end)
end

.src_path_to_output_path(src_path) ⇒ Object



32
33
34
35
# File 'lib/gloss/utils.rb', line 32

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

.with_file_header(str) ⇒ Object



29
30
31
# File 'lib/gloss/utils.rb', line 29

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