Module: Google

Defined in:
lib/fog/bin/google.rb

Overview

deviates from other bin stuff to accomodate gem

Class Method Summary collapse

Class Method Details

.[](service) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/fog/bin/google.rb', line 25

def [](service)
  @@connections ||= Hash.new do |hash, key|
    case key
    when :compute
      hash[key] = Fog::Compute.new(:provider => "Google")
    when :dns
      hash[key] = Fog::DNS.new(:provider => "Google")
    when :monitoring
      hash[key] = Fog::Google::Monitoring.new
    when :sql
      hash[key] = Fog::Google::SQL.new
    when :pubsub
      hash[key] = Fog::Google::Pubsub.new
    when :storage
      hash[key] = Fog::Storage.new(:provider => "Google")
    else
      hash[key] = raise ArgumentError, "Unrecognized service: #{key.inspect}"
    end
  end
  @@connections[service]
end

.accountObject



47
48
49
# File 'lib/fog/bin/google.rb', line 47

def 
  @@connections[:compute].
end

.available?Boolean

based off of virtual_box.rb

Returns:

  • (Boolean)


56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/fog/bin/google.rb', line 56

def available?
  # Make sure the gem we use is enabled.
  if Gem::Specification.respond_to?(:find_all_by_name)
    # newest rubygems
    availability = !Gem::Specification.find_all_by_name("google-api-client").empty?
  else
    # legacy
    availability = !Gem.source_index.find_name("google-api-client").empty?
  end

  # Then make sure we have all of the requirements
  services.each do |service|
    begin
      service = class_for(service)
      availability &&= service.requirements.all? { |requirement| Fog.credentials.include?(requirement) }
    rescue ArgumentError => e
      Fog::Logger.warning(e.message)
      availability = false
    rescue StandardError => e
      availability = false
    end
  end

  if availability
    services.each do |service|
      class_for(service).collections.each do |collection|
        next if respond_to?(collection)

        class_eval <<-EOS, __FILE__, __LINE__ + 1
            def self.#{collection}
              self[:#{service}].#{collection}
            end
        EOS
      end
    end
  end
  availability
end

.class_for(key) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/fog/bin/google.rb', line 4

def class_for(key)
  case key
  when :compute
    Fog::Google::Compute
  when :dns
    Fog::Google::DNS
  when :monitoring
    Fog::Google::Monitoring
  when :storage
    Fog::Google::Storage
  when :storage_json
    Fog::Google::Storage
  when :sql
    Fog::Google::SQL
  when :pubsub
    Fog::Google::Pubsub
  else
    raise ArgumentError, "Unsupported #{self} service: #{key}"
  end
end

.servicesObject



51
52
53
# File 'lib/fog/bin/google.rb', line 51

def services
  Fog::Google.services
end