Class: Confiner::Plugin
- Inherits:
-
Object
- Object
- Confiner::Plugin
- Includes:
- Logger
- Defined in:
- lib/confiner/plugin.rb
Overview
Plugin for Confiner
Direct Known Subclasses
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
-
#examples ⇒ Object
readonly
Returns the value of attribute examples.
Class Method Summary collapse
-
.arguments(*args) ⇒ Object
Define arguments that the plugin will accept.
Instance Method Summary collapse
-
#initialize(options, **args) ⇒ Plugin
constructor
A new instance of Plugin.
-
#run(action) {|_self| ... } ⇒ Object
Run the plugin.
Methods included from Logger
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(, **args) @options = DEFAULT_PLUGIN_ARGS.merge() @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
#examples ⇒ Object (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
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
55 56 57 |
# File 'lib/confiner/plugin.rb', line 55 def run(action, &block) yield self end |