Class: Flo::Provider::Base Abstract
- Inherits:
-
Object
- Object
- Flo::Provider::Base
- Defined in:
- lib/flo/provider/base.rb
Overview
This class is abstract.
Subclass and use Base.option to declare initialize options
A base provider class that all custom providers should inherit from.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#cred_store ⇒ Object
writeonly
Sets the attribute cred_store.
Class Method Summary collapse
-
.option(name, default = nil, args = {}) ⇒ Object
Declare an option to be passed in when declaring the provider in the .flo file.
-
.option_keys ⇒ Hash{Symbol => OptionDefiniton}
Hash of option definitions.
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ Base
constructor
Creates an instance of a provider.
Constructor Details
#initialize(opts = {}) ⇒ Base
Creates an instance of a provider
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/flo/provider/base.rb', line 24 def initialize(opts={}) # @options = allow_whitelisted(opts, @@option_keys) = {} self.class.option_keys.each do |key, definition| [key] = opts.fetch(key, definition.default) end missing_required = self.class.option_keys.select {|_k,v| v.required }.keys - .select { |_k,v| !v.nil? }.keys unless missing_required.empty? raise MissingOptionError.new("#{self.class.name} invoked without required options: #{missing_required.join(' ')}") end end |
Instance Attribute Details
#cred_store=(value) ⇒ Object (writeonly)
Sets the attribute cred_store
16 17 18 |
# File 'lib/flo/provider/base.rb', line 16 def cred_store=(value) @cred_store = value end |
Class Method Details
.option(name, default = nil, args = {}) ⇒ Object
Declare an option to be passed in when declaring the provider in the .flo file
45 46 47 |
# File 'lib/flo/provider/base.rb', line 45 def self.option(name, default=nil, args={}) option_keys[name] = OptionDefinition.new(default, args[:required] == true) end |
.option_keys ⇒ Hash{Symbol => OptionDefiniton}
Hash of option definitions. Add to this hash using the option method.
53 54 55 |
# File 'lib/flo/provider/base.rb', line 53 def self.option_keys @option_keys ||= {} end |