Class: CaptainHoog::Plugin

Inherits:
Object
  • Object
show all
Includes:
Delegatable
Defined in:
lib/captain_hoog/plugin.rb

Overview

Public: Class that evaluates a plugin from a given bunch of DSL code.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Delegatable

included

Constructor Details

#initialize(code, env) ⇒ Plugin

Public: Initializes the Plugin evaluator.

code - the plugin code as String env - An instance of CaptainHoog::Env containing some accessible

environment variables (context is limited to CaptainHoog)


15
16
17
18
19
# File 'lib/captain_hoog/plugin.rb', line 15

def initialize(code,env)
  @code  = code
  @env   = env
  @git   = CaptainHoog::Git.new
end

Instance Attribute Details

#envObject

Returns the value of attribute env.



6
7
8
# File 'lib/captain_hoog/plugin.rb', line 6

def env
  @env
end

Instance Method Details

#configObject

Public: Provides access to the configuration section in the hoogfile with the plugin’s name.

Returns the value of the key.



49
50
51
# File 'lib/captain_hoog/plugin.rb', line 49

def config
  Struct.new(env[:plugins_config].send(git.plugin_name))
end

#eval_pluginObject

Public: Evaluates the plugin by ‘reading’ the dsl. Did not execute anything.

Returns nothing



30
31
32
# File 'lib/captain_hoog/plugin.rb', line 30

def eval_plugin
  instance_eval(@code) && git
end

#executeObject

Public: Executes a plugin and stores the results in a Hash.

Returns a Hash containing the test result and the failure message.



37
38
39
40
41
42
43
# File 'lib/captain_hoog/plugin.rb', line 37

def execute
  eigenplugin.execute
  {
    :result  => @git.instance_variable_get(:@test_result),
    :message => @git.instance_variable_get(:@message)
  }
end

#gitObject

Public: Yields the code given in @code.



22
23
24
# File 'lib/captain_hoog/plugin.rb', line 22

def git
  eigenplugin
end