Sha256: 74d671ff2af67c86cab6f45c729cc24e998ab2236e749bc9472196dd6f27549a

Contents?: true

Size: 1.35 KB

Versions: 4

Compression:

Stored size: 1.35 KB

Contents

module Deployinator
  module Helpers
    module PluginHelpers
      attr_accessor :plugins
      @plugins = []

      def register_plugins(stack)
        @plugins = []
        global_plugins = Deployinator.global_plugins
        unless global_plugins.nil? then 
          Deployinator.global_plugins.each do |klass|
            @plugins << Deployinator.const_get("#{klass}").new
          end
        end

        unless Deployinator.stack_plugins.nil? || Deployinator.stack_plugins[stack].nil? then
          Deployinator.stack_plugins[stack].each do |klass|
            @plugins << Deployinator.const_get("#{klass}").new
          end
        end
      end

      def notify_plugins(event, state)
        ret = nil
        unless plugins.nil? then
          @plugins.each do |plugin|
            begin
              new_ret = plugin.run(event, state)
              if ret.nil? then
                ret = new_ret
              end
            rescue => e
              raise "Error running plugin #{plugin} with exception #{e.to_s}"
            end
          end
        end
        ret
      end

      def raise_event(event, extra_state = {})
        state = extra_state
        state[:username] = @username
        state[:stack] = @stack
        state[:stage] = @method
        state[:timestamp] = Time.now.to_i
        notify_plugins(event, state)
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
etsy-deployinator-1.1.1 lib/deployinator/helpers/plugin.rb
etsy-deployinator-1.1.0 lib/deployinator/helpers/plugin.rb
etsy-deployinator-1.0.2 lib/deployinator/helpers/plugin.rb
etsy-deployinator-1.0.1 lib/deployinator/helpers/plugin.rb