Sha256: fdb6bf90016a6eb7617350a517d326a32bc26d90d045389eac59c62dc7bac197

Contents?: true

Size: 1.63 KB

Versions: 9

Compression:

Stored size: 1.63 KB

Contents

module AeEasy
  module Core
    module Plugin
      module ContextIntegrator
        # Last mocked ontext object.
        attr_reader :context

        # Mock a context methods into self.
        #
        # @param source Object that represents the context to mock.
        #
        # @example
        #   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!
        def mock_context source
          @context = source
          AeEasy::Core.mock_instance_methods context, self
        end

        # Hook to mock context on initialize.
        #
        # @param [Hash] opts ({}) Configuration options.
        # @option opts :context Object that represents the context to mock.
        def initialize_hook_core_context_integrator opts = [{}]
          raise ':context object is required.' if opts[:context].nil?
          mock_context opts[:context]
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
ae_easy-core-0.1.5 lib/ae_easy/core/plugin/context_integrator.rb
ae_easy-core-0.1.4 lib/ae_easy/core/plugin/context_integrator.rb
ae_easy-core-0.1.3 lib/ae_easy/core/plugin/context_integrator.rb
ae_easy-core-0.1.2 lib/ae_easy/core/plugin/context_integrator.rb
ae_easy-core-0.1.1 lib/ae_easy/core/plugin/context_integrator.rb
ae_easy-core-0.1.0 lib/ae_easy/core/plugin/context_integrator.rb
ae_easy-core-0.0.5 lib/ae_easy/core/plugin/context_integrator.rb
ae_easy-core-0.0.4 lib/ae_easy/core/plugin/context_integrator.rb
ae_easy-core-0.0.3 lib/ae_easy/core/plugin/context_integrator.rb