class ClientDataAdapter::Wrapper

Attributes

target[R]

Instance of original class.

@example

@book.adapter_wrapper.target == @book # => true

Public Class Methods

adapter(&block) click to toggle source

Main adapter method, should return Hash.

Syntactic sugar of with.

@return [Hash] @see with @example

define_adapter do

  adapter do
    {
      id: id,
      title: title,
    }
  end

end
# File lib/client-data-adapter/wrapper.rb, line 36
def self.adapter(&block)
  with('__adapter__', &block)
end
new(target, &block) click to toggle source
# File lib/client-data-adapter/wrapper.rb, line 12
def initialize(target, &block)
  @target = target

  self.class.module_eval(&block)
end
with(method_name, &block) click to toggle source

Define a method of Wrapper.

Merged to the result of adapter method.

@param [Symbol] method_name @example

define_adapter do
  # ...

  with :something do
    # do something
  end

end
# File lib/client-data-adapter/wrapper.rb, line 102
def self.with(method_name, &block)
  define_method(method_name.to_sym) do |*args|
    target.instance_exec(
      *args,
      &Util.to_lambda(block)
    )
  end
end