Class: N1Finder::Adapters::BaseAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/n_1_finder/adapters/base_adapter.rb

Overview

Adds common functionality to other adapters

Direct Known Subclasses

ActiveRecordAdapter, NullAdapter, SequelAdapter

Constant Summary collapse

MAIN_METHOD_ALIAS =

An alias that we create for MAIN_METHOD function

:main_method_alias

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(storage) ⇒ BaseAdapter

Returns a new instance of BaseAdapter.



14
15
16
# File 'lib/n_1_finder/adapters/base_adapter.rb', line 14

def initialize(storage)
  @storage = storage
end

Instance Attribute Details

#storageObject (readonly)

Returns the value of attribute storage.



12
13
14
# File 'lib/n_1_finder/adapters/base_adapter.rb', line 12

def storage
  @storage
end

Instance Method Details

#exec { ... } ⇒ Object

Replaces original query execution function (defined in MAIN_METHOD) with our function that collects all queries and calls original function. After passed block yileds, replaces our function with origianal and removes our function.

Yields:

  • passed block

Returns:

  • passed block execution result



26
27
28
29
30
31
# File 'lib/n_1_finder/adapters/base_adapter.rb', line 26

def exec
  set_trap
  yield
ensure
  remove_trap
end