class HALPresenter::LazyEvaluator

Attributes

context[R]
options[R]
resource[R]
resources[R]

Public Class Methods

new(block, context) click to toggle source
# File lib/hal_presenter/lazy_evaluator.rb, line 8
def initialize(block, context)
  @context = context
  define_singleton_method(:call, &block)
end

Public Instance Methods

evaluate(resource, options) click to toggle source
# File lib/hal_presenter/lazy_evaluator.rb, line 17
def evaluate(resource, options)
  @resource = resource
  @options = (options || {}).dup
  call
ensure
  clear_state
end
update_context(context) click to toggle source
# File lib/hal_presenter/lazy_evaluator.rb, line 13
def update_context(context)
  @context = context
end

Private Instance Methods

clear_state() click to toggle source
# File lib/hal_presenter/lazy_evaluator.rb, line 29
def clear_state
  @resource = nil
  @options = nil
end
method_missing(method, *args, &block) click to toggle source
Calls superclass method
# File lib/hal_presenter/lazy_evaluator.rb, line 34
def method_missing(method, *args, &block)
  return super unless context.respond_to?(method)

  define_singleton_method(method) do |*a, &b|
    context.public_send(method, *a, &b)
  end

  public_send(method, *args, &block)
end
respond_to_missing?(method, _include_private = false) click to toggle source
Calls superclass method
# File lib/hal_presenter/lazy_evaluator.rb, line 44
def respond_to_missing?(method, _include_private = false)
  context.respond_to?(method) || super
end