Sha256: 50ad530737a28486d6fb389930fcca0ba7f47b0551b71693ff192894a06316f3

Contents?: true

Size: 1.52 KB

Versions: 5

Compression:

Stored size: 1.52 KB

Contents

module Heirloom
  module CLI
    module Formatter
      class Catalog

        def initialize(args)
          @catalog = args[:catalog]
        end

        def detailed_format(args)
          @name    = args[:name]
          @region  = args[:region]

          filter_by_name
          details
         end

        def summary_format(args)
          @region  = args[:region]

          summary
        end

        private

        def remove_heirloom_prefix
          Hash[@catalog.sort.map { |k, v| [k.sub(/heirloom_/, ''), v] }]
        end

        def add_indent_prefix
          Hash[remove_heirloom_prefix.sort.map { |k, v| [k.sub(/^/, '  '), v] }]
        end

        def filter_by_name
          @catalog.select! {|k| "heirloom_#{@name}" == k }
        end

        def summary
          s = @region + "\n"
          s << add_indent_prefix.keys.join("\n")
        end

        def details
          @catalog = remove_heirloom_prefix
          data = @catalog.each_pair.map do |k,v|
            urls = v["regions"].sort.map do |region|
              bucket_prefix = v["bucket_prefix"].first
              "  #{region}-s3-url : s3://#{bucket_prefix}-#{region}/#{k}"
            end

            d = k + "\n"
            d << "  metadata_region  : #{@region}\n"
            d << "  regions          : " + @catalog[k]["regions"].sort.join(", ") + "\n"
            d << "  bucket_prefix    : " + @catalog[k]["bucket_prefix"].first + "\n"
            d << urls.join("\n")
          end
          data.join "\n"
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
heirloom-0.12.7 lib/heirloom/cli/formatter/catalog.rb
heirloom-0.12.5 lib/heirloom/cli/formatter/catalog.rb
heirloom-0.12.4 lib/heirloom/cli/formatter/catalog.rb
heirloom-0.12.3 lib/heirloom/cli/formatter/catalog.rb
heirloom-0.12.2 lib/heirloom/cli/formatter/catalog.rb