Sha256: 2071dbc16071deb28493679751af42d4c26287402ff815c8f84b485b0cff673d

Contents?: true

Size: 1.07 KB

Versions: 1

Compression:

Stored size: 1.07 KB

Contents

class Tarquinn::Handler
  attr_accessor :config, :controller

  delegate :methods, :skip_methods, :blocks, :skip_blocks, to: :config

  def initialize(config, controller)
    @config = config
    @controller = controller
  end

  def perform_redirect?
    @perform_redirect = is_redirect? if @perform_redirect.nil?
    @perform_redirect
  end

  def redirect
    controller.send(:redirect_to, redirect_path)
  end

  private

  def redirect_method
    config.redirect
  end

  def redirect_path
    controller.send(config.redirect)
  end

  def is_redirect?
    return false if methods_skip_redirect? || blocks_skip_redirect?
    methods_require_redirect? || blocks_require_redirect?
  end

  def methods_skip_redirect?
    skip_methods.any? do |method|
      controller.send(method)
    end
  end

  def blocks_skip_redirect?
    skip_blocks.any? do |block|
      block.yield
    end
  end

  def methods_require_redirect?
    methods.any? do |method|
      controller.send(method)
    end
  end

  def blocks_require_redirect?
    blocks.any? do |block|
      block.yield
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
tarquinn-0.0.1 lib/tarquinn/handler.rb