class GClouderUndefinedResources::RemoteResources

Public Class Methods

new(project_id) click to toggle source
# File lib/gclouder_undefined_resources/remote_resources.rb, line 5
def initialize(project_id)
  @project_id = project_id
  @resources = []
end

Public Instance Methods

add(resources) click to toggle source
# File lib/gclouder_undefined_resources/remote_resources.rb, line 22
def add(resources)
  @resources += resources
end
any_undefined_and_unfiltered?() click to toggle source
# File lib/gclouder_undefined_resources/remote_resources.rb, line 115
def any_undefined_and_unfiltered?
  status_types = @resources.group_by { |resource| resource.status }

  return if status_types.empty?

  status_types.key?("✗".red)
end
collect() click to toggle source
# File lib/gclouder_undefined_resources/remote_resources.rb, line 10
def collect
  add Remote::GCloud.fetch(@project_id)

  @resources = @resources.reject do |resource|
    CLIArgs.cli_args[:hide_filtered] && resource.filtered?
  end

  @resources = @resources.reject do |resource|
    CLIArgs.cli_args[:hide_defined] && resource.defined?
  end
end
display_by_location() click to toggle source

display: region, zone, type, name

# File lib/gclouder_undefined_resources/remote_resources.rb, line 67
def display_by_location
  regions = @resources.group_by { |resource| resource.region }

  regions.each do |region, resources_by_region|
    region ||= "global"

    puts
    puts
    puts "  #{region}"

    zones = resources_by_region.group_by { |resource| resource.zone }

    zones.each do |zone, resources_by_zone|
      zone ||= "none"

      puts
      puts "    #{zone}"

      types = resources_by_zone.group_by { |resource| resource.type }

      types.each do |type, resources_by_type|
        puts
        puts "      #{type.join(' / ')}"
        puts

        resources_by_type.each do |resource|
          puts "        #{resource}"
        end
      end
    end
  end
end
display_by_type() click to toggle source

display: type, region, zone, name

# File lib/gclouder_undefined_resources/remote_resources.rb, line 27
def display_by_type
  types = @resources.group_by { |resource| resource.type }

  types.each do |type, resources_by_type|
    regions = resources_by_type.group_by { |resource| resource.region }

    next if regions.empty?

    puts
    puts
    puts "  #{type.join(' / ')}"

    regions.each do |region, resources_by_region|
      zones = resources_by_region.group_by { |resource| resource.zone }

      next if zones.empty?

      region ||= "global"

      puts
      puts "    #{region}"

      zones.each do |zone, resources_by_zone|
        next if resources_by_zone.empty?

        zone ||= "none"

        puts
        puts "      #{zone}"
        puts

        resources_by_region.each do |resource|
          puts "        #{resource}"
        end
      end
    end
  end
end
display_report() click to toggle source
# File lib/gclouder_undefined_resources/remote_resources.rb, line 100
def display_report
  status_types = @resources.group_by { |resource| resource.status_and_description }
  status_types = status_types.sort_by { |_, resources| resources.length }

  return if status_types.empty?

  puts
  puts "  report"
  puts
  status_types.each do |status_type, resources|
    puts "    #{status_type[0]} - #{resources.length} - #{status_type[1]}"
  end
  puts
end