Module: CaptainHoog::Test::Sandbox::FakePlugin

Defined in:
lib/captain_hoog/test/sandbox.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth_name, *args, &block) ⇒ Object (private)



56
57
58
# File 'lib/captain_hoog/test/sandbox.rb', line 56

def method_missing(meth_name, *args, &block)
  super unless meth_name.include?('_configuration')
end

Instance Attribute Details

#fake_pluginObject (readonly)

Returns the value of attribute fake_plugin.



11
12
13
# File 'lib/captain_hoog/test/sandbox.rb', line 11

def fake_plugin
  @fake_plugin
end

Class Method Details

.env_configuration(configuration) ⇒ Object



37
38
39
40
# File 'lib/captain_hoog/test/sandbox.rb', line 37

def env_configuration(configuration)
  suppress_headline = configuration[:env].fetch(:suppress_headline, false)
  self.class.suppress_headline = suppress_headline
end

.fake_codeObject



22
23
24
25
26
27
28
29
# File 'lib/captain_hoog/test/sandbox.rb', line 22

def fake_code
  proc do
    env = prepare_env
    @fake_plugin = CaptainHoog::Plugin.new(@raw_plugin, env)
    @fake_plugin.eval_plugin
    [@fake_plugin]
  end
end

.headline_on_failure_configuration(configuration) ⇒ Object



51
52
53
54
# File 'lib/captain_hoog/test/sandbox.rb', line 51

def headline_on_failure_configuration(configuration)
  headline = configuration[:env].fetch(:headline_on_failure)
  self.class.headline_on_failure = headline
end

.headline_on_success_configuration(configuration) ⇒ Object



46
47
48
49
# File 'lib/captain_hoog/test/sandbox.rb', line 46

def headline_on_success_configuration(configuration)
  headline = configuration[:env].fetch(:headline_on_success)
  self.class.headline_on_success = headline
end

.method_missing(meth_name, *args, &block) ⇒ Object



56
57
58
# File 'lib/captain_hoog/test/sandbox.rb', line 56

def method_missing(meth_name, *args, &block)
  super unless meth_name.include?('_configuration')
end

.plugin_configuration(configuration) ⇒ Object



42
43
44
# File 'lib/captain_hoog/test/sandbox.rb', line 42

def plugin_configuration(configuration)
  self.class.plugins_conf = CaptainHoog::Struct.new(configuration[:plugin])
end

.setup_env(configuration) ⇒ Object



31
32
33
34
35
# File 'lib/captain_hoog/test/sandbox.rb', line 31

def setup_env(configuration)
  configuration.keys.each do |key|
    self.send("#{key}_configuration", configuration)
  end
end

Instance Method Details

#fake(with_plugin: nil, config: {}, eval_plugin: :false) ⇒ Object



13
14
15
16
17
18
# File 'lib/captain_hoog/test/sandbox.rb', line 13

def fake(with_plugin: nil, config: {}, eval_plugin: :false)
  setup_env(config)
  self.instance_variable_set(:@raw_plugin, with_plugin)
  self.class.send(:define_method, :available_plugins, fake_code)
  self.plugins_eval if eval_plugin
end