Sha256: 7e719a4f9ca85f87d5d06b10c5600fc4055e41b6a926fc0ebc116dce7d79be9e

Contents?: true

Size: 765 Bytes

Versions: 3

Compression:

Stored size: 765 Bytes

Contents

require 'json'
require 'librato/space'

module Librato
  class Spaces < Struct.new(:client, :account)
    def find_all(config)
      config.map do |config|
        find(config['name']).tap { |space| space.config = config }
      end
    end

    private

      def all
        @all ||= fetch['spaces'].map do |data|
          Space.new(client, normalize(data))
        end
      end

      def find(name)
        space = all.detect { |space| space.name == name }
        space || fail("Could not find space #{name}")
      end

      def fetch
        JSON.parse(client.get(path).body)
      end

      def path
        '/v1/spaces'
      end

      def normalize(data)
        data.merge('name' => data['name'].sub(/\s*\(#{account}\)\s*/, ''))
      end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
librato-0.0.6 lib/librato/spaces.rb
librato-0.0.5 lib/librato/spaces.rb
librato-0.0.4 lib/librato/spaces.rb