Class: Olsen
- Inherits:
-
Object
- Object
- Olsen
- Defined in:
- lib/olsen.rb,
lib/olsen/version.rb
Constant Summary collapse
- VERSION =
"0.0.10"
Class Method Summary collapse
- .filter(value, filters) ⇒ Object
- .initFramework ⇒ Object
- .initSadie(params) ⇒ Object
- .process(job, storage) ⇒ Object
- .registerFilter(name, &block) ⇒ Object
- .setFrameworkDir(dirpath) ⇒ Object
Instance Method Summary collapse
-
#filter(filter_name, value) ⇒ Object
def registerFilter( filter, &block ) defined? @filters \ or @filters = Hash.new @filters = block end.
Class Method Details
.filter(value, filters) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/olsen.rb', line 33 def self.filter( value, filters ) # validate filters defined? filters \ or return value filters.respond_to? "each" \ or return value sadie = Sadie::getCurrentSadieInstance fhnd = "filter.#{filters[0]}" puts "fetching filter: #{fhnd}" sadie.isset? fhnd \ or raise "olsen error: filter(#{fhnd}) does not exist" f = sadie.get fhnd if filters.length > 1 rem = filters[1..(filters.length-1)] ret = f.call value ret = Olsen.filter f.call(ret), rem return ret else ret = f.call value return ret end end |
.initFramework ⇒ Object
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/olsen.rb', line 61 def self.initFramework if ! defined? @@framework_dirpath puts "framework dirpath not set...aborting." return nil end puts "initializing olsen framework in #{@@framework_dirpath}" [ "output", "jobs", "primers" ].each do |dir| Dir.mkdir File.join( @@framework_dirpath, dir ) end end |
.initSadie(params) ⇒ Object
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 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/olsen.rb', line 82 def self.initSadie( params ) sadieparams = { "sadie.primers_dirpath" => "primers" } # if session and output dirs not defined, create temp dirs and use them if ! sadieparams.has_key? "sadie.sessions_dirpath" Dir.mktmpdir("olsen_tmp_sess") do | dir | sadieparams["sadie.sessions_dirpath"] = dir end end if ! sadieparams.has_key? "olsen.output_dirpath" Dir.mktmpdir("olsen_output") do | dir | sadieparams["olsen.output_dirpath"] = dir end end # process params if defined? params if params.respond_to? "each" params.each do |k,v| sadieparams[k] = v end end end # init sadie storage = Sadie::getSadieInstance( sadieparams ) # add olsen plugin handlers plugins_dirpath = File.join( ENV['GEM_HOME'], "gems/olsen-#{Olsen::VERSION}", "lib/olsen/primer_plugins" ) if ! File.exists? plugins_dirpath # for dev plugins_dirpath = File. "lib/olsen/primer_plugins" end if ! File.exists? plugins_dirpath # for dev plugins_dirpath = File.join "/home/fred/Source/LMSys/olsen", "lib/olsen/primer_plugins" end storage.addPrimerPluginsDirPath plugins_dirpath storage.initializePrimers end |
.process(job, storage) ⇒ Object
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/olsen.rb', line 127 def self.process( job, storage ) if ( ! defined?( job ) ) puts "job parameter was undefined. must be hash or file. returning nil." return nil end # turn files into hashes if ! job.respond_to? "each" if File.exists? job job = Sadie::iniFileToHash( job ) elsif defined? @@framework_dirpath jobdirpath = File.join( @@framework_dirpath, "jobs" ) jobfile = File.join jobdirpath, "#{job}.job" if File.exists? jobfile job = Sadie::iniFileToHash( jobfile ) end else puts "job param was non-hash and was not a path to valid job file" return nil end end # validate job if ! job.has_key? "output" puts "job has no output definition" return nil end # call output triggers storage = Sadie::getCurrentSadieInstance job["output"].each do |x,type| outputkey = "output.#{type}" puts "processing output trigger: #{outputkey}" storage.output outputkey end if block_given? yield storage end end |
.registerFilter(name, &block) ⇒ Object
76 77 78 79 80 |
# File 'lib/olsen.rb', line 76 def self.registerFilter( name, &block ) puts "registering filter: #{name}" instance = Sadie::getCurrentSadieInstance instance.set "filter.#{name}", block end |
.setFrameworkDir(dirpath) ⇒ Object
72 73 74 |
# File 'lib/olsen.rb', line 72 def self.setFrameworkDir( dirpath ) @@framework_dirpath = dirpath end |
Instance Method Details
#filter(filter_name, value) ⇒ Object
def registerFilter( filter, &block )
defined? @filters \
or @filters = Hash.new
@filters["filter"] = block
end
177 178 179 180 181 182 183 184 185 186 |
# File 'lib/olsen.rb', line 177 def filter( filter_name, value ) defined? @filters \ or return nil @filters.respond_to? "has_key?" \ or return nil @filters.has_key? filter_name \ or return nil f = @filters[filter_name] f.call value end |