Class: Laborantin::Runner

Inherits:
Object
  • Object
show all
Includes:
Metaprog::Configurable, Singleton
Defined in:
lib/laborantin/runner.rb

Direct Known Subclasses

CliRunner

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Metaprog::Configurable

#load_config!, #save_config

Constructor Details

#initializeRunner

Initializes the root_dir with the current working directory of the shell (i.e. ‘.’).



59
60
61
# File 'lib/laborantin/runner.rb', line 59

def initialize 
  @root_dir = File.expand_path('.') 
end

Instance Attribute Details

#configObject

The configuration of the Runner, a hash serialized in the laborantin.yaml file.



51
52
53
# File 'lib/laborantin/runner.rb', line 51

def config
  @config
end

#root_dirObject

The root_dir is the internal name for the working directory of a Laborantin’s project.



55
56
57
# File 'lib/laborantin/runner.rb', line 55

def root_dir
  @root_dir
end

Instance Method Details

#config_pathObject



83
84
85
# File 'lib/laborantin/runner.rb', line 83

def config_path
  file(dir(:config), 'laborantin.yaml')
end

#dir(*sym) ⇒ Object

Provides a shortcut for building the correct directory path inside the root_dir. Returns a string. Does not check if the directory exists or is readable or anything. e.g. dir(:results) or dir(‘results’) to build the path to the result dir.



67
68
69
# File 'lib/laborantin/runner.rb', line 67

def dir(*sym)
  File.join(root_dir, sym.map{|s| s.to_s})
end

#extra_dirObject



127
128
129
# File 'lib/laborantin/runner.rb', line 127

def extra_dir
  File.join('laborantin', 'extra')
end

#file(dir, sym) ⇒ Object



79
80
81
# File 'lib/laborantin/runner.rb', line 79

def file(dir, sym)
  File.join(dir, sym)
end

#load_analysesObject



123
124
125
# File 'lib/laborantin/runner.rb', line 123

def load_analyses
  load_local_dir(:analyses)
end

#load_commandsObject



111
112
113
# File 'lib/laborantin/runner.rb', line 111

def load_commands
  load_local_dir(:commands)
end

#load_dir(path) ⇒ Object



87
88
89
90
91
92
93
94
95
96
97
# File 'lib/laborantin/runner.rb', line 87

def load_dir(path)
  # Verify the presence of the dir, needed for backward
  # compatibility
  if File.directory?(path) 
    Object::Find.find(path) do |file| 
      if File.extname(file) == '.rb'
        require file 
      end 
    end 
  end 
end

#load_environmentsObject



115
116
117
# File 'lib/laborantin/runner.rb', line 115

def load_environments
  load_local_dir(:environments)
end

#load_extra(what, name) ⇒ Object



131
132
133
# File 'lib/laborantin/runner.rb', line 131

def load_extra(what, name)
  require File.join(extra_dir, what.to_s, name.to_s)
end

#load_extra_commandsObject



135
136
137
138
139
140
141
# File 'lib/laborantin/runner.rb', line 135

def load_extra_commands
  if config and config[:extra].is_a? Hash
    config[:extra].each_pair do |name, val|
      load_extra(:commands, name) if val
    end
  end
end

#load_local_dir(dirname) ⇒ Object

Load the ruby files from the dirname directory of a Laborantin project. Current implementation require all .rb files found in the commands directory.



106
107
108
109
# File 'lib/laborantin/runner.rb', line 106

def load_local_dir(dirname)
  d = dir(dirname)
  load_dir(d)
end

#load_scenariiObject



119
120
121
# File 'lib/laborantin/runner.rb', line 119

def load_scenarii
  load_local_dir(:scenarii)
end

#load_user_commandsObject



99
100
101
102
# File 'lib/laborantin/runner.rb', line 99

def load_user_commands
  dir = File.join(user_laborantin_dir, 'commands')
  load_dir(dir)
end

#prepareObject

Prepare a Runner by loading the configuration and the extra commands.



144
145
146
147
148
149
150
151
152
# File 'lib/laborantin/runner.rb', line 144

def prepare
  load_config!
  load_user_commands
  load_commands
  load_environments
  load_scenarii
  load_analyses
  load_extra_commands
end

#resultdirObject



71
72
73
# File 'lib/laborantin/runner.rb', line 71

def resultdir
  dir(:results)
end

#user_laborantin_dirObject



75
76
77
# File 'lib/laborantin/runner.rb', line 75

def user_laborantin_dir
  File.join(File.expand_path('~'), '.laborantin')
end