Sha256: 0a48430ad1c910c76d1a7abe43ece6a3c41923156f6edd28ab6c0360fa285e4b

Contents?: true

Size: 1.72 KB

Versions: 2

Compression:

Stored size: 1.72 KB

Contents

module God
  
  class Behavior < Base
    # Generate a Behavior of the given kind. The proper class if found by camel casing the
    # kind (which is given as an underscored symbol).
    #   +kind+ is the underscored symbol representing the class (e.g. foo_bar for God::Behaviors::FooBar)
    def self.generate(kind)
      sym = kind.to_s.capitalize.gsub(/_(.)/){$1.upcase}.intern
      God::Behaviors.const_get(sym).new
    rescue NameError
      raise NoSuchBehaviorError.new("No Behavior found with the class name God::Behaviors::#{sym}")
    end
    
    # Override this method in your Behaviors (optional)
    #
    # Called once after the Condition has been sent to the block and attributes have been
    # set. Do any post-processing on attributes here
    def prepare
      
    end
    
    # Override this method in your Behaviors (optional)
    #
    # Called once during evaluation of the config file. Return true if valid, false otherwise
    #
    # A convenience method 'complain' is available that will print out a message and return false,
    # making it easy to report multiple validation errors:
    #
    #   def valid?
    #     valid = true
    #     valid &= complain("You must specify the 'pid_file' attribute for :memory_usage") if self.pid_file.nil?
    #     valid &= complain("You must specify the 'above' attribute for :memory_usage") if self.above.nil?
    #     valid
    #   end
    def valid?
      true
    end
    
    #######
    
    def before_start
    end
    
    def after_start
    end
    
    def before_restart
    end
    
    def after_restart
    end
    
    def before_stop
    end
    
    def after_stop
    end
    
    protected
    
    def complain(text)
      puts text
      false
    end
  end
  
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
god-0.2.0 lib/god/behavior.rb
god-0.1.0 lib/god/behavior.rb