Class: Sitefull::Cloud::Provider

Inherits:
Object
  • Object
show all
Includes:
Mock
Defined in:
lib/sitefull-cloud/provider.rb

Constant Summary collapse

PROVIDERS =
%w(amazon azure google)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Mock

#mocked?

Constructor Details

#initialize(type, options = {}) ⇒ Provider

Returns a new instance of Provider.



11
12
13
14
15
# File 'lib/sitefull-cloud/provider.rb', line 11

def initialize(type, options = {})
  @type = type || 'base'
  extend(provider_module)
  @options = respond_to?(:process) ? process(options) : options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



9
10
11
# File 'lib/sitefull-cloud/provider.rb', line 9

def options
  @options
end

#typeObject (readonly)

Returns the value of attribute type.



9
10
11
# File 'lib/sitefull-cloud/provider.rb', line 9

def type
  @type
end

Class Method Details

.all_required_optionsObject



18
19
20
# File 'lib/sitefull-cloud/provider.rb', line 18

def all_required_options
  PROVIDERS.map { |type| required_options_for(type) }.flatten
end

.provider_class(type) ⇒ Object



26
27
28
29
# File 'lib/sitefull-cloud/provider.rb', line 26

def provider_class(type)
  require "sitefull-cloud/provider/#{type}"
  Kernel.const_get "Sitefull::Provider::#{type.capitalize}"
end

.required_options_for(type) ⇒ Object



22
23
24
# File 'lib/sitefull-cloud/provider.rb', line 22

def required_options_for(type)
  provider_class(type).const_get(:REQUIRED_OPTIONS)
end

Instance Method Details

#authObject



32
33
34
# File 'lib/sitefull-cloud/provider.rb', line 32

def auth
  @auth ||= Sitefull::Cloud::Auth.new(type, options)
end