Sha256: 88c3bdf98365ead666c5edcb83dab6b1c6d444bcffad2db4b57dd94a7c3fbf36
Contents?: true
Size: 1.19 KB
Versions: 6
Compression:
Stored size: 1.19 KB
Contents
# -*- coding: utf-8 -*- require 'tengine/job/jobnet' module Tengine::Job::Jobnet::StateTransition def self.included(mod) mod.extend(ClassMethods) end module ClassMethods def available(method_name, options = {}) original_method = :"__#{method_name}_without_ignore_and_na" available_phase_keys = Array(options[:on]) ignored_phase_keys = Array(options[:ignored]) ignore_case = ignored_phase_keys.empty? ? "" : "when #{ignored_phase_keys.map(&:inspect).join(', ')} then return" class_eval(<<-EOS, __FILE__, __LINE__ + 1) if method_defined?(:#{original_method}) raise "Already available_on #{method_name}" end alias #{original_method} #{method_name} def #{method_name}(*args, &block) case self.phase_key when #{available_phase_keys.map(&:inspect).join(', ')} then #{original_method}(*args, &block) #{ignore_case} else raise Tengine::Job::Executable::PhaseError, "\#{name_path} \#{self.class.name}##{method_name} not available when the phase_key of \#{self.name_path.inspect} is \#{self.phase_key.inspect}" end end EOS end end end
Version data entries
6 entries across 6 versions & 1 rubygems