Class: HomePage::ApiProviderHost
- Inherits:
-
Object
- Object
- HomePage::ApiProviderHost
- Defined in:
- lib/home_page/api_provider_host.rb
Constant Summary collapse
- ENVIRONMENTS =
[:development, :test, :staging, :production]
- ALIASES =
{ dev: :development, testing: :test, stage: :staging, show: :staging, live: :production, prod: :production }
- FALLBACKS =
{ development: [:development, :test, :staging, :production], test: [:test, :development, :staging, :production], staging: [:staging, :production], production: [:production] }
Instance Method Summary collapse
- #environment ⇒ Object
-
#initialize(provider, working_environment) ⇒ ApiProviderHost
constructor
A new instance of ApiProviderHost.
- #setting_namespace ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(provider, working_environment) ⇒ ApiProviderHost
Returns a new instance of ApiProviderHost.
15 16 17 18 |
# File 'lib/home_page/api_provider_host.rb', line 15 def initialize(provider, working_environment) @provider = provider @environment = working_environment.to_s.to_sym end |
Instance Method Details
#environment ⇒ Object
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/home_page/api_provider_host.rb', line 24 def environment if ENVIRONMENTS.include?(@environment) @environment else ALIASES[@environment] || raise( NotImplementedError, 'Your environment is unknown. Please update alias mapping!' ) end end |
#setting_namespace ⇒ Object
20 21 22 |
# File 'lib/home_page/api_provider_host.rb', line 20 def setting_namespace "home_page.apis.providers.#{@provider}.hosts" end |
#to_s ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/home_page/api_provider_host.rb', line 35 def to_s host = nil FALLBACKS[environment].each do |provider_environment| host = Setting["#{setting_namespace}.#{provider_environment}"] break if host end unless host raise( NotImplementedError, 'The API provider does not support your environment!' ) end host end |