Class: WhiskeyDisk::Config::DropEmptyDomainRolesFilter

Inherits:
AbstractFilter
  • Object
show all
Defined in:
lib/whiskey_disk/config/filters/drop_empty_domain_roles_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

#drop_empty_domain_roles(domains_list) ⇒ Object



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

def drop_empty_domain_roles(domains_list)
  domains_list.collect { |domain| drop_empty_roles_for_domain(domain) }
end

#drop_empty_roles_for_domain(domain) ⇒ Object



17
18
19
20
# File 'lib/whiskey_disk/config/filters/drop_empty_domain_roles_filter.rb', line 17

def drop_empty_roles_for_domain(domain)
  return domain unless has_empty_role?(domain)
  domain.reject {|key, value| key == 'roles' }
end

#filter(data) ⇒ Object



26
27
28
# File 'lib/whiskey_disk/config/filters/drop_empty_domain_roles_filter.rb', line 26

def filter(data)
  data.merge('domain' => drop_empty_domain_roles(data['domain']))
end

#has_empty_role?(domain) ⇒ Boolean

Returns:

  • (Boolean)


6
7
8
9
10
11
12
13
14
15
# File 'lib/whiskey_disk/config/filters/drop_empty_domain_roles_filter.rb', line 6

def has_empty_role?(domain)
  return true unless domain.has_key?('roles')
  return true if domain['roles'].nil?

  roles = domain['roles'].uniq.compact
  return true if roles == [ '' ]
  return true if roles == []
  
  false
end