Class: Confiner::Plugin

Inherits:
Object
  • Object
show all
Includes:
Logger
Defined in:
lib/confiner/plugin.rb

Overview

Plugin for Confiner

Constant Summary collapse

DEFAULT_PLUGIN_ARGS =
{
  debug: false,  # Used for debugging logging
  dry_run: false # Used for when external requests are inhibited
}.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Logger

#log, log_to, log_to=

Constructor Details

#initialize(options, **args) ⇒ Plugin

Returns a new instance of Plugin.



43
44
45
46
47
48
49
50
51
52
# File 'lib/confiner/plugin.rb', line 43

def initialize(options, **args)
  @options = DEFAULT_PLUGIN_ARGS.merge(options)
  @options = Struct.new(*@options.keys).new(*@options.values)

  args.each do |k, v|
    v = ENV[v[1..]] if v[0] == '$' # get environment variable

    self.public_send(:"#{k}=", v)
  end
end

Instance Attribute Details

#examplesObject (readonly)

Returns the value of attribute examples.



8
9
10
# File 'lib/confiner/plugin.rb', line 8

def examples
  @examples
end

Class Method Details

.arguments(*args) ⇒ Object

Note:

the arguments should be well-formed in the .yml rule file

Define arguments that the plugin will accept

Parameters:

  • args (Array<Symbol, Hash>)

    the arguments that this plugin accepts

Options Hash (*args):

  • :argument (Symbol)

    the argument to pass with no default

  • :argument (Hash)

    the argument to pass with a default value



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/confiner/plugin.rb', line 21

def arguments(*args)
  @arguments ||= args

  args.each do |arg|
    if arg.is_a? Hash
      arg.each do |a, default_value|
        attr_writer a

        default = default_value
        default = ENV[default_value[1..]] if default_value[0] == '$'

        define_method(a) do
          instance_variable_get("@#{a}") || instance_variable_set("@#{a}", default)
        end
      end
    else
      attr_accessor arg
    end
  end
end

Instance Method Details

#run(action) {|_self| ... } ⇒ Object

Run the plugin

Yields:

  • (_self)

Yield Parameters:



55
56
57
# File 'lib/confiner/plugin.rb', line 55

def run(action, &block)
  yield self
end