Class: HookGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/skynet/hook_generator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, server, output) ⇒ HookGenerator

Returns a new instance of HookGenerator.



8
9
10
11
12
# File 'lib/skynet/hook_generator.rb', line 8

def initialize(config, server, output)
  @config = config
  @server = server
  @output = output
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



6
7
8
# File 'lib/skynet/hook_generator.rb', line 6

def config
  @config
end

#outputObject (readonly)

Returns the value of attribute output.



6
7
8
# File 'lib/skynet/hook_generator.rb', line 6

def output
  @output
end

#serverObject (readonly)

Returns the value of attribute server.



6
7
8
# File 'lib/skynet/hook_generator.rb', line 6

def server
  @server
end

Instance Method Details

#generateObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/skynet/hook_generator.rb', line 14

def generate
  File.open(output, 'w') do |file|
    payload = {
        repository: { url: config[:url] },
        before: '$oldrev',
        after: '$newrev',
        ref: '$refname'
    }
    file.write <<-EOS.strip_heredoc
      read oldrev newrev refname

      curl -d "payload=#{payload.to_json.gsub('"', '\"')}" #{server}
    EOS
  end
end