Module: AeEasy::Core::Plugin::ContextIntegrator

Included in:
ConfigBehavior, ExecutorBehavior
Defined in:
lib/ae_easy/core/plugin/context_integrator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#contextObject (readonly)

Last mocked ontext object.



6
7
8
# File 'lib/ae_easy/core/plugin/context_integrator.rb', line 6

def context
  @context
end

Instance Method Details

#initialize_hook_core_context_integrator(opts = [{}]) ⇒ Object

Hook to mock context on initialize.

Parameters:

  • opts (Hash) (defaults to: [{}])

    ({}) Configuration options.

Options Hash (opts):

  • :context (Object)

    Object that represents the context to mock.



53
54
55
56
# File 'lib/ae_easy/core/plugin/context_integrator.rb', line 53

def initialize_hook_core_context_integrator opts = [{}]
  raise ':context object is required.' if opts[:context].nil?
  mock_context opts[:context]
end

#mock_context(source) ⇒ Object

Mock a context methods into self.

Examples:

class MyContext
  attr_accessor :message
  def initialize
    message = 'Hello world!'
  end

  def hello_world
    message
  end
end

class Foo
  include ContextIntegrator

  def hello_person
    'Hello person!'
  end
end

context = MyContext.new
my_object = Foo.new
my_object.mock_context context

puts my_object.hello_world
# => 'Hello world!'
puts my_object.hello_person
# => 'Hello person!'

context.message = 'Hello world again!'
puts my_object.hello_world
# => 'Hello world again!

Parameters:

  • source

    Object that represents the context to mock.



44
45
46
47
# File 'lib/ae_easy/core/plugin/context_integrator.rb', line 44

def mock_context source
  @context = source
  AeEasy::Core.mock_instance_methods context, self
end