Sha256: deb111a4ab3a11428992f85ba6fba1fcdf384c2a92dd5a639ca7a6f4ecf086a9

Contents?: true

Size: 1.17 KB

Versions: 2

Compression:

Stored size: 1.17 KB

Contents

module Stevenson
  module Deployer
    autoload :S3, 'stevenson/deployers/s3'

    module Base
      attr_reader :options

      def self.included(deployer)
        deployer.extend ClassMethods

        Stevenson.deployers[deployer.deployer_name] = deployer
      end

      module ClassMethods
        def deployer_name
          name.gsub(/^.*::/, '').downcase.to_sym
        end
      end

      def initialize(options)
        @options = options
      end

      def deploy!(directory)
        raise NotImplementedError
      end
    end

    class << self
      def deploy(directory, options)
        deployers_for(options).each do |deployer|
          deployer.new(options).deploy!(directory)
        end
      end

      private

      def deployers_for(options)
        [].tap do |deployers|
          deployers << deployer_for(:s3) if options.keys.include?("s3")
        end
      end

      def deployer_for(type)
        Stevenson.deployers.fetch(type, nil) || const_get(type.to_s.capitalize)
      rescue NameError
        raise InvalidDeployerException.new "Type '#{type}' is not a valid deployer."
      end
    end

    class InvalidDeployerException < StandardError; end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
stevenson-2.2.0 lib/stevenson/deployer.rb
stevenson-2.1.0 lib/stevenson/deployer.rb