Sha256: b51f939cf205cf7f48315a7b503777922bdc1b770b95cc7d6070fdb92e780247

Contents?: true

Size: 1.09 KB

Versions: 5

Compression:

Stored size: 1.09 KB

Contents

require 'whiskey_disk/config/abstract_filter'
require 'whiskey_disk/config/filters/modules/scope_helper'

class WhiskeyDisk
  class Config
    class ProjectScopeFilter < AbstractFilter
      include ScopeHelper

      def repository_depth(data, depth = 0)
        raise 'no repository found' unless data.respond_to?(:has_key?)
        return depth if data.has_key?('repository')
        repository_depth(data.values.first, depth + 1)
      end
  
      # is this data hash an environment data hash without a project name?
      def needs_project_scoping?(data)
        repository_depth(data) == 1
      end

      # TODO: why do we continue to need override_project_name! ?
      # TODO: this is invasive into Config's implementation
      def override_project_name!(data)
        return if ENV['to'] && ENV['to'] =~ /:/
        ENV['to'] = data[environment_name]['project'] + ':' + ENV['to'] if data[environment_name]['project']
      end

      def filter(data)
        return data unless needs_project_scoping?(data)
        override_project_name!(data)
        { project_name => data }
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 3 rubygems

Version Path
ol-whisk_deploy-0.6.25 lib/whiskey_disk/config/filters/project_scope_filter.rb
ol-whisk_deploy-0.6.26 lib/whiskey_disk/config/filters/project_scope_filter.rb
whisk_deploy-0.6.26 lib/whiskey_disk/config/filters/project_scope_filter.rb
whiskey_disk-0.6.24 lib/whiskey_disk/config/filters/project_scope_filter.rb
whiskey_disk-0.6.23 lib/whiskey_disk/config/filters/project_scope_filter.rb