Module: Trestle::Resource::AdapterMethods::ClassMethods

Defined in:
lib/trestle/resource/adapter_methods.rb

Instance Method Summary collapse

Instance Method Details

#adapterObject

Unbound instance of adapter.


56
57
58
# File 'lib/trestle/resource/adapter_methods.rb', line 56

def adapter
  @adapter ||= adapter_class.new(self)
end

#adapter_classObject

Returns the adapter class for this admin.

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


40
41
42
# 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) ⇒ Object

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


46
47
48
# 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) ⇒ Object

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


13
14
15
16
17
18
19
# 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_methodsObject

Module container for admin-specific adapter methods.


51
52
53
# File 'lib/trestle/resource/adapter_methods.rb', line 51

def adapter_methods
  @adapter_methods ||= Module.new
end

#define_adapter_method(name, &block) ⇒ Object

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.


26
27
28
29
30
31
32
33
34
# 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