Class: Lolcommits::Lolsrv
- Inherits:
-
Plugin
- Object
- Plugin
- Lolcommits::Lolsrv
show all
- Defined in:
- lib/lolcommits/plugins/lolsrv.rb
Instance Attribute Summary
Attributes inherited from Plugin
#options, #runner
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Plugin
#configuration, #configure_options!, #debug, #enabled?, #execute_postcapture, #execute_precapture, #log_error, #parse_user_input, #puts, #run_precapture, #valid_configuration?
Constructor Details
#initialize(runner) ⇒ Lolsrv
Returns a new instance of Lolsrv.
8
9
10
11
|
# File 'lib/lolcommits/plugins/lolsrv.rb', line 8
def initialize(runner)
super
options << 'server'
end
|
Class Method Details
.name ⇒ Object
51
52
53
|
# File 'lib/lolcommits/plugins/lolsrv.rb', line 51
def self.name
'lolsrv'
end
|
.runner_order ⇒ Object
55
56
57
|
# File 'lib/lolcommits/plugins/lolsrv.rb', line 55
def self.runner_order
:postcapture
end
|
Instance Method Details
18
19
20
|
# File 'lib/lolcommits/plugins/lolsrv.rb', line 18
def configured?
!configuration['enabled'].nil? && configuration['server']
end
|
#existing_lols ⇒ Object
31
32
33
34
35
36
37
38
|
# File 'lib/lolcommits/plugins/lolsrv.rb', line 31
def existing_lols
lols = JSON.parse(
RestClient.get(configuration['server'] + '/lols'))
lols.map { |lol| lol['sha'] }
rescue => e
log_error(e, "ERROR: existing lols could not be retrieved #{e.class} - #{e.message}")
return nil
end
|
#run_postcapture ⇒ Object
13
14
15
16
|
# File 'lib/lolcommits/plugins/lolsrv.rb', line 13
def run_postcapture
return unless valid_configuration?
fork { sync }
end
|
#sync ⇒ Object
22
23
24
25
26
27
28
29
|
# File 'lib/lolcommits/plugins/lolsrv.rb', line 22
def sync
existing = existing_lols
return unless existing.nil?
Dir[runner.config.loldir + '/*.{jpg,gif}'].each do |item|
sha = File.basename(item, '.*')
upload(item, sha) unless existing.include?(sha) || sha == 'tmp_snapshot'
end
end
|
#upload(file, sha) ⇒ Object
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/lolcommits/plugins/lolsrv.rb', line 40
def upload(file, sha)
RestClient.post(configuration['server'] + '/uplol',
:lol => File.new(file),
:url => runner.git_info.url + sha,
:repo => runner.git_info.repo,
:date => File.ctime(file),
:sha => sha)
rescue => e
log_error(e, "ERROR: Upload of lol #{sha} FAILED #{e.class} - #{e.message}")
end
|