Parent

Syckle::Service

Service

The plugin acts a base class for ecapsulating batch routines. This helps to keep the main batch context free of the clutter of private supporting methods.

Plugins are tightly coupled to the batch context, which allows them to call on the context easily. However this means plugins cannot be used independent of a batch context, and changes in the batch context can cause effects in plugin behvior that can be harder to track down and fix if a bug arises.

The context must be a subclass of Syckle::Script.

Attributes

active[RW]
context[R]

The batch context.

key[R]
options[R]
priority[RW]

Public Class Methods

aftcycle(name, phase=nil, &block) click to toggle source

Designate the procedure to run after the main cycle procedure.

# File lib/syckle/service.rb, line 86
def self.aftcycle(name, phase=nil, &block)
  unless phase
    name, phase = *name.split(':')
    name, phase = 'main', name unless phase
  end
  phase = ('aft_' + phase.to_s).to_sym
  cycle(name, phase, &block)
end
autorun(&block) click to toggle source

DEPRECATE: temporarily, this is a no-op to prevent old plugins from breaking.

# File lib/syckle/service.rb, line 108
def self.autorun(&block)
#  @autorun = block if block
#  @autorun ||= nil
end
available(&block) click to toggle source
# File lib/syckle/service.rb, line 96
def self.available(&block)
  @available = block if block
  @available ||= nil
end
available?(project) click to toggle source
# File lib/syckle/service.rb, line 102
def self.available?(project)
  return true unless available
  @available.call(project)
end
cycle(name, phase=nil, &block) click to toggle source

Define the procedure for a given cycle-phase.

cycle '<cycle>:<phase>' do
  ...
end
# File lib/syckle/service.rb, line 59
def self.cycle(name, phase=nil, &block)
  unless phase
    name, phase = *name.split(':')
    name, phase = 'main', name unless phase
  end
  if block
    define_method("#{name}_#{phase}", &block)
  else
    define_method("#{name}_#{phase}") do
      send(phase)
    end
  end
end
factory(&block) click to toggle source
# File lib/syckle/service.rb, line 44
def self.factory(&block)
  Class.new(self, &block)
end
inherited(base) click to toggle source

TODO: Probably should make a named registry instead.

# File lib/syckle/service.rb, line 36
def self.inherited(base)
  return if base.name.to_s.empty?
  if base.name !~ /Service$/
    registry[base.basename.downcase] = base
  end
end
init(&block) click to toggle source

NOTE: How is this being used?

# File lib/syckle/service.rb, line 49
def self.init(&block)
  define_method(:init, &block)
end
new(context, key, options={}) click to toggle source
# File lib/syckle/service.rb, line 143
def initialize(context, key, options={})
  @context  = context
  @project  = context.project
  @key      = key
  @options  = options || {}

  @priority = 0
  @active   = true

  raise TypeError, "context must be a subclass of Syckle::Script" unless context.is_a?(Syckle::Script) # Syckle::DSL

  initialize_defaults

  options ||= {}

  options.each do |k, v|
    send("#{k}=", v) unless v.nil? #if respond_to?("#{k}=") && !v.nil?
  end
end
precycle(name, phase=nil, &block) click to toggle source

Designate the procedure to run prior to the main cycle procedure.

# File lib/syckle/service.rb, line 75
def self.precycle(name, phase=nil, &block)
  unless phase
    name, phase = *name.split(':')
    name, phase = 'main', name unless phase
  end
  phase = ('pre_' + phase.to_s).to_sym
  cycle(name, phase, &block)
end
registry() click to toggle source
# File lib/syckle/service.rb, line 31
def self.registry
  @@registry ||= {}
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.