Class: BeamUp::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/beam_up/configuration.rb

Constant Summary collapse

DEFAULT_TIMEOUT =

5 minutes

300

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



9
10
11
12
# File 'lib/beam_up/configuration.rb', line 9

def initialize
  @providers = {}
  @timeout = DEFAULT_TIMEOUT
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *arguments) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/beam_up/configuration.rb', line 36

def method_missing(method_name, *arguments)
  if PROVIDERS.key?(method_name.to_s)
    @providers[method_name.to_s] ||= PROVIDERS[method_name.to_s]::Config.new
  else
    super
  end
end

Instance Attribute Details

#after_actionsObject

Returns the value of attribute after_actions.



5
6
7
# File 'lib/beam_up/configuration.rb', line 5

def after_actions
  @after_actions
end

#before_actionsObject

Returns the value of attribute before_actions.



5
6
7
# File 'lib/beam_up/configuration.rb', line 5

def before_actions
  @before_actions
end

#pathObject

Returns the value of attribute path.



5
6
7
# File 'lib/beam_up/configuration.rb', line 5

def path
  @path
end

#providerObject

Returns the value of attribute provider.



5
6
7
# File 'lib/beam_up/configuration.rb', line 5

def provider
  @provider
end

#timeoutObject

Returns the value of attribute timeout.



5
6
7
# File 'lib/beam_up/configuration.rb', line 5

def timeout
  @timeout
end

Class Method Details

.with(options) ⇒ Object



14
15
16
17
18
19
# File 'lib/beam_up/configuration.rb', line 14

def self.with(options)
  new.tap do |config|
    config.provider = options[:provider]
    config.provider_config.with(options)
  end
end

Instance Method Details

#provider_configObject

Raises:



21
22
23
24
25
26
27
28
# File 'lib/beam_up/configuration.rb', line 21

def provider_config
  raise(ConfigurationError, "Provider must be set") if provider.nil? || provider.empty?

  provider_class = PROVIDERS[provider.to_s]
  raise(ConfigurationError, "Unknown provider: #{provider}") unless provider_class

  @providers[provider.to_s] ||= provider_class::Config.new
end

#respond_to_missing?(method_name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/beam_up/configuration.rb', line 44

def respond_to_missing?(method_name, include_private = false)
  PROVIDERS.key?(method_name.to_s) || super
end

#validate!Object

Raises:



30
31
32
33
34
# File 'lib/beam_up/configuration.rb', line 30

def validate!
  raise ConfigurationError, "Provider must be set" unless provider

  provider_config.validate!
end