Class: SimpleWorker::MergeHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/simple_worker/config.rb

Class Method Summary collapse

Class Method Details

.check_for_file(f, callerr) ⇒ Object

callerr is original file that is calling the merge function, ie: your worker. See Base for examples.



208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
# File 'lib/simple_worker/config.rb', line 208

def self.check_for_file(f, callerr)
  SimpleWorker.logger.debug 'Checking for ' + f.to_s
  f = f.to_str
  f_ext = File.extname(f)
  if f_ext.empty?
    f_ext = ".rb"
    f << f_ext
  end
  exists = false
  if File.exist? f
    exists = true
  else
    # try relative
    #          p caller
    f2 = File.join(File.dirname(callerr), f)
    puts 'f2=' + f2
    if File.exist? f2
      exists = true
      f = f2
    end
  end
  unless exists
    raise "File not found: " + f
  end
  f = File.expand_path(f)
  require f if f_ext == '.rb'
  ret = {}
  ret[:path] = f
  ret[:extname] = f_ext
  ret[:basename] = File.basename(f)
  ret[:name] = ret[:basename]
  ret
end

.create_gem_info(gem_name, options = {}) ⇒ Object



242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
# File 'lib/simple_worker/config.rb', line 242

def self.create_gem_info(gem_name, options={})
  gem_info = {:name=>gem_name, :merge=>true}
  if options.is_a?(Hash)
    gem_info.merge!(options)
    if options[:include_dirs]
      gem_info[:include_dirs] = options[:include_dirs].is_a?(Array) ? options[:include_dirs] : [options[:include_dirs]]
    end
  else
    gem_info[:version] = options
  end
  gem_info[:require] ||= gem_name

  path = SimpleWorker::Service.get_gem_path(gem_info)
  SimpleWorker.logger.debug "Gem path=#{path}"
  if !path
    raise "Gem '#{gem_name}' not found."
  end
  gem_info[:path] = path
  gem_info
end