Class: Flo::Provider::Base Abstract

Inherits:
Object
  • Object
show all
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

Developer

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Base

Creates an instance of a provider

Parameters:

  • opts (Hash) (defaults to: {})

    Arbitrary array of options defined by the provider using the option method

Raises:

  • (MissingOptionError)

    if a required option is not provided. Error message will state which options are missing.



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)
  @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

Instance Attribute Details

#cred_store=(value) ⇒ Object (writeonly)

Sets the attribute cred_store

Parameters:

  • value

    the value to set the attribute cred_store to.



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

Parameters:

  • name (Symbol)

    The name of the option

  • default (defaults to: nil)

    Default value for the option if none is provided

  • args (Hash) (defaults to: {})

    a customizable set of options

Options Hash (args):

  • :required (Boolean) — default: false

    Whether the option is required. A MissingOptionError will be raised if a provider is instantiated without a required argument



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_keysHash{Symbol => OptionDefiniton}

Hash of option definitions. Add to this hash using the option method.

Returns:

  • (Hash{Symbol => OptionDefiniton})


53
54
55
# File 'lib/flo/provider/base.rb', line 53

def self.option_keys
  @option_keys ||= {}
end