class Flo::Provider::Base
@abstract Subclass and use {.option} to declare initialize options A base provider class that all custom providers should inherit from.
Attributes
cred_store[W]
options[R]
Public Class Methods
new(opts={})
click to toggle source
Creates an instance of a provider @param opts [Hash] Arbitrary array of options defined by the provider
using the {.option} method
@raise [MissingOptionError] if a required option is not provided. Error
message will state which options are missing.
# File lib/flo/provider/base.rb, line 24 def initialize(opts={}) # @options = allow_whitelisted(opts, @@option_keys) @options = {} self.class.option_keys.each do |key, definition| @options[key] = opts.fetch(key, definition.default) end missing_required = self.class.option_keys.select {|_k,v| v.required }.keys - @options.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
option(name, default=nil, args={})
click to toggle source
Declare an option to be passed in when declaring the provider in the .flo file @param name [Symbol] The name of the option @param default Default value for the option if none is provided @option args [Boolean] :required (false) Whether the option is required.
A MissingOptionError will be raised if a provider is instantiated without a required argument
# 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()
click to toggle source
Hash of option definitions. Add to this hash using the {.option} method.
@return [Hash{Symbol => OptionDefiniton}]
# File lib/flo/provider/base.rb, line 53 def self.option_keys @option_keys ||= {} end