Class: Janky::Builder::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/janky/builder/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, callback_url) ⇒ Client

Returns a new instance of Client.



4
5
6
7
# File 'lib/janky/builder/client.rb', line 4

def initialize(url, callback_url)
  @url          = URI(url)
  @callback_url = URI(callback_url)
end

Instance Attribute Details

#callback_urlObject (readonly)

The String absoulte URL callback of this Janky host.



13
14
15
# File 'lib/janky/builder/client.rb', line 13

def callback_url
  @callback_url
end

#urlObject (readonly)

The String absolute URL of the Jenkins server.



10
11
12
# File 'lib/janky/builder/client.rb', line 10

def url
  @url
end

Instance Method Details

#adapterObject

The adapter used to trigger builds. Defaults to HTTP, which hits the Jenkins server configured by ‘setup`.



46
47
48
# File 'lib/janky/builder/client.rb', line 46

def adapter
  @adapter ||= HTTP.new(url.user, url.password)
end

#complete!Object

Simulate the last callback. Only available when mocked.



77
78
79
# File 'lib/janky/builder/client.rb', line 77

def complete!
  @adapter.complete
end

#green!Object Also known as: enable_mock!, reset!

Enable the mock adapter and make subsequent builds green.



55
56
57
58
# File 'lib/janky/builder/client.rb', line 55

def green!
  @adapter = Mock.new(true, Janky.app)
  job_creator.enable_mock!
end

#job_creatorObject



50
51
52
# File 'lib/janky/builder/client.rb', line 50

def job_creator
  @job_creator ||= JobCreator.new(url, @callback_url)
end

#output(build) ⇒ Object

Retrieve the output of the given Build.

build - a Build object. Must have an url attribute.

Returns the String build output.



29
30
31
# File 'lib/janky/builder/client.rb', line 29

def output(build)
  Runner.new(@url, build, adapter).output
end

#red!Object

Enable the mock adapter and make subsequent builds red.



67
68
69
# File 'lib/janky/builder/client.rb', line 67

def red!
  @adapter = Mock.new(false, Janky.app)
end

#run(build) ⇒ Object

Trigger a Jenkins build for the given Build.

build - a Build object.

Returns the Jenkins build URL.



20
21
22
# File 'lib/janky/builder/client.rb', line 20

def run(build)
  Runner.new(@url, build, adapter).run
end

#setup(name, repo_uri, template_path) ⇒ Object

Setup a job on the Jenkins server.

name - The desired job name as a String. repo_uri - The repository git URI as a String. template_path - The Pathname to the XML config template.

Returns nothing.



40
41
42
# File 'lib/janky/builder/client.rb', line 40

def setup(name, repo_uri, template_path)
  job_creator.run(name, repo_uri, template_path)
end

#start!Object

Simulate the first callback. Only available when mocked.



72
73
74
# File 'lib/janky/builder/client.rb', line 72

def start!
  @adapter.start
end