Class: WhiskeyDisk::Config::ProjectScopeFilter

Inherits:
AbstractFilter show all
Includes:
ScopeHelper
Defined in:
lib/whiskey_disk/config/filters/project_scope_filter.rb

Instance Attribute Summary

Attributes inherited from AbstractFilter

#config

Instance Method Summary collapse

Methods inherited from AbstractFilter

#environment_name, #initialize, #project_name

Constructor Details

This class inherits a constructor from WhiskeyDisk::Config::AbstractFilter

Instance Method Details

#filter(data) ⇒ Object



27
28
29
30
31
# File 'lib/whiskey_disk/config/filters/project_scope_filter.rb', line 27

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

#needs_project_scoping?(data) ⇒ Boolean

is this data hash an environment data hash without a project name?

Returns:

  • (Boolean)


16
17
18
# File 'lib/whiskey_disk/config/filters/project_scope_filter.rb', line 16

def needs_project_scoping?(data)
  repository_depth(data) == 1
end

#override_project_name!(data) ⇒ Object

TODO: why do we continue to need override_project_name! ? TODO: this is invasive into Config’s implementation



22
23
24
25
# File 'lib/whiskey_disk/config/filters/project_scope_filter.rb', line 22

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

#repository_depth(data, depth = 0) ⇒ Object



9
10
11
12
13
# File 'lib/whiskey_disk/config/filters/project_scope_filter.rb', line 9

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