Class: Adorn::AbstractPresenter

Inherits:
Object
  • Object
show all
Defined in:
lib/adorn/abstract_presenter.rb

Direct Known Subclasses

Presenter

Class Method Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Method, StandardError

Check both the context and the object before passing exception along



15
16
17
18
19
20
# File 'lib/adorn/abstract_presenter.rb', line 15

def method_missing(method, *args, &block)
  @context.send(method, *args, &block) if @context.respond_to?(method)
  @object.send(method, *args, &block) if @object.respond_to?(method)
rescue => e
  super(method, *args, &block)
end

Class Method Details

.presents(name) ⇒ Method

Macro used to create an instance method that wraps the underlying object passed to the decorator



9
10
11
# File 'lib/adorn/abstract_presenter.rb', line 9

def self.presents(name)
  define_method(name) { @object }
end

Instance Method Details

#respond_to_missing?(method) ⇒ Boolean



22
23
24
# File 'lib/adorn/abstract_presenter.rb', line 22

def respond_to_missing?(method,*)
  method =~ /#{method.to_s}/ || super
end