Module: Jenkins::Plugin::Behavior
- Includes:
- BehavesAs
- Included in:
- CLI::Command, Extension, Listeners::RunListener, Model, Model::Describable, Model::EnvironmentProxy, Proxy, Wrapper, Slaves::ComputerListener
- Defined in:
- lib/jenkins/plugin/behavior.rb
Overview
A Behavior will receive a callback any time that it is included into a class or when a class that has been included is extended. This is needed for a couple reasons.
One case is to enable Transient marking behavior. Every time a concrete model class is implemented, it needs the ability to define which of its attributes are transient, so that they will not be persisted with the Jenkins serialization. which attributes are tracked on a per-class basis, so we need a callback for each class in the inheritance hierachy.
class Foo
include Model
transient :foo do
@foo = 1 + 2
end
end class Bar < Foo
transient :bar do # <- no need to include Model
@bar =
end
end
Another is the case of auto registration. We want to be able to find out when extension points are implemented, and register them with the Jenkins Runtime
module Descriptor
implemented do |cls|
Jenkins.plugin.on.start do |plugin|
plugin.register_extension new(Jenkins.plugin, cls.ruby_type, cls.java_type)
end
end
end
And of course, there is the case of proxies where we need to make sure that certain behaviors are always included into the proxy, and that if java classes need to be implemented, they are.
If the module (=X) that extend Behavior defines a module named ClassMethods in it, then every subtype of X automatically extends this ClassMethods.n
module Foo
extend Behavior
module ClassMethod
def look_ma
puts "I'm here'"
end
end
end class Bar
include Foo
end
Bar.look_ma
Defined Under Namespace
Modules: BehavesAs, Implementation
Class Method Summary collapse
Instance Method Summary collapse
Methods included from BehavesAs
Class Method Details
.extended(mod) ⇒ Object
80 81 82 83 84 85 |
# File 'lib/jenkins/plugin/behavior.rb', line 80 def self.extended(mod) super(mod) mod.instance_eval do @_behaviors = Set.new([self]) end end |
Instance Method Details
#implemented(cls = nil, &implemented_block) ⇒ Object
72 73 74 75 76 77 78 |
# File 'lib/jenkins/plugin/behavior.rb', line 72 def implemented(cls = nil, &implemented_block) if cls @implemented_block.call cls if @implemented_block else @implemented_block = implemented_block end end |
#included(mod) ⇒ Object
62 63 64 65 66 67 68 69 70 |
# File 'lib/jenkins/plugin/behavior.rb', line 62 def included(mod) if mod.is_a? Class mod.extend Implementation unless mod.is_a? Implementation else mod.extend Behavior unless mod.is_a? Behavior end mod.behaves_as *@_behaviors super(mod) end |