Class: Jkr::TrialUtils

Inherits:
Object
  • Object
show all
Defined in:
lib/jkr/utils.rb

Class Method Summary collapse

Class Method Details

.define_routine_utils(result_dir, plan, params) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/jkr/utils.rb', line 65

def self.define_routine_utils(result_dir, plan, params)
  _plan = plan
  begin
  line = __LINE__; src = <<EOS
def result_file_name(basename)
  File.join(#{result_dir.inspect}, basename)
end
def rname(basename)
  result_file_name(basename)
end

def result_file(basename, mode = "a+")
  path = result_file_name(basename)
  File.open(path, mode)
end

def common_file_name(basename)
  File.join(File.dirname(#{result_dir.inspect}), basename)
end
def cname(basename)
  result_file_name(basename)
end

def touch_result_file(basename, options = {})
  path = result_file_name(basename)
  FileUtils.touch(path, options)
  path
end

def with_result_file(basename, mode = "a+")
  file = result_file(basename, mode)
  err = nil
  begin
yield(file)
  rescue Exception => e
err = e
  end
  file.close
  raise err if err
  file.path
end
EOS
    if _plan.routine
      _plan.routine.binding.eval(src, __FILE__, line)
    end
  end while _plan = _plan.base_plan
end

.undef_routine_utils(plan) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/jkr/utils.rb', line 48

def self.undef_routine_utils(plan)
  _plan = plan
  begin
    if _plan.routine
      _plan.routine.binding.eval <<EOS
undef result_file
undef result_file_name
undef rname
undef common_file_name
undef cname
undef touch_result_file
undef with_result_file
EOS
    end
  end while _plan = _plan.base_plan
end