Sha256: 3ec568b87dd4067f8ec603d7b0108ec09dd071354637e3e2c28ec5fb49a1a842

Contents?: true

Size: 577 Bytes

Versions: 2

Compression:

Stored size: 577 Bytes

Contents

module Gara

  class Delegator
    attr_accessor :emitter

    def self.define_delegate(method_name, on: nil, to: nil)
      on.module_eval <<-RUBY
        def #{method_name}(*args)
          #{to || "@gara_delegate"}.#{method_name}(*args) { yield if block_given? }
        end
      RUBY
    end


    def initialize(view_context, emitter)
      @emitter = emitter
      view_context.instance_variable_set(:@gara_delegate, emitter)
      view_context.extend(emitter.registered_methods)
      yield if block_given?
    end

    def render
      @emitter.emit
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
gara-0.1.5 lib/gara/delegator.rb
gara-0.1.4 lib/gara/delegator.rb