Class: ActiveGenie::Config::ProvidersConfig
- Inherits:
-
BaseConfig
- Object
- BaseConfig
- ActiveGenie::Config::ProvidersConfig
show all
- Defined in:
- lib/active_genie/configs/providers_config.rb
Instance Method Summary
collapse
Methods inherited from BaseConfig
#attributes
Constructor Details
Returns a new instance of ProvidersConfig.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args) ⇒ Object
64
65
66
|
# File 'lib/active_genie/configs/providers_config.rb', line 64
def method_missing(method_name, *args, &)
@all[method_name] || super
end
|
Instance Method Details
#add(name, provider_configs) ⇒ Object
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/active_genie/configs/providers_config.rb', line 39
def add(name, provider_configs)
@all ||= {}
Array(provider_configs).each do |provider_config|
remove([name]) if @all.key?(name)
@all[name] = provider_config.new
end
self
end
|
#all ⇒ Object
30
31
32
|
# File 'lib/active_genie/configs/providers_config.rb', line 30
def all
@all ||= {}
end
|
#default ⇒ Object
22
23
24
|
# File 'lib/active_genie/configs/providers_config.rb', line 22
def default
@default ||= ENV.fetch('PROVIDER_NAME', nil)&.to_s&.downcase&.strip
end
|
#default=(provider) ⇒ Object
26
27
28
|
# File 'lib/active_genie/configs/providers_config.rb', line 26
def default=(provider)
@default = provider&.to_s&.downcase&.strip
end
|
#provider_name_by_model(model) ⇒ Object
58
59
60
61
62
|
# File 'lib/active_genie/configs/providers_config.rb', line 58
def provider_name_by_model(model)
return nil if model.nil?
valid.find { |_, config| config.valid_model?(model) }&.first
end
|
#remove(provider_configs) ⇒ Object
50
51
52
53
54
55
56
|
# File 'lib/active_genie/configs/providers_config.rb', line 50
def remove(provider_configs)
Array(provider_configs).each do |provider|
@all.delete(provider::NAME)
end
self
end
|
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
68
69
70
|
# File 'lib/active_genie/configs/providers_config.rb', line 68
def respond_to_missing?(method_name, include_private = false)
@all.key?(method_name) || super
end
|
#to_h ⇒ Object
72
73
74
75
76
77
78
79
|
# File 'lib/active_genie/configs/providers_config.rb', line 72
def to_h
h = {}
@all.each do |key, config|
h[key] = config.to_h
end
super.merge(h)
end
|
#valid ⇒ Object
34
35
36
37
|
# File 'lib/active_genie/configs/providers_config.rb', line 34
def valid
valid_provider_keys = @all.keys.select { |k| @all[k].valid? }
@all.slice(*valid_provider_keys)
end
|