Sha256: b4f192b211b8e10205ff475942cdc9c735824d0a085950e88f5b016de1b2a435

Contents?: true

Size: 1.49 KB

Versions: 10

Compression:

Stored size: 1.49 KB

Contents

require 'pushwagner/ext'
require 'pushwagner/maven'
require 'yaml'

module Pushwagner

  class Environment
    attr_reader :config
    attr_accessor :current, :version

    def initialize(opts = {})
      opts = HashWithIndifferentAccess.new(opts)

      config_file = look_for_config_file(opts[:config_file])

      @version = opts[:version] && opts[:version].to_s
      @current = opts[:environment] || 'default'

      @config = HashWithIndifferentAccess.new(YAML::load_file(config_file) || {})
    end

    def path_prefix
      config['path_prefix'] || '/'
    end

    def maven
      @maven = (config['maven'] ? Maven.new(config['maven'], version) : {})
    end

    def maven?
      maven.any?
    end

    def static
      config['static'] || {}
    end

    def static?
      static.any?
    end

    def environments
      config['environments'] || {}
    end

    def hooks
      config['hooks'] || {}
    end

    def environment
      environments[current] || {}
    end

    def hosts
      environment['hosts'] || []
    end

    def user
      environment['user'] || "nobody"
    end

    private
    def look_for_config_file(file)
      locations = [file, './deploy.yml', './.pw.yml', './config/deploy.yml']

      locations.each do |location|
        return location if File.exist? location
        cf = File.join(File.dirname(__FILE__), location) # i.e rake/thor.
        return cf if File.exist? cf
      end
      raise "Couldn't find config file in locations: #{locations.join(', ')}"
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
pushwagner-0.0.2.6 lib/pushwagner/environment.rb
pushwagner-0.0.2.5 lib/pushwagner/environment.rb
pushwagner-0.0.2.4 lib/pushwagner/environment.rb
pushwagner-0.0.2.3 lib/pushwagner/environment.rb
pushwagner-0.0.2.2 lib/pushwagner/environment.rb
pushwagner-0.0.2.1 lib/pushwagner/environment.rb
pushwagner-0.0.2.0 lib/pushwagner/environment.rb
pushwagner-0.0.1.12 lib/pushwagner/environment.rb
pushwagner-0.0.1.11 lib/pushwagner/environment.rb
pushwagner-0.0.1.10 lib/pushwagner/environment.rb