Class: EvalUploader

Inherits:
Object
  • Object
show all
Defined in:
lib/captured/uploaders/eval_uploader.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config = {}) ⇒ EvalUploader

Returns a new instance of EvalUploader.



4
5
6
# File 'lib/captured/uploaders/eval_uploader.rb', line 4

def initialize(config = {})
  @config = config
end

Instance Attribute Details

#urlObject

Returns the value of attribute url.



2
3
4
# File 'lib/captured/uploaders/eval_uploader.rb', line 2

def url
  @url
end

Instance Method Details

#gen_remote_name(file) ⇒ Object



8
9
10
# File 'lib/captured/uploaders/eval_uploader.rb', line 8

def gen_remote_name(file)
  Digest::MD5.hexdigest(file+Time.now.to_i.to_s) + File.extname(file)
end

#upload(file) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/captured/uploaders/eval_uploader.rb', line 12

def upload(file)
  remote_path = nil
  remote_name = gen_remote_name(file)
  unless eval @config['upload']['command']
    raise "Upload failed: Bad Eval in config file"
  end
  # if the eval defines remote_path we will copy that to the clipboard
  # otherwise we compute it ouselves
  @url = remote_path || "#{@config['upload']['url']}#{remote_name}"
  @url
end