Module: AgnosticPresenters::Helper

Defined in:
lib/base.rb

Instance Method Summary collapse

Instance Method Details

#presenters(&block) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/base.rb', line 16

def presenters(&block)
  klass = Class.new(::AgnosticPresenters::Base)
  klass.class_eval(&block)
  const_set(:Presenters, klass)
  
  self.send :include, Proxen
  self.class_eval do
    Proxen::Proxy.add(self, :_presenters, :if => /!$/)

    def method_missing(sym, *args, &block)
      Proxen::Proxy.handle(self, sym, *args, &block) || super
    end

    def _presenters
      @_presenters ||= self.class::Presenters.new(self)
    rescue NameError
      raise ::AgnosticPresenters::NoPresenter, "No presenter has been found for #{self.class.name}."
    end
  end
end