Sha256: 8c532da6526e4ad2c630c60689c8c370b5ca84797b18946831458dc68327a4ad

Contents?: true

Size: 904 Bytes

Versions: 34

Compression:

Stored size: 904 Bytes

Contents

module Dply
  module Strategy

    def self.load(config, options)
      require_relative "strategy/#{config.strategy}"
      const = "::Dply::Strategy::#{config.strategy.capitalize}"
      const = Module.const_get(const)

      # persist roles if DPLY_PERSIST_ROLES env is present
      # load roles from roles file
      roles = get_roles
      persist_roles(roles)

      return const.new(config, options)
    end

    private

    def self.persist_roles(roles)
      persist = ENV['DPLY_PERSIST_ROLES']
      return if not persist
      return if not roles
      Logger.logger.info  "persisting roles #{roles}"
      File.open('roles', 'w') { |f| f.write roles }
    end

    def self.get_roles
      ENV['DPLY_ROLES'] ||= roles_from_file
    end

    def self.roles_from_file
      if File.readable? "roles"
        File.read("roles").chomp.strip
      else
        nil
      end
    end


  end
end

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
dply-0.3.15 lib/dply/strategy.rb
dply-0.3.14 lib/dply/strategy.rb
dply-0.3.13 lib/dply/strategy.rb
dply-0.3.12 lib/dply/strategy.rb
dply-0.3.11 lib/dply/strategy.rb
dply-0.3.10 lib/dply/strategy.rb
dply-0.3.9 lib/dply/strategy.rb
dply-0.3.8 lib/dply/strategy.rb
dply-0.3.7 lib/dply/strategy.rb
dply-0.3.6 lib/dply/strategy.rb
dply-0.3.5 lib/dply/strategy.rb
dply-0.3.4 lib/dply/strategy.rb
dply-0.3.3 lib/dply/strategy.rb
dply-0.3.2 lib/dply/strategy.rb
dply-0.3.1 lib/dply/strategy.rb
dply-0.3.0 lib/dply/strategy.rb
dply-0.2.19 lib/dply/strategy.rb
dply-0.2.18 lib/dply/strategy.rb
dply-0.2.17 lib/dply/strategy.rb
dply-0.2.16 lib/dply/strategy.rb