Sha256: 33fbe642ed320b977cb45e94524afbee961ad9612a066222d030b7e799a69a81

Contents?: true

Size: 1020 Bytes

Versions: 2

Compression:

Stored size: 1020 Bytes

Contents

require "rehearsal/version"
require "rehearsal/engine"

module Rehearsal
  def self.included(base)
    base.extend ClassMethods
    base.helper_method :rehearsing?
    base.before_filter :require_http_basic_auth
  end

  module ClassMethods
    def rehearse_with(username, password)
      class_eval do
        define_method(:username) do
          username
        end

        define_method(:password) do
          password
        end
      end

      Rehearsal.config.enabled = true
    end
  end

  class << self
    def configure
      yield(config)
    end

    def config=(config_instance)
      @config = config_instance
    end

    def config
      @config ||= Configuration.new
    end
  end

  private
  def require_http_basic_auth
    authenticate_or_request_with_http_basic do |username, password|
      username == self.username && password == self.password
    end if rehearsing?
  end

  def rehearsing?
    return unless Rehearsal.config.enabled
    Rails.env.to_sym == Rehearsal.config.env
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rehearsal-1.2.0 lib/rehearsal.rb
rehearsal-1.1.0 lib/rehearsal.rb