Module: GClouder::Resource::Cleaner

Defined Under Namespace

Modules: Default

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



6
7
8
# File 'lib/gclouder/resource_cleaner.rb', line 6

def self.included(klass)
  klass.extend Cleaner
end

Instance Method Details

#cleanObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/gclouder/resource_cleaner.rb', line 10

def clean
  return if undefined.empty?

  header :clean

  undefined.each do |namespace, resources|
    info namespace, indent: 2, heading: true
    info
    resources.each do |resource|
      message = resource['name']
      message += " (not defined locally)"
      warning message
      # FIXME: enable purge on --purge flag..
      #Resource.symlink.send(:purge, namespace, resource)
    end
  end
end

#cleanerObject



39
40
41
# File 'lib/gclouder/resource_cleaner.rb', line 39

def cleaner
  (self.const_defined?(:Cleaner) && self::Cleaner.respond_to?(:custom)) ? self::Cleaner.custom : Default.cleaner
end

#undefinedObject



43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/gclouder/resource_cleaner.rb', line 43

def undefined
  self::Remote.list.each_with_object({}) do |(namespace, resources), collection|
    resources.each do |resource|
      namespace_resources = self::Local.list[namespace]

      # accept PROC for custom matching of undefined resources
      next if namespace_resources && cleaner.call(namespace_resources, resource["name"])

      collection[namespace] ||= []
      collection[namespace] << resource
    end
  end
end