Module: Jenkins::Model::Descriptor

Included in:
DefaultDescriptor, Slaves::NodeProperty::NodePropertyDescriptor
Defined in:
lib/jenkins/model/descriptor.rb

Overview

Jenkins typically defines one Descriptor subtype per extension point, and in Ruby we want to subtype those to add Ruby-specific behaviours.

This class captures commonality of such “Ruby-specific behaviours” across different Descriptors so it can be mixed into the Descriptor subtypes

Instance Method Summary collapse

Instance Method Details

#getConfigPageObject

we take a fully-qualified class name, like Abc::Def::GhiJkl to underscore-separated tokens, like abc/def/ghi_jkl and then look for config.* (where *=.erb, .haml, …)



43
44
45
46
47
# File 'lib/jenkins/model/descriptor.rb', line 43

def getConfigPage
  "/#{name_to_path}/config".tap { |path|
    puts "getConfigPage -> #{path}"
  }
end

#getDisplayNameObject



18
19
20
21
22
23
24
25
26
# File 'lib/jenkins/model/descriptor.rb', line 18

def getDisplayName
  if @impl.respond_to?(:display_name)
    @impl.display_name
  elsif @impl.respond_to?(:getDisplayName)
    @impl.getDisplayName()
  else
    @impl.name
  end
end

#getGlobalConfigPageObject



49
50
51
52
53
54
55
# File 'lib/jenkins/model/descriptor.rb', line 49

def getGlobalConfigPage
  # TODO: use Descriptor.getPossibleViewNames() that's made protected in 1.441 when it gets released
  base = "/#{name_to_path}/global"
  [base+".erb",base+".haml"].find { |n|
    self.getKlass.getResource(n)
  }
end

#getIdObject



28
29
30
# File 'lib/jenkins/model/descriptor.rb', line 28

def getId()
  "#{@plugin.name}-#{@impl.name}"
end

#getKlassObject

let Jenkins use our Ruby class for resource lookup and all



37
38
39
# File 'lib/jenkins/model/descriptor.rb', line 37

def getKlass()
  @plugin.peer.klassFor(@impl)
end

#getTObject



32
33
34
# File 'lib/jenkins/model/descriptor.rb', line 32

def getT()
  @java_type
end

#initialize(impl, plugin, java_type) ⇒ Object



13
14
15
16
# File 'lib/jenkins/model/descriptor.rb', line 13

def initialize(impl, plugin, java_type)
  super(java_type)
  @impl, @plugin, @java_type = impl, plugin, java_type
end

#newInstance(request, form) ⇒ Object



57
58
59
60
61
62
63
64
# File 'lib/jenkins/model/descriptor.rb', line 57

def newInstance(request, form)
  properties = JSON.parse(form.toString(2))
  properties.delete("kind")
  properties.delete("stapler-class")
  instance = construct(properties)
  puts "instance created: #{instance} (#{@java_type})"
  return @plugin.export(instance)
end