module Trestle::Resource::AdapterMethods::ClassMethods

Public Instance Methods

adapter() click to toggle source

Unbound instance of adapter.

# File lib/trestle/resource/adapter_methods.rb, line 56
def adapter
  @adapter ||= adapter_class.new(self)
end
adapter_class() click to toggle source

Returns the adapter class for this admin.

Defaults to a subclass of `Trestle.config.default_adapter` with the admin-specific adapter methods module included.

# File lib/trestle/resource/adapter_methods.rb, line 40
def adapter_class
  @adapter_class ||= Class.new(Trestle.config.default_adapter).include(adapter_methods)
end
adapter_class=(klass) click to toggle source

Sets an explicit adapter class for this admin. A subclass is created with the admin-specific adapter methods module included.

# File lib/trestle/resource/adapter_methods.rb, line 46
def adapter_class=(klass)
  @adapter_class = Class.new(klass).include(adapter_methods)
end
adapter_method(name) click to toggle source

Declares a method that is handled by the admin's adapter class.

# File lib/trestle/resource/adapter_methods.rb, line 13
def adapter_method(name)
  delegate name, to: :adapter

  singleton_class.class_eval do
    delegate name, to: :adapter
  end
end
adapter_methods() click to toggle source

Module container for admin-specific adapter methods.

# File lib/trestle/resource/adapter_methods.rb, line 51
def adapter_methods
  @adapter_methods ||= Module.new
end
define_adapter_method(name, &block) click to toggle source

Defines an admin-specific adapter method.

The given block is wrapped rather than passed to define_method directly, so that adapter methods can be defined with incomplete block parameters. Unfortunately this means we lose the ability to call super from within a custom adapter method.

# File lib/trestle/resource/adapter_methods.rb, line 26
def define_adapter_method(name, &block)
  return unless block_given?

  adapter_methods.module_eval do
    define_method(name) do |*args|
      instance_exec(*args, &block)
    end
  end
end