Module: Coco::Helpers

Defined in:
lib/coco/helpers.rb

Overview

Public: Collection of application's helpers methods.

TODO The app is full of `Dir.pwd`. This is the root project directory and must be in Configuration class (or Coco module ?).

Class Method Summary collapse

Class Method Details

.expand(files) ⇒ Object

Public: Expands a bulk of filenames into full path filenames.

files - List of filenames as an Array of String.

Returns an Array of String.


42
43
44
# File 'lib/coco/helpers.rb', line 42

def expand(files)
  files.map {|file| File.expand_path(file) }
end

.index_titleObject

Public: Get page title for the index.html file.

Returns String.


31
32
33
34
35
# File 'lib/coco/helpers.rb', line 31

def index_title
  project_name = File.basename(Dir.pwd)
  version = File.read(File.join(Coco::ROOT, 'VERSION')).strip
  "#{project_name} - Code coverage (coco #{version})"
end

.rb2html(name) ⇒ Object

Public: Get html filename (from a ruby filename) suitable for the coverage directory.

name - String full path filename.

Examples

ruby = '/home/user/my_project/lib/source.rb'
html = Helpers.rb2html(ruby)
#=> '_lib_source.rb.html'

Returns String HTML filename.


24
25
26
# File 'lib/coco/helpers.rb', line 24

def rb2html(name)
  name.sub(Dir.pwd, '').tr('/\\', '_') + '.html'
end

.rb_files_from(directory) ⇒ Object

Public: Get all ruby files from a directory, including sub-directories.

directory - String directory to look into.

Returns an Array of String.


52
53
54
55
# File 'lib/coco/helpers.rb', line 52

def rb_files_from(directory)
  rb_files = File.join(directory, "**", "*.rb")
  Dir.glob(rb_files)
end