class Confiner::Plugin

Plugin for Confiner

Constants

DEFAULT_PLUGIN_ARGS

Attributes

examples[R]

Public Class Methods

arguments(*args) click to toggle source

Define arguments that the plugin will accept @param [Array<Symbol, Hash>] args the arguments that this plugin accepts @option args [Symbol] :argument the argument to pass with no default @option args [Hash] :argument the argument to pass with a default value @note the arguments should be well-formed in the .yml rule file

# 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
new(options, **args) click to toggle source
# 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

Public Instance Methods

run(action) { |self| ... } click to toggle source

Run the plugin

# File lib/confiner/plugin.rb, line 55
def run(action, &block)
  yield self
end