Class: Moka::Utilities

Inherits:
Object show all
Defined in:
lib/commands/lib/utilities.rb

Class Method Summary collapse

Class Method Details

.deepcopy(obj) ⇒ Object



40
41
42
# File 'lib/commands/lib/utilities.rb', line 40

def self.deepcopy(obj)
  Marshal::load(Marshal::dump(obj))
end

.eval_erb_haml(code, ext, scope) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/commands/lib/utilities.rb', line 27

def self.eval_erb_haml(code, ext, scope)
  require "rubygems"
  # evaluates erb or haml code
  if ext == "erb"
    require 'erb'
    eval_string = ERB.new(code).result(scope)
  elsif ext == "haml"
    require 'haml'
    eval_string = Haml::Engine.new(code).render(scope)
  end
  return eval_string
end

.parse_argvalue(argvalue) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/commands/lib/utilities.rb', line 14

def self.parse_argvalue(argvalue)
  # parse argument=value syntax and return [argument, value]
  equal = argvalue.index "="
  unless equal.nil?
    arg_name = argvalue[0..(equal-1)]
    arg_value = argvalue[(equal + 1)..-1]
  else
    arg_name = argvalue
    arg_value = nil
  end
  return [arg_name, arg_value]
end

.parse_grouppage(grouppage) ⇒ Object



4
5
6
7
8
9
10
11
12
# File 'lib/commands/lib/utilities.rb', line 4

def self.parse_grouppage(grouppage)
  # parse group:page syntax and return [page, group]
  semicolon = grouppage.index ":"
  unless semicolon.nil?
    return [grouppage[(semicolon + 1)..-1], grouppage[0..(semicolon-1)]]
  else
    return [grouppage, "root"]
  end
end